[FIX][BUG] Float NaN's ( retracting patch for #testNaN2 )

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Sep 28 01:51:48 UTC 2004


"Boris Gaertner" <Boris.Gaertner at gmx.net> wrote:

	I use Squeak in Windows, with an Intel Celeron. On that
	platform  the expressions
	1.0e200 sin   and  1.0e200 tan
	answer two different representations of  NaN.
	
which is certainly a wrong answer.

	The Intel documentation (IA-32 Intel Architecture
	Software Developer's Manual)
	says for instructions  FSIN  and  FPTAN:
	
	<citation>
	The source operand must be given in radians and must be
	within the range -2^63 to +2^63.
	</citation>

which is why a C compiler *MUST NOT* convert calls to sin() and tan()
directly to uses of the FSIN and FPTAN instructions, unless the
programmer has explicitly requested a non-standard fp mode (rather like
the "-fnonstd" option of the Sun C compiler or the "-ffast-math" option
of GCC.

	Source values outside the range -2^63 to +2^63 can be
	reduced to the range of the instruction by subtracting an
	appropriate integer multiple of 2*pi or by using the
	FPREM instruction with a divisor of 2*pi. See the section
	titled 'Pi' in Chapter 8 of the IA-32 Intel Architecture
	Software Developer's Manual, Volume 1, for a discussion
	of the proper value to use for pi in performing such reductions.

Which is what someone implementing sin() and tan() in the maths library
might do, yes.  Although it is not the best advice.  The Sun math library
uses "infinite precision pi" for argument reduction.  This can make testing
a bit tricky as sin(3.14.......) is non-zero in the Sun library even for the
representable number closest to pi.  Demonstration:
    f% cat >sin.c
    #include "math.h"
    int main(void) { printf("%g\n", sin(M_PI)); return 0; }
    <EOF>
    f% cc sin.c -lm
    f% a.out
    1.22465e-16
Where this _really_ matters of course is precisely for those very large
argument values; using "infinite precision pi" and using the Intel
recommended value will give you quite different answers.

	In other words: The implementor of a maths library has the
	permission to do whatever he thinks is suitable.
	
No, that's not what it says.  They cannot give that permission.
Permission to deliver bad answers in the name of speed can only
come from the language standard or the programmer who invokes the compiler.




More information about the Squeak-dev mailing list