For number -5 x 10^-1
i.e., -0.5
, I could write,
-5E-1f
or -50E-2f
or -0.05E+1F
as "decimal floating point literal" in java.
If the same number is written in "hexadecimal floating literal", I found it as
-0X32p-2f
which is wrong. This value is -25.0
. I considered 50
as 0x32
and came out with this notation.
How do I learn writing the above value -5 x 10^-1
in hexadecimal floating point literal?
See section 3.10.2 of the Java Language Specification:
In case of a hexadecimal floating point literal, the exponent is a binary exponent; it's a power of 2, not a power of 10 as in decimal floating point literals.
So
0x32p-2f
means 50 times 2 to the power -2, not times 10 to the power -2.A hexadecimal
float
literal that represents0.5
would be0x1p-1f
.