-
Bug
-
Resolution: Fixed
-
P3
-
1.0, 1.0.2, 1.1, 1.1.6, 1.2.0
-
beta
-
generic, x86, sparc
-
generic, solaris_2.4, solaris_2.5, solaris_2.5.1, windows_nt
to have special code to check for the bouncary conditions where the floating operand
is NaN or has a value too large or to small to be representable in the integer format.
Related bugs 1240810, 1240807
The SPARC architecture happens to handle some of these cases correctly, but not others.
Porting the C code as written to other architectures may not work properly.
Example: converting a NaN (float or double) to int, Java produces 0 (which is what the
spec says) but produces 9223372036854775807 or -9223372036854775808 when converting a NaN to long (depending on whether the hardware thinks it has a
"positive NaN" or a "negative NaN" in hand, though Java is supposed to make no
such distinction).
Here is some test code I was using (I am gratified to have found no difference in behavior
among constants computed at compile time and values computed at run time):
class Fltint {
public static void main(String[] argv) {
foo(0.0f/0.0f, 0.0d/0.0d, 1.0e25f, 1.0e25d, 1.0e50d);
}
static void foo(float pnan, double pdnan, float p25, double pd25, double pd50) {
float vnan = 0.0f/0.0f;
double vdnan = 0.0/0.0;
float v25 = 1.0e25f;
double vd25 = 1.0e25d;
double vd50 = 1.0e50d;
System.out.println(0.0f/0.0f + ", " + pnan + ", " + vnan);
System.out.println(0.0d/0.0d + ", " + pdnan + ", " + vdnan);
System.out.println((int)(0.0f/0.0f) + ", " + (int)pnan + ", " + (int)vnan);
System.out.println((long)(0.0f/0.0f) + ", " + (long)pnan + ", " + (long)vnan);
System.out.println((int)(0.0d/0.0d) + ", " + (int)pdnan + ", " + (int)vdnan);
System.out.println((long)(0.0d/0.0d) + ", " + (long)pdnan + ", " + (long)vdnan);
System.out.println((int)(-(0.0f/0.0f)) + ", " + (int)(-pnan) + ", " + (int)(-vnan));
System.out.println((long)(-(0.0f/0.0f)) + ", " + (long)(-pnan) + ", " + (long)(-vnan));
System.out.println((int)(-(0.0d/0.0d)) + ", " + (int)(-pdnan) + ", " + (int)(-vdnan));
System.out.println((long)(-(0.0d/0.0d)) + ", " + (long)(-pdnan) + ", " + (long)(-vdnan));
System.out.println((int)1.0e25f + ", " + (int)p25 + ", " + (int)v25);
System.out.println((long)1.0e25f + ", " + (long)p25 + ", " + (long)v25);
System.out.println((int)-1.0e25f + ", " + (int)-p25 + ", " + (int)-v25);
System.out.println((long)-1.0e25f + ", " + (long)-p25 + ", " + (long)-v25);
System.out.println((int)1.0e25d + ", " + (int)pd25 + ", " + (int)vd25);
System.out.println((long)1.0e25d + ", " + (long)pd25 + ", " + (long)vd25);
System.out.println((int)-1.0e25d + ", " + (int)-pd25 + ", " + (int)-vd25);
System.out.println((long)-1.0e25d + ", " + (long)-pd25 + ", " + (long)-vd25);
System.out.println((int)1.0e50d + ", " + (int)pd50 + ", " + (int)vd50);
System.out.println((long)1.0e50d + ", " + (long)pd50 + ", " + (long)vd50);
System.out.println((int)-1.0e50d + ", " + (int)-pd50 + ", " + (int)-vd50);
System.out.println((long)-1.0e50d + ", " + (long)-pd50 + ", " + (long)-vd50);
}
}
Dimtry.Khukhro@Eng 1998-10-14
JDK1.2fcsN with jit on Ultra-1 still fails JCK tests
vm/instr/d2i/d2i001/d2i00101/d2i00101.html
vm/instr/f2i/f2i001/f2i00101/f2i00101.html
Note that the tests pass on SparcStation-10, that is,
JVM implementation still "relies on hardware idiosyncracies".
The above test Fltint also fails.
- duplicates
-
JDK-1239497 conversion of double NaN to integral type doesn't produce zero
- Closed
-
JDK-4086717 java.lang.math.Round returning a bad answer
- Closed
-
JDK-4071785 (long)(Double.NaN) should yield 0 but doesn't
- Closed
-
JDK-4175006 Math.round(Float.NaN) returns Integer.MAX_VALUE instead of 0
- Closed
- relates to
-
JDK-4007658 wrong conversion of floating-point to integral types in Windows
- Closed
-
JDK-4686820 narrowing from float -NaN to int should produce constant 0
- Closed
-
JDK-1266773 wrong narrowing primitive conversion
- Closed
-
JDK-1266803 wrong narrowing primitive conversion
- Closed
-
JDK-1266804 wrong narrowing primitive conversion
- Closed