Title
"`round_to_nearest`" rounding mode is unclear
Status
new
Section
[round.style]
Submitter
Jan Schultke

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

Messages

Date: 2025-11-15.18:01:01

Proposed resolution:

This wording is relative to N5014.

  1. Modify [round.style] as indicated:

    -1- The rounding mode for floating-point arithmetic is characterized by the values:

    • (1.1) — `round_indeterminate` if the rounding style is indeterminable
    • (1.2) — `round_toward_zero` if the rounding style is toward zero
    • (1.3) — `round_to_nearest` if the rounding style is to the nearest representable value; if there are two equally near such values, the one with an even least significant digit is chosen
    • (1.4) — `round_toward_infinity` if the rounding style is toward infinity
    • (1.5) — `round_toward_neg_infinity` if the rounding style is toward negative infinity
Date: 2025-11-13.00:00:00

Consider the specification of `round_to_nearest` in [round.style]:

`round_to_nearest` if the rounding style is to the nearest representable value

It is unclear how exact ties are rounded. For example, with this rounding, would a value that is equidistant to zero and numeric_limits<float>::min() be rounded towards zero or away from zero?

In [numeric.limits.members], there exists a footnote for numeric_limits<T>::round_style:

185) Equivalent to `FLT_ROUNDS`. Required by ISO/IEC 10967-1:2012.

In C23 5.2.4.2.2 [Characteristics of floating types <float.h>], it is specified that a value of `1` for `FLT_ROUNDS` (which equals `round_to_nearest`) means

to nearest, ties to even

This is also the default ISO/IEC 60559 rounding mode, and chosen by standard libraries such as libstdc++ for `numeric_limits` under that assumption. Do note that C23 no longer references ISO/IEC 10967 in any normative wording, so presumably, matching `FLT_ROUNDS` values means to match the value that exists in C23, including its meaning.

History
Date User Action Args
2025-11-15 18:01:01adminsetmessages: + msg15746
2025-11-13 00:00:00admincreate