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

Created on 2025-11-10.00:00:00 last changed 1 week ago

Messages

Date: 2026-03-15.00:00:00

Additional notes (March, 2026)

Assigned to SG6 at the request of the SG6 chair, via paper issue 2684.

The above resolution was approved by SG6 and EWG.

Date: 2026-03-27.18:23:15

Proposed resolution (approved by CWG 2026-03-27):

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
2026-03-27 18:23:15adminsetstatus: open -> ready
2026-03-26 19:27:50adminsetmessages: + msg8523
2025-11-19 20:32:32adminsetmessages: + msg8402
2025-11-10 00:00:00admincreate