Title
Floating-point `std::midpoint` should not be freestanding
Status
new
Section
[numeric.ops.midpoint]
Submitter
Jan Schultke

Created on 2026-09-11.00:00:00 last changed 2 days ago

Messages

Date: 2026-09-19.16:13:04

Proposed resolution:

This wording is relative to N5054 on top of LWG 4614.

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

    […]
    // [numeric.ops.midpoint], midpoint
    template<classintegral T>
      constexpr T midpoint(T a, T b) noexcept;
    template<floating_point T>
      constexpr T midpoint(T a, T b) noexcept; // freestanding-deleted
    template<class T>
      constexpr T* midpoint(T* a, T* b);
    […]
    
  2. Modify [numeric.ops.midpoint] as indicated:

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

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

    -2- Effects: If `T` is a floating-point type, equivalent to `return lerp(a, b, T(0.5));` ([c.math.lerp]). Otherwise, returns half
    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.

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

    -?- Effects: Equivalent to: `return lerp(a, b, T(0.5));` ([c.math.lerp])

    -?- Remarks: At most one inexact operation occurs.

Date: 2026-09-11.00:00:00

The standard library typically does not provide freestanding floating-point numerics, but floating-point `std::midpoint` is freestanding, presumably by accident. LWG 4614 makes this pre-existing issue readily apparent by making floating-point `std::midpoint` (freestanding) equivalent to `std::lerp(a, b, T(0.5))` (not freestanding).

History
Date User Action Args
2026-09-19 16:13:04adminsetmessages: + msg16616
2026-09-11 00:00:00admincreate