P在不断的声明中 [英] P in constant declaration
问题描述
在 java.lang.Double
中,有以下常量声明:
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;
什么是 P
?区别重要吗?
我知道 L
, D
和 F
用于长
s, Double
s和 Float
s,但之前从未见过 P
。
I am aware of the L
, D
and F
used for Long
s, Double
s and Float
s, but have never seen a P
before.
推荐答案
P
(或 p
)表示一个十六进制的浮点字面值,其中有效数以十六进制指定。
The P
(or p
) indicates a hexadecimal floating-point literal, where the significand is specified in hex.
使用 p
代替 e
。您看到的 d
和 f
后缀与此正交: 0x1。 0p + 2f
和 0x1.0p + 2d
是有效的文字(一个类型为 float
另一种类型为 double
)。
The p
is used instead of the e
. The d
and f
suffixes that you've seen are orthogonal to this: both 0x1.0p+2f
and 0x1.0p+2d
are valid literals (one is of type float
and the other is of type double
).
乍一看似乎 0x
前缀足以识别十六进制浮点字面值,那么为什么选择Java设计者将字母从 e
更改为 p
?这与 e
是一个有效的十六进制数字有关,因此保留它会引起解析模糊。考虑:
At first glance it might seem that the 0x
prefix is sufficient to identify a hex floating-point literal, so why have the Java designers chosen to change the letter from e
to p
? This has to do with e
being a valid hex digit, so keeping it would give rise to parsing ambiguity. Consider:
0x1e+2
这是十六进制 double
还是两个整数的总和, 0x1e
和 2
?当我们将 e
更改为 p
时,歧义已解决:
Is that a hex double
or the sum of two integers, 0x1e
and 2
? When we change e
to p
, the ambiguity is resolved:
0x1p+2
这篇关于P在不断的声明中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!