std::midpoint

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.

Parameters

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.

Exceptions

Throws no exceptions.

Examples

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/numeric/midpoint