2012-07-25 19 views
17

मुझे आश्चर्य है कि यह क्यों संकलित करता है? और इसका मतलब क्या है क्योंकि यह संकलित करता है?0xp0 प्रिंट 0.0 (हेक्साडेसिमल फ्लोटिंग प्वाइंट लिटल)

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

उत्पादन:

0.0 
+0

मेरे लिए यह संकलन नहीं है, 'javac 1.7.0_02' साथ। केवल '0x0p0' करता है। –

+0

@TheGuyOfDoom मैं '1.7.0_05' का उपयोग कर रहा हूं। –

+0

मैं सूर्य जेडीके के रास्ते से हूं। यह प्रासंगिक हो सकता है। –

उत्तर

9

यह एक फ़्लोटिंग पॉइंट हेक्स शाब्दिक है।

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 खैर, पहली बार मुझे फ्लोटिंग पॉइंट हेक्स के बारे में पता है। –

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 

ऊपर के आधार पर, मैं एक अनिवार्य .HexDigitp से पहले हालांकि उम्मीद करेंगे।

0
बस संदर्भ के लिए

, यहाँ है कैसे मैन्युअल रूप से परिवर्तित करने के लिए एक दशमलव संख्या के लिए निम्न:

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

enter image description here

संबंधित मुद्दे