SysTutorials

Linux Manual Pages › Section 3

stdmidpoint(3)

std::midpoint – std::midpoint

Synopsis

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

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

 This section is incomplete
 Reason: no example