< cpp‎ | numeric
Defined in header <numeric>
template< class T >
constexpr T midpoint(T a, T b) noexcept;
(1) (since C++20)
template< class T >
constexpr T* midpoint(T* a, T* b);
(2) (since C++20)

Computes the midpoint of the integers, floating-points, or pointers a and b.


a, b - intergers, floating-points, or pointer values
Type requirements
T must be an arithmetic type other than bool for overload (1)
T must be a complete object type for overload (2)

Return value

1) Half the sum of a and b. No overflow occurs. If a and b have integer type and the sum is odd, the result is rounded towards a. If a and b have floating-point type, at most one inexact operation occurs.
2) If a and b point to, respectively, x[i] and x[j] of the same array object x (for the purpose of pointer arithmetic), returns a pointer to x[i+(j-i)/2] where the division rounds towards zero. If a and b do not point to elements of the same array object, the behavior is undefined.


Throws no exceptions.