This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
Section: 26.10.16 [numeric.ops.midpoint] Status: New Submitter: Jan Schultke Opened: 2026-08-16 Last modified: 2026-08-22
Priority: Not Prioritized
View all other issues in [numeric.ops.midpoint].
View all issues with New status.
Discussion:
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
aandb. IfTis an integer type and the sum is odd, the result is rounded towardsa.
Not only is there no description of the result, there is also no description of error handling
because the blanket wording in 16.2 [library.c] does not apply to <numeric>,
only to <cmath> functions.
Proposed resolution:
This wording is relative to N5054.
Modify 26.10.16 [numeric.ops.midpoint] as indicated:
template<class T> constexpr T midpoint(T a, T b) noexcept;-1- Constraints:
-2-Tis an arithmetic type other than cvbool.ReturnsEffects:Half the sum ofIfaandb. IfTis an integer type and the sum is odd, the result is rounded towardsaTis a floating-point type, equivalent tolerp(a, b, T(0.5))(29.7.4 [c.math.lerp]). Otherwise, returns half the sum ofaandb; if the sum is odd, the result is rounded towardsa. -3- Remarks: No overflow occurs. IfTis a floating-point type, at most one inexact operation occurs.