Define midpoint and lerp functions for C++20 (P0811R3)
authorJonathan Wakely <jwakely@redhat.com>
Tue, 5 Mar 2019 18:37:24 +0000 (18:37 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 5 Mar 2019 18:37:24 +0000 (18:37 +0000)
commit243874426dddf0cd56031eea8bbb7b3986f37baa
tree37e454c2ac25aa892570e55690083e4436b43bcb
parentf0c3b1337fbd9216c3c7c6c28066df8abf45cccb
Define midpoint and lerp functions for C++20 (P0811R3)

The implementation of midpoint used for integral types is due to Howard
Hinnant and avoids a branch for int and larger types (but not for chars
and shorts).

The midpoint and lerp functions for floating point types come straight
from the P0811R3 proposal, with no attempt at optimization.

* include/c_compatibility/math.h [C++20] (lerp): Add using
declaration.
* include/c_global/cmath [C++20] (__cpp_lib_interpolate): Define.
(__lerp): Define function template to implement lerp.
(lerp(float, float, float), lerp(double, double, double))
(lerp(long double, long double, long double)): Define for C++20.
* include/std/numeric [C++20] (__cpp_lib_interpolate): Define.
(midpoint(T, T), midpoint(T*, T*)): Define.
* include/std::version [C++20] (__cpp_lib_interpolate): Define.
* testsuite/26_numerics/lerp.cc: New test.
* testsuite/26_numerics/midpoint/floating.cc: New test.
* testsuite/26_numerics/midpoint/integral.cc: New test.
* testsuite/26_numerics/midpoint/pointer.cc: New test.

From-SVN: r269398
libstdc++-v3/ChangeLog
libstdc++-v3/include/c_compatibility/math.h
libstdc++-v3/include/c_global/cmath
libstdc++-v3/include/std/numeric
libstdc++-v3/include/std/version
libstdc++-v3/testsuite/26_numerics/lerp.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/midpoint/floating.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/midpoint/integral.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc [new file with mode: 0644]