I was looking at the C++17 spec for floating point literals and found a problem. How do you tell the difference between the digit F
and the suffix F
for single precision?
For instance, does the literal 0x1p0F
translate to a double precision 32768.0L
or a single precision 1.0F
?
The spec says that the suffix is optional, and that no suffix indicates double precision, so, as written, there is a definite ambiguity.
A hex-float literal must use a p
exponent. The exponent is defined using non-hexadecimal digits (a decimal integer that represents the exponent to be applied to 2). Therefore, it cannot contain "A-F" characters. So there is no ambiguity. 0x1p0F
has an exponent of "0", and is of type float
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With