[numeric.ops.midpoint]

# 26 Algorithms library [[algorithms]](./#algorithms)

## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#midpoint)

### 26.10.16 Midpoint [numeric.ops.midpoint]

[ð](#lib:midpoint)

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

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13339)

*Constraints*: T is an arithmetic type other than bool[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13343)

*Returns*: Half the sum of a and b[.](#2.sentence-1)

If T is an integer type and the sum is odd,
the result is rounded towards a[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13349)

*Remarks*: No overflow occurs[.](#3.sentence-1)

If T is a floating-point type, at most one inexact operation occurs[.](#3.sentence-2)

[ð](#lib:midpoint_)

`template<class T>
  constexpr T* midpoint(T* a, T* b);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13361)

*Constraints*: T is an object type[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13365)

*Mandates*: T is a complete type[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13369)

*Preconditions*: a and b point to, respectively,
elements i and j of the same array object x[.](#6.sentence-1)

[*Note [1](#note-1)*:

As specified in [[basic.compound]](basic.compound "6.9.4 Compound types"),
an object that is not an array element
is considered to belong to a single-element array for this purpose and
a pointer past the last element of an array of n elements
is considered to be equivalent to a pointer
to a hypothetical array element n for this purpose[.](#6.sentence-2)

â *end note*]

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13382)

*Returns*: A pointer to array element i+jâi2 of x,
where the result of the division is truncated towards zero[.](#7.sentence-1)
