Title
Narrowing floating-point conversions
Status
drwp
Section
9.4.5 [dcl.init.list]
Submitter
Brian Bi

Created on 2023-11-04.00:00:00 last changed 4 days ago

Messages

Date: 2024-04-15.00:00:00

Additional notes (April, 2024)

According to the proposed wording, since NaNs are not finite, conversion of NaNs is always non-narrowing. However, the payload of the NaN might not be preserved when converting to a smaller floating-point type.

Date: 2024-04-19.21:17:21

Proposed resolution (approved by CWG 2024-04-19):

Change in 9.4.5 [dcl.init.list] paragraph 7 as follows:

A narrowing conversion is an implicit conversion
  • from a floating-point type to an integer type, or
  • from a floating-point type T to another floating-point type whose floating-point conversion rank is neither greater than nor equal to that of T, except where the source result of the conversion is a constant expression and the actual either its value after conversion is finite and within the range of values that can be represented (even if it cannot be represented exactly) the conversion did not overflow, or the values before and after the conversion are not finite, or
  • from an integer type ...
Date: 2024-06-15.00:00:00

[Accepted as a DR at the June, 2024 meeting.]

Consider:

  float f = {1e100};

This is rejected as narrowing on all implementations. Issue 2723 made the example non-narrowing, which seems incorrect on an IEEE platform.

History
Date User Action Args
2024-12-17 09:54:02adminsetstatus: dr -> drwp
2024-07-20 13:52:34adminsetstatus: ready -> dr
2024-06-27 04:25:11adminsetstatus: tentatively ready -> ready
2024-04-30 19:05:37adminsetmessages: + msg7684
2024-04-19 21:17:21adminsetstatus: review -> tentatively ready
2024-04-05 21:08:10adminsetstatus: open -> review
2024-02-26 20:59:47adminsetmessages: + msg7618
2023-11-04 00:00:00admincreate