sqrt interpreter Q

Andrew Haley aph@cambridge.redhat.com
Fri Feb 8 06:07:00 GMT 2002


Tom Tromey writes:
 > >>>>> "Andreas" == Andreas Tobler <toa@pop.agri.ch> writes:
 > 
 > Andreas> Doing it with gij I get the following:
 > Andreas> [titanium:~] andreast% gij my_sqrt
 > Andreas> sqrt_int: -2147483648
 > Andreas> sqrt_double: NaN
 > Andreas> sqrt_long: -9223372034707292160
 > 
 > I looked at this a bit.
 > On x86 the appended program prints the `int' value.
 > So I think the C++ compiler translates `(int) NaN' differently from
 > the Java compiler.

Yeah, I wrote special code in the Java compiler to do the Right Thing.

It's:

/* Convert an IEEE real to an integer type.  The result of such a
   conversion when the source operand is a NaN isn't defined by
   IEEE754, but by the Java language standard: it must be zero.  Also,
   overflows must be clipped to within range.  This conversion
   produces something like:

      ((expr >= (float)MAX_INT)
       ? MAX_INT 
       : ((expr <= (float)MIN_INT)
	  ? MIN_INT
	  : ((expr != expr)
	     ? 0 
	     : (int)expr))) */

in java/typeck.c.

Andrew.



More information about the Java mailing list