In java.lang.Double, there are the following constant declarations:
public static final double MAX_VALUE = 0x1.fffffffffffffP+1023;
public static final double MIN_NORMAL = 0x1.0p-1022;
What is the P for? Is the difference in case important?
I am aware of the L, D and F used for Longs, Doubles and Floats, but have never seen a P before.
The
P(orp) indicates a hexadecimal floating-point literal, where the significand is specified in hex.The
pis used instead of thee. Thedandfsuffixes that you’ve seen are orthogonal to this: both0x1.0p+2fand0x1.0p+2dare valid literals (one is of typefloatand the other is of typedouble).At first glance it might seem that the
0xprefix is sufficient to identify a hex floating-point literal, so why have the Java designers chosen to change the letter frometop? This has to do withebeing a valid hex digit, so keeping it would give rise to parsing ambiguity. Consider:Is that a hex
doubleor the sum of two integers,0x1eand2? When we changeetop, the ambiguity is resolved: