例如,在 Java 中,这是一个十六进制数 0x10
。
0x10.2P2
是一个正确的十六进制 double 值。
但为什么 0x1f.2
不正确?为什么我们不能使用它,虽然 0x1f.2P1
应该给出相同的结果但它有效?
最佳答案
好吧,如果您的意思是为什么,我们将不得不希望其中一位负责语法的人会插话。在我看来,使指数可选不会损害解析文字的能力,但我没有详细考虑过。我所能提供的是 Java Language Specification §3.10.2需要它:
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.
关于java - 为什么 Java 中的十六进制实数需要指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37365652/