2012-07-25 15 views
17

Bunun neden derlendiğini merak ediyorum? ve derlediğinden bu ne anlama geliyor?0xp0 baskıları 0.0 (Onaltılık Yüzer Noktalı Literal)

System.out.println(0xp0); // p? 

ÇIKIŞ:

0.0 
+0

Benim için bu derleme değil, 'javactır 1.7.0_02' ile. Sadece '0x0p0' yapar. –

+0

@TheGuyOfDoom '1.7.0_05' kullanıyorum. –

+0

Güneş JDK'sındayım. Bu alakalı olabilir. –

cevap

9

Bu bir kayan nokta hex literal.

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.

özellikleri here bakınız. Sadece başvuru için

+0

+1 Şey, ilk kez kayan nokta hex'i biliyorum. –

11

The JLS bunu açıklıyor:

HexadecimalFloatingPointLiteral: 
    HexSignificand BinaryExponent FloatTypeSuffixopt 

HexSignificand: 
    HexNumeral 
    HexNumeral . 
    0 x HexDigitsopt . HexDigits 
    0 X HexDigitsopt . HexDigits 

BinaryExponent: 
    BinaryExponentIndicator SignedInteger 

BinaryExponentIndicator:one of 
    p P 

yukarıdaki dayanarak, Yine de p önce zorunlu .HexDigit beklenebilir.

0

, burada elle ondalık sayı için aşağıdaki dönüştürmek için yapılması gerekenler:

double hfpl = 0x1e.18p4; 
System.out.println(hfpl); // 481.5 

enter image description here