How to write a floating point hex literal in java?

For a 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" in java.

If the same number is written in a "hex float literal" I found it as

-0X32p-2f

which is wrong. This is the meaning -25.0

. I considered 50

how 0x32

and came out with these designations.

How do I know how to write the value above -5 x 10^-1

in a hexadecimal floating point literal?

+3


source to share


2 answers


See section 3.10.2 of the Java Language Specification:

In the case of a hexadecimal floating point literal, the exponent is binary ; it is a cardinality of 2, not a cardinality of 10 as in floating point decimal numbers.



So 0x32p-2f

means 50 times 2 to -2, not 10 to -2.

The hexadecimal float

literal representing 0.5

will 0x1p-1f

.

+5


source


Check out the documentation for Double.toHexString()

.



-1


source







All Articles