-
Bug
-
Resolution: Fixed
-
P4
-
1.1.3
-
1.2beta4
-
generic
-
solaris_2.5.1
-
Not verified
Run the following program. It shows that for the really big long value
given, conversion to float using Float.valueOf() differs from the value
of converting the same string to a Long, then casting to a float.
I believe that the latter process gives the correct answer, where the
former is wrong in the least significant bit.
class doubleRoundBug {
/*
* try to demonstrate input error caused
* by double rounding.
*/
static String instring = "18014399583223809";
public static void main( String ignore[] ){
long lval = Long.valueOf( instring).longValue();
float f1 = Float.valueOf( instring).floatValue();
float f2 = (float)lval;
if ( f1 == f2 ){
System.out.println("OK");
} else {
System.out.println("String "+instring+" =>"+f1 );
System.out.println("Long "+lval+" =>"+f2 );
System.out.println(f1+" != "+f2);
}
}
}
Output is:
String 18014399583223809 =>1.80143985E16
Long 18014399583223809 =>1.80144007E16
1.80143985E16 != 1.80144007E16
richard.tuck@Eng 1997-08-11
given, conversion to float using Float.valueOf() differs from the value
of converting the same string to a Long, then casting to a float.
I believe that the latter process gives the correct answer, where the
former is wrong in the least significant bit.
class doubleRoundBug {
/*
* try to demonstrate input error caused
* by double rounding.
*/
static String instring = "18014399583223809";
public static void main( String ignore[] ){
long lval = Long.valueOf( instring).longValue();
float f1 = Float.valueOf( instring).floatValue();
float f2 = (float)lval;
if ( f1 == f2 ){
System.out.println("OK");
} else {
System.out.println("String "+instring+" =>"+f1 );
System.out.println("Long "+lval+" =>"+f2 );
System.out.println(f1+" != "+f2);
}
}
}
Output is:
String 18014399583223809 =>1.80143985E16
Long 18014399583223809 =>1.80144007E16
1.80143985E16 != 1.80144007E16
richard.tuck@Eng 1997-08-11