bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] pi in gawk


From: John Haque
Subject: Re: [bug-gawk] pi in gawk
Date: Fri, 17 Feb 2012 04:37:38 -0600
User-agent: Mutt/1.4.2.2i

Hi.

On Wed, Feb 15, 2012 at 11:29:17AM -0700, Nelson H. F. Beebe wrote:
...
 
> How did I get the numeric values in the first place?  I used a
> symbolic algebra system:
> 
> % maple
> > evalf(Pi, 35);
>                       3.1415926535897932384626433832795029
> % math
> In[1]:= N[Pi, 35]
> Out[1]= 3.1415926535897932384626433832795029
> 
> % maxima
> (%i1) fpprec : 35$
> (%i2) bfloat(atan2(0,-1));
> (%o2)               3.1415926535897932384626433832795029b0
> 
> % gp
> ? \p 35
>    realprecision = 38 significant digits (35 digits displayed)
> ? Pi
> %1 = 3.1415926535897932384626433832795029

Why 35?
The decimal(binary) precision for IEEE 754 128-bit is 34(113).

gawk+MPFR can now compute atan2 in arbitrary precision.

With the default rounding to the nearest:

$ ./gawk -M -vPREC=113 'BEGIN { printf("%.33f\n", atan2(0, -1)) }'
3.141592653589793238462643383279503

Rounding towards zero:

$ ./gawk -M -vPREC=113 -vRNDMODE="RNDZ" 'BEGIN { printf("%.33f\n", atan2(0, 
-1)) }'
3.141592653589793238462643383279502

If I increase the precision to 117 and print 1 more digit:

$ ./gawk -M -vPREC=115 'BEGIN { printf("%.34f\n", atan2(0, -1)) }'
3.1415926535897932384626433832795029

However, rounding towards zero gives us:

$ ./gawk -M -vPREC=115 -vRNDMODE="RNDZ" 'BEGIN { printf("%.34f\n", atan2(0, 
-1)) }'
3.1415926535897932384626433832795027

I was expecting 8 or 9 in the last digit, not 7.
Is there an explanation?

Thanks.

John



reply via email to

[Prev in Thread] Current Thread [Next in Thread]