2012-07-25 13 views
17

これはなぜコンパイルするのでしょうか?それがコンパイルして以来、それはどういう意味ですか?0xp0は0.0(16進浮動小数点定数)を出力します

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

OUTPUT:

0.0 
+0

これは 'javacの1.7.0_02'と、コンパイルされません。 '0x0p0'だけが行います。 –

+0

@TheGuyOfDoom私は '1.7.0_05'を使用しています。 –

+0

私はSun JDKを見ています。それは関連性があります。 –

答えて

9

浮動小数点の16進表記です。

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.

hereを参照してください。

+0

+1をdigit'さて、初めて浮動小数点の16進数を知っています。 –

11

The JLSがそれを説明する:

HexadecimalFloatingPointLiteral: 
    HexSignificand BinaryExponent FloatTypeSuffixopt 

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

BinaryExponent: 
    BinaryExponentIndicator SignedInteger 

BinaryExponentIndicator:one of 
    p P 

以上を踏まえ、私はしかし、p前に必須.HexDigitを期待します。

0

ただ、参考のために、ここでは手動で10進数に以下を変換する方法である:私にとって

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

enter image description here

関連する問題