Advertisement
Muskar2

Untitled

May 25th, 2025
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 16.55 KB | Software | 0 0
  1.     f64 NormalValues[] = {
  2.         0.82981006368785004135L,
  3.         0.3946389489976506L,
  4.         9.99999999999999954748e-8L, //0.0000001L
  5.         0.99999830000000000663L,
  6.         0.16760932829569819003L,
  7.         0.0997680529077115L,
  8.     };
  9.     f64 HalfPiValues[] = {
  10.        -1.3528578242776663L,
  11.         1.54429663234196290489L,
  12.         1.0000001L,
  13.        -1.0000001L,
  14.     };
  15.    
  16.     f64 PiValues[] = {
  17.        -2.93270853041948909024L,
  18.        -1.8576054803775690L,
  19.        -3.09047547364271268933L,
  20.         2.2576982172404999L,
  21.         1.5947303745826045L
  22.     };
  23.    
  24.     f64 SinInputs[ArrayCount(NormalValues) + ArrayCount(HalfPiValues) + ArrayCount(PiValues)];
  25.     f64 CosInputs[ArrayCount(NormalValues) + ArrayCount(HalfPiValues)];
  26.    
  27.     for (umm NormalIndex = 0; NormalIndex < ArrayCount(NormalValues); ++NormalIndex)
  28.     {
  29.         f64 NormalValue = NormalValues[NormalIndex];
  30.         SinInputs[NormalIndex] = NormalValue;
  31.         CosInputs[NormalIndex] = NormalValue;
  32.     }
  33.    
  34.     for (umm HalfPiIndex = 0; HalfPiIndex < ArrayCount(HalfPiValues); ++HalfPiIndex)
  35.     {
  36.         f64 HalfPiValue = HalfPiValues[HalfPiIndex];
  37.         umm InputIndex = HalfPiIndex + ArrayCount(NormalValues);
  38.         Assert(InputIndex < ArrayCount(SinInputs) && InputIndex < ArrayCount(CosInputs));
  39.         SinInputs[InputIndex] = HalfPiValue;
  40.         CosInputs[InputIndex] = HalfPiValue;
  41.     }
  42.    
  43.     for (umm PiIndex = 0; PiIndex < ArrayCount(PiValues); ++PiIndex)
  44.     {
  45.         f64 PiValue = PiValues[PiIndex];
  46.         umm InputIndex = PiIndex + ArrayCount(NormalValues) + ArrayCount(HalfPiValues);
  47.         Assert(InputIndex < ArrayCount(SinInputs));
  48.         SinInputs[InputIndex] = PiValue;
  49.     }
  50.    
  51.     flint_64 SinAnswers[] = {
  52.         { 0x3FE79C15671C10A8L }, // 0.7378031743869728    //NormalValues
  53.         { 0x3FD89B3CAC680372L }, // 0.3844749148993777  
  54.         { 0x3E7AD7F29ABCAF3BL }, // 9.99999999999998288081e-8
  55.         { 0x3FEAED52A1E94A9FL }, // 0.8414700662927607  
  56.         { 0x3FC55A8B0D1EE780L }, // 0.16682565823230888
  57.         { 0x3FB97F8EC3B8B32FL }, // 0.0997680529077115  
  58.                                  //                    
  59.         { 0xBFEF3E3867909F45L }, //-0.9763452551605744    //HalfPiValues
  60.         { 0x3FEFFD1FB2943722L }, // 0.9996489036436496  
  61.         { 0x3FEAED54AC0AE885L }, // 0.8414710388381229  
  62.         { 0xBFEAED54AC0AE885L }, //-0.8414710388381229  
  63.                                  //                    
  64.         { 0xBFCA8B0C49D4AC3AL }, //-0.20736840825097308   //PiValues
  65.         { 0xBFEEB15E54830DA2L }, //-0.9591514254211015  
  66.         { 0xBFAA291D12A22F8FL }, //-0.05109492161235983775
  67.         { 0x3FE8BE2C114F65B9L }, // 0.7732143724526203  
  68.         { 0x3FEFFDA75D234936L }  // 0.9997135943506581  
  69.     };
  70.    
  71.     flint_64 CosAnswers[] = {
  72.         { 0x3FE599BAF611469AL }, //0.6750159078603304     //NormalValues
  73.         { 0x3FED8A535559210BL }, //0.9231354395824679  
  74.         { 0x3FEFFFFFFFFFFFD3L }, //0.999999999999995  
  75.         { 0x3FE14A2B0FB36F12L }, //0.5403037363680332  
  76.         { 0x3FEF8D335EE5D97DL }, //0.9859864095185881  
  77.         { 0x3FEFD7437B1B968BL }, //0.9950272945831825  
  78.                                                        
  79.         { 0x3FCBAD0298F38751L }, //0.21621735065769568    //HalfPiValues
  80.         { 0x3F9B21EC42AD6FDFL }, //0.02649659306494800159
  81.         { 0x3FE14A27E287EFA0L }, //0.5403022217210385  
  82.         { 0x3FE14A27E287EFA0L }, //0.5403022217210385  
  83.     };
  84.    
  85.     flint_64 ASinAnswers[] = {
  86.         { 0x3FEF520FABFE83E0L }, //0.97876723854653491477 //NormalValues
  87.         { 0x3FD9F693BF444FA0L }, //0.4056748740997538  
  88.         { 0x3E7AD7F29ABCAF55L }, //1.0000000000000017e-7
  89.         { 0x3FF91A6DD9AC0E3AL }, //1.5689524176422212  
  90.         { 0x3FC58E44BC4C704EL }, //0.16840419000880264059
  91.         { 0x3FB9954B79DC1102L }, //0.0999343082913278  
  92.     };
  93.    
  94.     flint_64 SqrtAnswers[] = {
  95.         { 0x3FED2669C738D163L }, //0.9109391108564008     //NormalValues
  96.         { 0x3FE41A3D13CD6ADEL }, //0.6282029520765169    
  97.         { 0x3F34B96BE9C2DA2CL }, //0.00031622776601683794
  98.         { 0x3FEFFFFE37A8D704L }, //0.9999991499996388    
  99.         { 0x3FDA33A104873FB1L }, //0.4094011825773079    
  100.         { 0x3FD437104500AA57L }, //0.31586081255469395  
  101.     };
  102.    
  103.     for (umm InputIndex = 0; InputIndex < ArrayCount(SinInputs); ++InputIndex) {
  104.         f64 InputValue = SinInputs[InputIndex];
  105.         flint_64 ExpectedSin = SinAnswers[InputIndex];
  106.         f64 OutputValue = sin(InputValue);
  107.         RecordError(InputValue, OutputValue, ExpectedSin.F64, &SinMinimax);
  108.     }
  109.    
  110.     for (umm InputIndex = 0; InputIndex < ArrayCount(CosInputs); ++InputIndex) {
  111.         f64 InputValue = CosInputs[InputIndex];
  112.         flint_64 ExpectedCos = CosAnswers[InputIndex];
  113.         f64 OutputValue = cos(InputValue);
  114.         RecordError(InputValue, OutputValue, ExpectedCos.F64, &CosMinimax);
  115.     }
  116.    
  117.     for (umm InputIndex = 0; InputIndex < ArrayCount(NormalValues); ++InputIndex) {
  118.         f64 InputValue = NormalValues[InputIndex];
  119.        
  120.         flint_64 ExpectedASin = ASinAnswers[InputIndex];
  121.         f64 OutputAsin = asin(InputValue);
  122.         RecordError(InputValue, OutputAsin, ExpectedASin.F64, &ASinMinimax);
  123.        
  124.         flint_64 ExpectedSqrt = SqrtAnswers[InputIndex];
  125.         f64 OutputSqrt = sqrt(InputValue);
  126.         RecordError(InputValue, OutputSqrt, ExpectedSqrt.F64, &SqrtMinimax);
  127.     }
  128.  
  129.     /*
  130.  
  131.     // I don't recall what this exactly was. It is something like making 128 equidistant values between 0 and 1/8,
  132.     // avoiding those values. But I'm not sure how I picked the exact values, and it seems to be slightly inaccurate
  133.     f64 TurnExtremals[128] = {
  134.         0.12499999254941944064L, 0.12402343010762706094L, 0.12304686766583472188L, 0.12207030522404238282L,
  135.         0.12109374278225004376L, 0.1201171803404577047L,  0.11914061789866536564L, 0.11816405545687302658L,
  136.         0.11718749301508068752L, 0.11621093057328834846L, 0.1152343681314960094L,  0.11425780568970367034L,
  137.         0.11328124324791133128L, 0.11230468080611899222L, 0.11132811836432665316L, 0.1103515559225343141L,
  138.         0.10937499348074197504L, 0.10839843103894963598L, 0.10742186859715729692L, 0.10644530615536495786L,
  139.         0.1054687437135726188L,  0.10449218127178027974L, 0.10351561882998794068L, 0.10253905638819560162L,
  140.         0.10156249394640326256L, 0.1005859315046109235L,  0.09960936906281858444L, 0.09863280662102624538L,
  141.         0.09765624417923390632L, 0.09667968173744156726L, 0.0957031192956492282L,  0.09472655685385688914L,
  142.         0.09374999441206455008L, 0.09277343197027221102L, 0.09179686952847987196L, 0.0908203070866875329L,
  143.         0.08984374464489519384L, 0.08886718220310285478L, 0.08789061976131051572L, 0.08691405731951817666L,
  144.         0.0859374948777258376L,  0.08496093243593349854L, 0.08398436999414115948L, 0.08300780755234882042L,
  145.         0.08203124511055648136L, 0.0810546826687641423L,  0.08007812022697180324L, 0.07910155778517946418L,
  146.         0.07812499534338712512L, 0.07714843290159478606L, 0.076171870459802447L,   0.07519530801801010794L,
  147.         0.07421874557621776888L, 0.07324218313442542982L, 0.07226562069263309076L, 0.0712890582508407517L,
  148.         0.07031249580904841264L, 0.06933593336725607358L, 0.06835937092546373452L, 0.06738280848367139546L,
  149.         0.0664062460418790564L,  0.06542968360008671734L, 0.06445312115829437828L, 0.06347655871650203922L,
  150.         0.06249999627470970016L, 0.0615234338329173611L,  0.06054687139112502204L, 0.05957030894933268298L,
  151.         0.05859374650754034392L, 0.05761718406574800486L, 0.0566406216239556658L,  0.05566405918216332674L,
  152.         0.05468749674037098768L, 0.05371093429857864862L, 0.05273437185678630956L, 0.0517578094149939705L,
  153.         0.05078124697320163144L, 0.04980468453140929238L, 0.04882812208961695332L, 0.04785155964782461426L,
  154.         0.0468749972060322752L,  0.04589843476423993614L, 0.04492187232244759708L, 0.04394530988065525802L,
  155.         0.04296874743886291896L, 0.0419921849970705799L,  0.04101562255527824084L, 0.04003906011348590178L,
  156.         0.03906249767169356272L, 0.03808593522990122366L, 0.0371093727881088846L,  0.03613281034631654554L,
  157.         0.03515624790452420648L, 0.03417968546273186742L, 0.03320312302093952836L, 0.0322265605791471893L,
  158.         0.03124999813735485024L, 0.03027343569556251118L, 0.02929687325377017212L, 0.02832031081197783306L,
  159.         0.027343748370185494L,   0.02636718592839315494L, 0.02539062348660081588L, 0.02441406104480847682L,
  160.         0.02343749860301613776L, 0.0224609361612237987L,  0.02148437371943145964L, 0.02050781127763912058L,
  161.         0.01953124883584678152L, 0.01855468639405444246L, 0.0175781239522621034L,  0.01660156151046976434L,
  162.         0.01562499906867742528L, 0.01464843662688508622L, 0.01367187418509274716L, 0.0126953117433004081L,
  163.         0.01171874930150806904L, 0.01074218685971572998L, 0.00976562441792339092L, 0.00878906197613105186L,
  164.         0.0078124995343387128L,  0.00683593709254637374L, 0.00585937465075403468L, 0.00488281220896169562L,
  165.         0.00390624976716935656L, 0.0029296873253770175L,  0.00195312488358467844L, 0.00097656244179233938L
  166.     };
  167.    
  168.     f64 Sin128Answers[128] = { //Slightly inaccurate
  169.         0.70710674808448932248L, 0.70275471141287160359L, 0.69837621642672182625L, 0.69397142797388183231L,
  170.         0.68954051189212750533L, 0.68508363500292507287L, 0.68060096510515037328L, 0.67609267096877132361L,
  171.         0.67155892232849382649L, 0.66699988987737135514L, 0.66241574526037845716L, 0.65780666106794841898L,
  172.         0.65317281082947533443L, 0.64851436900678082187L, 0.64383151098754563601L, 0.63912441307870642163L,
  173.         0.63439325249981785789L, 0.62963820737638044302L, 0.62485945673313417071L, 0.62005718048731835067L,
  174.         0.61523155944189782703L, 0.61038277527875584972L, 0.60551101055185385509L, 0.60061644868035841323L,
  175.         0.59569927394173560088L, 0.59075967146481305977L, 0.58579782722281000178L, 0.5808139280263354231L,
  176.         0.57580816151635479132L, 0.57078071615712546992L, 0.56573178122910114635L, 0.5606615468218055308L,
  177.         0.55557020382667559391L, 0.55045794392987461293L, 0.54532495960507529686L, 0.54017144410621326233L,
  178.         0.53499759146021113301L, 0.52980359645967353653L, 0.52458965465555327386L, 0.51935596234978893737L,
  179.         0.51410271658791425465L, 0.50883011515163943641L, 0.50353835655140480782L, 0.49822764001890700345L,
  180.         0.49289816549959800745L, 0.48755013364515732114L, 0.48218374580593754164L, 0.47679920402338363575L,
  181.         0.47139671102242619469L, 0.46597647020384895592L, 0.46053868563663087954L, 0.45508356205026306746L,
  182.         0.44961130482704081471L, 0.44412211999433108301L, 0.4386162142168156878L,  0.43309379478871049069L,
  183.         0.42755506962596089032L, 0.42200024725841390547L, 0.41642953682196714512L, 0.41084314805069496105L,
  184.         0.40524129126895207942L, 0.39962417738345500863L, 0.3939920178753415216L,  0.38834502479220851142L,
  185.         0.38268341074012852009L, 0.37700738887564524107L, 0.3713171728977482968L,  0.36561297703982759349L,
  186.         0.35989501606160755605L, 0.35416350524106154679L, 0.34841866036630677238L, 0.34266069772747998418L,
  187.         0.33688983410859427777L, 0.33110628677937729843L, 0.32531027348709115956L, 0.31950201244833438244L,
  188.         0.31368172234082616549L, 0.30784962229517329281L, 0.30200593188661999162L, 0.29615087112678104944L,
  189.         0.2902846604553585021L,  0.28440752073184220456L, 0.27851967322719459693L, 0.27262133961551997879L,
  190.         0.26671274196571860547L, 0.26079410273312592043L, 0.25486564475113723863L, 0.24892759122281819614L,
  191.         0.2429801657125012819L,  0.23702359213736876792L, 0.23105809475902235495L, 0.22508389817503985096L,
  192.         0.21910122731051920023L, 0.21311030740961018161L, 0.20711136402703409458L, 0.20110462301959175246L,
  193.         0.19509031053766010258L, 0.18906865301667779337L, 0.18303987716862000913L, 0.17700420997346289332L,
  194.         0.17096187867063788174L, 0.16491311075047626741L, 0.1588581339456443192L,  0.15279717622256927666L,
  195.         0.14673046577285654395L, 0.14065823100469840585L, 0.13458070053427458943L, 0.12849810317714499521L,
  196.         0.12241066793963492157L, 0.11631862401021310717L, 0.11022220075086291557L, 0.10412162768844698731L,
  197.         0.09801713450606568423L, 0.09190895103440965162L, 0.08579730724310682364L, 0.07968243323206419785L,
  198.         0.07356455922280470476L, 0.06744391554979949872L, 0.0613207326517959962L,  0.05519524106314198833L,
  199.         0.04906767140510615398L, 0.04293825437719530036L, 0.0368072207484686581L,  0.03067480134884955753L,
  200.         0.02454122706043481366L, 0.01840672880880214669L, 0.01227153755431596564L, 0.00613588428343184214L
  201.     };
  202.    
  203.     f64 Cos128Answers[128] = { //Slightly inaccurate
  204.         0.7071068142886041767L,  0.71143222838652140296L, 0.71573085746633601127L, 0.72000253968711203447L,
  205.         0.72424711422244739683L, 0.7284644212665289365L,  0.73265430204014900327L, 0.73681659879668340535L,
  206.         0.74095115482803047986L, 0.74505781447051106361L, 0.74913642311072914189L, 0.75318682719139295485L,
  207.         0.75720887421709634192L, 0.7612024127600601071L,  0.76516729246583318851L, 0.76910336405895341783L,
  208.         0.7730104793485676564L,  0.77688849123401109646L, 0.78073725371034551734L, 0.78455662187385628821L,
  209.         0.78834645192750791039L, 0.79210660118635789382L, 0.79583692808292876387L, 0.79953729217253799618L,
  210.         0.803207554138585679L,   0.80684757579779970375L, 0.81045722010543828655L, 0.81403635116044962463L,
  211.         0.81758483421058849354L, 0.82110253565748959239L, 0.82458932306169744623L, 0.82804506514765267606L,
  212.         0.83146963180863444886L, 0.83486289411165892154L, 0.8382247243023334943L,  0.84155499580966669075L,
  213.         0.8448535832508334836L,  0.84812036243589588663L, 0.8513552103724786351L,  0.85455800527039977858L,
  214.         0.85772862654625601197L, 0.86086695482796257188L, 0.86397287195924752765L, 0.8670462610041002977L,
  215.         0.87008700625117422364L, 0.87309499321814303663L, 0.87607010865601105168L, 0.87901224055337692787L,
  216.         0.88192127814065083377L, 0.8847971118942248594L,  0.88763963354059651768L, 0.8904487360604451801L,
  217.         0.89322431369266129319L, 0.89596626193832822405L, 0.89867447756465658499L, 0.90134885860887088928L,
  218.         0.90398930438204839156L, 0.90659571547290996839L, 0.90916799375156289629L, 0.91170604237319538631L,
  219.         0.914209765781722736L,   0.91667906971338496159L, 0.91911386120029577482L, 0.92151404857394277091L,
  220.         0.92387954146863869584L, 0.92621025082492366299L, 0.92850608889291819104L, 0.93076696923562693698L,
  221.         0.93299280673219299974L, 0.93518351758110267193L, 0.93733901930334051911L, 0.93945923074549466774L,
  222.         0.9415440720828121849L,  0.94359346482220443473L, 0.94560733180520229857L, 0.94758559721086114729L,
  223.         0.94952818655861545672L, 0.95143502671108295848L, 0.95330604587681822075L, 0.95514117361301555533L,
  224.         0.9569403408281611491L,  0.95870347978463432017L, 0.96043052410125780074L, 0.96212140875579695055L,
  225.         0.96377607008740780701L, 0.96539444579903387971L, 0.96697647495975159909L, 0.968522098007064331L,  
  226.         0.97003125674914487078L, 0.97150389436702633239L, 0.97293995541674135017L, 0.97433938583140951259L,
  227.         0.9757021329232729495L,  0.97702814538567999624L, 0.97831737329501685978L, 0.97956976811258721441L,
  228.         0.98078528268643965595L, 0.98196387125314294587L, 0.98310548943950897843L, 0.98421009426426340591L,
  229.         0.9852776441396638591L,  0.98630809887306570213L, 0.98730141966843526263L, 0.98825756912781048027L,
  230.         0.9891765112527089188L,  0.99005821144548308831L, 0.99090263651062302703L, 0.99170975465600609332L,
  231.         0.99247953549409392099L, 0.99321195004307649281L, 0.99390697072796328916L, 0.99456457138162147068L,
  232.         0.99518472724576105594L, 0.99576741497186705694L, 0.99631261262207853743L, 0.99682029967001456082L,
  233.         0.99729045700154699678L, 0.99772306691552015725L, 0.99811811312441723485L, 0.99847558075497351868L,
  234.         0.99879545634873636417L, 0.99907772786257189621L, 0.99932238466911842629L, 0.99952941755718656655L,
  235.         0.99969881873210602591L, 0.99983058181601907486L, 0.99992470184812066824L, 0.99998117528484521673L,
  236.     };
  237.    
  238.     for (umm ExtremalIndex = 0; ExtremalIndex < ArrayCount(TurnExtremals); ++ExtremalIndex) {
  239.         f64 InputValue = TurnExtremals[ExtremalIndex] * (f64)6.28318530717958647693L;
  240.         f64 ExpectedSin = Sin128Answers[ExtremalIndex];
  241.         f64 OutputSin = sin(InputValue);
  242.         RecordError(InputValue, OutputSin, ExpectedSin, &SinMinimax);
  243.         f64 ExpectedCos = Cos128Answers[ExtremalIndex];
  244.         f64 OutputCos = cos(InputValue);
  245.         RecordError(InputValue, OutputCos, ExpectedCos, &CosMinimax);
  246.     }
  247.  
  248.     */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement