Name: gm110360 Date: 04/15/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Service Pack 2
A DESCRIPTION OF THE PROBLEM :
Converting hex strings representing floating point values
that in its integer bit representation would represent a
negative integer value always fail. The problem comes from
the Integer.parseInt method. The problem is best explained
by an example:
The float value -8.0014E-13 has the following
hexadecimal representation ab61382a which is
equivalent to the decimal integer -1419691990.
The following does not work:
float f = Float.intBitsToFloat(Integer.parseInt
("ab61382a",16));
But the followoing does:
float f = Float.intBitsToFloat(Integer.parseInt
("2B61382A",16) | 0x80000000);
It does not help to add "-" in front of the ab61382a number.
Since Float does not have the "parseIntBitRepresentation
(String, hex)" method you have to go via Integer. The
presence of the Integer.floatValue() method indicates to me
that it must be possible to parse the value above.
(Furthermore I don't see the point in requiring the sign in
front of the hexadecimal representation where the msb
equals the sign).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Just compile and run the code supplied
2.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
As described under description
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Run code
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class HexFloatError {
public static void main(String[] args) {
//Works:
float f = Float.intBitsToFloat(Integer.parseInt("2B61382A",16) |
0x80000000);
// Does not work
//float f = Float.intBitsToFloat(Integer.parseInt("ab61382a",16));
int iF = Float.floatToIntBits(f);
System.out.println("hexFloat: "+f);
System.out.println("hexFloat hex: " + Integer.toHexString(iF) + " " +
iF);
}
}
---------- END SOURCE ----------
(Review ID: 145421)
======================================================================