Title
Clarify which floating-point-literals are valid
Status
open
Section
5.13.4 [lex.fcon]
Submitter
Jan Schultke

Created on 2025-11-10.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-11-19.20:32:32

Suggested resolution:

Change in 5.13.4 [lex.fcon] paragraph 3 as follows:

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.
[ Example:

The following example assumes that std::float32_t is supported (6.9.3 [basic.extended.fp]).

  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
-- end example ]
Date: 2025-11-10.00:00:00

(From submission #801.)

Implementations diverge on whether the following declaration is well-formed:

  float x = 1e100000000000000000000000000000000000000000000000.f;

However, 5.13.4 [lex.fcon] paragraph 3 seems to be clear that this is allowed if float has a representation of infinity.

History
Date User Action Args
2025-11-19 20:32:32adminsetmessages: + msg8402
2025-11-10 00:00:00admincreate