-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Reference (section label): [lex.fcon]
Issue description
Implementations diverge on whether the following declaration is well-formed (https://godbolt.org/z/hT6nza5hr):
float x = 1e100000000000000000000000000000000000000000000000.f;[lex.fcon] paragraph 3 states:
If the scaled value is not in the range of representable values for its type, the program is ill-formed. Otherwise, the value of a floating-point-literal is the scaled value if representable, else the larger or smaller representable value nearest the scaled value, chosen in an implementation-defined manner.
Following the changes made in CWG2723, the range of representable values includes all real numbers if the infinities can be represented in float, meaning that x is infinity, and the program is well-formed. GCC and Clang are correct; MSVC and EDG are not. This should be clarified.
Note that GCC and Clang have been using the definition of "range of representable values" that dates back to at least C11, even though it did not exist in C++ until recently.
Suggested resolution
Add an example below [lex.fcon] paragraph 3:
std::float32_t x = 0.0f32; // value 0 is exactly representable
std::float32_t y = 0.1f32; // rounded to one of two values nearest to 0.1
std::float32_t z = 1e1000000000f32; // either greatest finite value or positive infinity