-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.6
-
x86
-
windows_nt
Name: tb29552 Date: 05/13/98
I should be able to take any Number, run toString on it and then recreate the
Number from the String. This generally works, but in the case of NaN values,
the Number classes seem to punt. For example, the following will not work
because the Double constructor can't handle input of "NaN":
new Double(Double.NaN.toString());
Sample program follows:
/*
* I should be able to take any Number, run toString on
* it and then recreate the Number from the String.
* This generally works, but in the case of NaN values,
* the Number classes seem to punt. For example, the
* following will not work because the Double
* constructor can't handle input of "NaN":
*/
import java.lang.Double;
class NaN_Test {
public static void outputMessage(){
System.out.println("java.version = " +
System.getProperty("java.version"));
System.out.println("O/S Name = " +
System.getProperty("os.name"));
System.out.println("O/S architecture = " +
System.getProperty("os.arch"));
System.out.println("O/S version = " +
System.getProperty("os.version"));
}
public static void main(String[] args){
outputMessage();
//The first example works as expected:
Double one = new Double (1.0D);
Double ot = new Double (one.toString());
System.out.println("\nCreated Double ot with value: " + ot);
//The second example gives "java.lang.NumberFormatException: NaN"
Double nan = new Double (Double.NaN);
Double nt = new Double (nan.toString());
System.out.println("Created Double nt with value: " + nt);
}
}
% javac NaN_Test.java
% java NaN_Test
java.version = 1.1.6
O/S Name = Solaris
O/S architecture = sparc
O/S version = 2.x
Created Double ot with value: 1.0
java.lang.NumberFormatException: NaN
at java.lang.Double.<init>(Double.java)
at NaN_Test.main(NaN_Test.java:33)
(Review ID: 29465)
======================================================================
- relates to
-
JDK-4428772 Establish invariant for Float & Double classes and their string representations
-
- Resolved
-