Title
§[numeric.ops.midpoint] No handling of non-finite floats
Status
new
Section
[numeric.ops.midpoint]
Submitter
Jan Schultke

Created on 2026-08-16.00:00:00 last changed 3 days ago

Messages

Date: 2026-08-22.11:50:44

Proposed resolution:

This wording is relative to N5054.

  1. Modify [numeric.ops.midpoint] as indicated:

    template<class T>
      constexpr T midpoint(T a, T b) noexcept;
    

    -1- Constraints: `T` is an arithmetic type other than cv `bool`.

    -2- ReturnsEffects: Half the sum of `a` and `b`. If `T` is an integer type and the sum is odd, the result is rounded towards `a`If `T` is a floating-point type, equivalent to `lerp(a, b, T(0.5))` ([c.math.lerp]). Otherwise, returns half the sum of `a` and `b`; if the sum is odd, the result is rounded towards `a`.

    -3- Remarks: No overflow occurs. If `T` is a floating-point type, at most one inexact operation occurs.

Date: 2026-08-16.00:00:00

While `std::midpoint` accepts operands of floating-point type, it is unclear what the midpoint is if any operand is an infinity, if both operands are differently signed infinities, if any operand is a NaN, etc. The specification merely says:

Returns: Half the sum of `a` and `b`. If `T` is an integer type and the sum is odd, the result is rounded towards `a`.

Not only is there no description of the result, there is also no description of error handling because the blanket wording in [library.c] does not apply to <numeric>, only to <cmath> functions.

History
Date User Action Args
2026-08-22 11:50:44adminsetmessages: + msg16559
2026-08-16 00:00:00admincreate