Title
Missing "round to nearest, ties away from zero" mode
Status
new
Section
[round.style]
Submitter
Jan Schultke

Created on 2026-03-30.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-04-04.13:37:50

Proposed resolution:

This wording is relative to N5032 after application of LWG motion 1 (See LWG Motion 1-#4474).

  1. Modify [round.style] as indicated:

    namespace std {
      enum float_round_style {
        round_indeterminate = -1,
        round_toward_zero = 0,
        round_to_nearest = 1,
        round_toward_infinity = 2,
        round_toward_neg_infinity = 3,
        round_to_nearest_from_zero = 4
      };
    }
    

    -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

    • (1.?) — `round_to_nearest_from_zero` if the rounding style is to the nearest representable value; if there are two equally near such values, the one with greater magnitude is chosen

Date: 2026-03-30.00:00:00

As discussed in LWG 4474 (approved for C++26), `std::round_style` is intended to be symmetrical with `FLT_ROUNDS`. LWG 4474 clarified that `round_to_nearest` corresponds to an `FLT_ROUNDS` value of 1, meaning "to nearest, ties to even".

Unfortunately, any implementation using the mode "to nearest, ties away from zero" (corresponding to an `FLT_ROUNDS` value of 4 and supported by ISO/IEC 60559 floating-point implementations) is forced to stop using `round_to_nearest` as a numeric_limits<float>::round_style constant due to stricter requirements for that enumerator. To prevent such implementations from resorting to a non-standard enumerator, a new enumerator is needed.

The name should be inspired by C23 macros such as `FE_TONEARESTFROMZERO`.

See also ISO/IEC 9899:2024 §5.2.5.3 paragraph 23

History
Date User Action Args
2026-04-04 13:37:50adminsetmessages: + msg16250
2026-03-30 00:00:00admincreate