# [Mono-list] Math precision.

Bob Smith bob@thestuff.net
19 Jul 2001 12:30:36 -0600

```Blah. Misspelling. That is, CORDIC not CODIC. Sorry. :)

On 19 Jul 2001 12:22:50 -0600, Bob Smith wrote:
> Hello all,
>
> I've been working on the System.Math class, trying to implement
> everything in C# without useing P/Invoke. I've been fairly successfull
> at implementing the trig functions like sin/cos, but I've so far not
> been able to get the precission of the results more precise then 15
> decimals. What would everyone prefer I do. Will 15 decimal precision be
> good enough until I can find a way to do it better, or should I just
> give up and P/Invoke the C sin/cos function?
>
> For those math types, here's the algarithm I'm useing (CODIC in C). Can
> anyone see a way to improve it? A and K were generated useing Octave.:
>
> double my_sin(double t){
>   int j, d;
>   double x=K, y=0, z=t, ox=K, oy=0, p=2;
>   for(j=0; j<50; j++){
>     d=(z<0)?-1:1;
>     p/=2;
>     x -= d*oy*p;
>     y += d*ox*p;
>     z -= d*A[j];
>     ox=x; oy=y;
>   }
>   return y;
> }
>
> static const double
> K=6.0725293500888144482274810798116959631443023681640625000e-01;
>
> static const double A[]={
> 7.8539816339744827899949086713604629039764404296875000000e-01,
> 4.6364760900080609351547877849952783435583114624023437500e-01,
> 2.4497866312686414347332686247682431712746620178222656250e-01,
> 1.2435499454676143815667899161780951544642448425292968750e-01,
> 6.2418809995957350023054743815009715035557746887207031250e-02,
> 3.1239833430268277442154456480238877702504396438598632812e-02,
> 1.5623728620476831294161534913200739538297057151794433594e-02,
> 7.8123410601011111439873069173245312413200736045837402344e-03,
> 3.9062301319669717573901390750279460917226970195770263672e-03,
> 1.9531225164788187584341550007138721412047743797302246094e-03,
> 9.7656218955931945943649274965991935459896922111511230469e-04,
> 4.8828121119489828992621394121442790492437779903411865234e-04,
> 2.4414062014936177124474481203719733457546681165695190430e-04,
> 1.2207031189367020785306594543584424172877334058284759521e-04,
> 6.1035156174208772593501454162279173942806664854288101196e-05,
> 3.0517578115526095727154734515984557674528332427144050598e-05,
> 1.5258789061315761542377868187347900175154791213572025299e-05,
> 7.6293945311019699810389967098434027548137237317860126495e-06,
> 3.8146972656064961417507561819428829608114028815180063248e-06,
> 1.9073486328101869647792853193490891783312690677121281624e-06,
> 9.5367431640596084412763106322175055140633048722520470619e-07,
> 4.7683715820308884228106408205427602098325223778374493122e-07,
> 2.3841857910155797366768810983256310365163699316326528788e-07,
> 1.1920928955078068089973856351695968847081985586555674672e-07,
> 5.9604644775390552208106095333564611316035097843268886209e-08,
> 2.9802322387695302573832649363667901543095695160445757210e-08,
> 1.4901161193847654595638774893944650257182615860074292868e-08,
> 7.4505805969238281250000000000000000000000000000000000000e-09,
> 3.7252902984619140625000000000000000000000000000000000000e-09,
> 1.8626451492309570312500000000000000000000000000000000000e-09,
> 9.3132257461547851562500000000000000000000000000000000000e-10,
> 4.6566128730773925781250000000000000000000000000000000000e-10,
> 2.3283064365386962890625000000000000000000000000000000000e-10,
> 1.1641532182693481445312500000000000000000000000000000000e-10,
> 5.8207660913467407226562500000000000000000000000000000000e-11,
> 2.9103830456733703613281250000000000000000000000000000000e-11,
> 1.4551915228366851806640625000000000000000000000000000000e-11,
> 7.2759576141834259033203125000000000000000000000000000000e-12,
> 3.6379788070917129516601562500000000000000000000000000000e-12,
> 1.8189894035458564758300781250000000000000000000000000000e-12,
> 9.0949470177292823791503906250000000000000000000000000000e-13,
> 4.5474735088646411895751953125000000000000000000000000000e-13,
> 2.2737367544323205947875976562500000000000000000000000000e-13,
> 1.1368683772161602973937988281250000000000000000000000000e-13,
> 5.6843418860808014869689941406250000000000000000000000000e-14,
> 2.8421709430404007434844970703125000000000000000000000000e-14,
> 1.4210854715202003717422485351562500000000000000000000000e-14,
> 7.1054273576010018587112426757812500000000000000000000000e-15,
> 3.5527136788005009293556213378906250000000000000000000000e-15,
> 1.7763568394002504646778106689453125000000000000000000000e-15,
> 8.8817841970012523233890533447265625000000000000000000000e-16,
> 4.4408920985006261616945266723632812500000000000000000000e-16
> };
>
>
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>

```