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

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

Messages

Date: 2026-09-11.16:39:09

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 `return 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-09-15.00:00:00

[ 2026-09-11; LWG telecon. Status changed: New → Ready. ]

Date: 2026-08-15.00:00:00

[ 2026-08-27; Reflector poll. ]

Set priority to P3 after reflector poll.

"`lerp` handles such corner cases, just call `lerp` to get it right."

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-09-11 16:39:09adminsetmessages: + msg16610
2026-09-11 16:39:09adminsetstatus: new -> ready
2026-09-10 14:03:08adminsetmessages: + msg16578
2026-08-22 11:50:44adminsetmessages: + msg16559
2026-08-16 00:00:00admincreate