On Oct 30, 2008, at 6:16 PM, Bradley Lucier wrote:
I believe that all the others are because of the following somewhat disheartening difference.
On my x86-64 linux box running Ubuntu 8.4:
frying-pan:~> gsi Gambit v4.3.0
(atan 1)
.7853981633974483
(sin (atan 1))
.7071067811865475
(cos (atan 1))
.7071067811865476
On my Mac G5 running 10.5.5:
[descartes:~/programs/gambc-v4_2_8] lucier% gsi/gsi Gambit v4.2.9
(atan 1)
.7853981633974483
(sin (atan 1))
.7071067811865476
(cos (atan 1))
.7071067811865475
Which one is correct, I don't know. Perhaps there's a double- rounding going on somewhere. (I'm glad I finally tracked this down.)
Well, I ran things through my computable reals package (with a quick implementation of computable-sin and computable-cos, so there could be bugs here) and got
[descartes:computation/computational-reals/src] lucier% gsi Gambit v4.3.0
(load "exact-reals.scm")
"/Volumes/lucier/text/courses/computation/computational-reals/src/ exact-reals.scm"
(computable->inexact (computable-/-by-integer computable-pi 4))
.7853981633974483
(computable->inexact (computable-sin (computable-/-by-integer
computable-pi 4))) .7071067811865476
(computable->inexact (computable-sin (exact->computable (inexact- exact (computable->inexact (computable-/-by-integer computable-pi
4)))))) .7071067811865475
(computable->inexact (computable-cos (computable-/-by-integer
computable-pi 4))) .7071067811865476
(computable->inexact (computable-cos (exact->computable (inexact- exact (computable->inexact (computable-/-by-integer computable-pi
4)))))) .7071067811865476
So the inexact (double-precision floating-point) approximations to the sine and cosine of exact pi/4 are equal, as one would expect, but the inexact approximations to the sine and cosine of the inexact approximation to pi/4 are not equal (it's obvious that they're not equal to infinite precision, but indeed they round to different floating-point numbers) and it appears that glibc on linux is getting it right and the math library on Mac OS X 10.5.5 is getting it wrong.
I'm sure everyone on this list was just dying to hear how this mystery turned out ;-).
Brad