Subject: Fwd: Re: cos(1.0d97) with GCL, Clozure, and Julia
From: Richard Fateman
Date: Thu, 10 May 2012 17:21:08 -0700
-------- Original Message --------
Subject: Re: [Maxima] cos(1.0d97) with GCL, Clozure, and Julia
Date: Thu, 10 May 2012 17:19:58 -0700
From: Richard Fateman <fateman at eecs.berkeley.edu>
To: Barton Willis <willisb at unk.edu>
On 5/10/2012 5:01 AM, Barton Willis wrote:
> With GCL:
>
> (%i63) cos(1.0d97);
> (%o63) 0.44800964805919
>
> With Julia or Clozure CL:
>
> julia> cos(1.0e97)
> 0.7496172085944125
>
> $ wx86cl64
> Welcome to Clozure Common Lisp Version 1.8-r15286M (WindowsX8664)!
> ? (cos 1.0d97)
> 0.7496172085944125D0
>
> And bigfloats:
>
> (%i60) cos(1.0b97), fpprec : 2000;
> (%o60) -7.0797267715593222213703559504[1944 digits]888604264163488232493341331b-2
>
> Let me guess that Clozure& Julia turn the calculation entirely over to the (Intel) microprocessor. What on earth does GCL do?
> Is this a binary32 / binary64 confusion problem?
>
> No, I'm not surprised that the Clozure& Julia values are likely completely wrong--it just makes me wonder what GCL is doing.
>
> --bw
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
Maxima says
6.352949290110150372337895080118015434113381369350... b-1
and actually you don't need extravagant extra precision.
All you need is enough precision to exactly represent 1.0b97.
So fpprec:97 does fine.
If fpprec is 20, you are computing cosine of
9999999999999999999986855440896063627350130660722318322605057839705205096078837019768675641589760
...
The bigfloat cosine routine figures that it needs about 194 digits of pi to
reduce the given argument accurately into the range [-pi/8, pi/8] or
thereabouts.
Then a taylor series works.
Julia (etc.) presumably make an error in the representation of the
original input.
Intel (etc) know how to do the range reduction, I think.
e.g. see
http://www.researchgate.net/publication/3798381_New_algorithms_for_improved_transcendental_functions_on_IA-64