Me pregunto por qué esta compila? y ¿qué significa ya que compila?0xp0 imprime 0.0 (Literal punto hexadecimal flotante)
System.out.println(0xp0); // p?
SALIDA:
0.0
Me pregunto por qué esta compila? y ¿qué significa ya que compila?0xp0 imprime 0.0 (Literal punto hexadecimal flotante)
System.out.println(0xp0); // p?
SALIDA:
0.0
Es un literal hexadecimal de coma flotante.
For hexadecimal floating-point literals, at least one digit is required (in either the whole number or the fraction part), and the exponent is mandatory, and the float type suffix is optional. The exponent is indicated by the ASCII letter p or P followed by an optionally signed integer.
Consulte la especificación here.
+1 Bueno, la primera vez que sé sobre el punto flotante hex. –
The JLS lo explica:
HexadecimalFloatingPointLiteral:
HexSignificand BinaryExponent FloatTypeSuffixopt
HexSignificand:
HexNumeral
HexNumeral .
0 x HexDigitsopt . HexDigits
0 X HexDigitsopt . HexDigits
BinaryExponent:
BinaryExponentIndicator SignedInteger
BinaryExponentIndicator:one of
p P
base en lo anterior, yo esperaría un sistema obligatorio de .HexDigit
antes de la p
, sin embargo.
Para mí esto no compila, con 'javac 1.7.0_02'. Solo '0x0p0' lo hace. –
@TheGuyOfDoom Estoy usando '1.7.0_05'. –
Estoy por cierto en el Sun JDK. eso podría ser relevante. –