Java 十六进制浮点字面量歧义

标签 java floating-point hex ambiguity

Java specification ,它说了以下内容:

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.

据我了解,指示字母的指数必须是 p 或 P 才能解决与十六进制数字 e 或 E 的歧义。为什么它说后缀指示类型(float vs double)是可选的,当使用它时会用同样是十六进制数字的字母d、D、f、F引入歧义?

最佳答案

根据grammar :

DecimalFloatingPointLiteral:
  Digits . [Digits] [ExponentPart] [FloatTypeSuffix] 
  . Digits [ExponentPart] [FloatTypeSuffix] 
  Digits ExponentPart [FloatTypeSuffix] 
  Digits [ExponentPart] FloatTypeSuffix

HexadecimalFloatingPointLiteral:
  HexSignificand BinaryExponent [FloatTypeSuffix]

可选的 FloatTypeSuffix 必须 遵循十六进制 float 的强制性 BinaryExponent

如果添加fd 而没有BinaryExponent,则它是十进制 float 。

关于Java 十六进制浮点字面量歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51026405/

相关文章:

c# - IFormattable.ToString 无法按预期进行十六进制格式化

java - 安卓菜单和子菜单

java - 如何将 DocumentSnapshot id 获取为字符串?

JavaFX 8 在 Outlook 中创建新邮件

c++ - C++03 保证 `double` 准确表示小整数吗?

c++ - 如何将 cpp_dec_float_50 转换为 cpp_int?关于一般的 float ?

c - 理解从整数到 float 的转换

java - 在 Splash Screen 中接收 URL Intent 并在 WebView 中加载 URL

python - Ruby 和 Minecraft 数据包

javascript - 带label标签的文件拖拽输入框