Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++17 Hexidecimal floating point literal single precision suffix conflict?

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.

like image 200
Keldor314 Avatar asked Dec 17 '22 20:12

Keldor314


1 Answers

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.

like image 122
Nicol Bolas Avatar answered Jan 16 '23 18:01

Nicol Bolas