aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/c_global
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-08-12 17:35:25 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-08-12 19:46:16 +0100
commit9017326e19fe278d5f62898cca4682b17f8e8e07 (patch)
tree4d52aa17bdb30c2ffe9889dd75668bd0287d1752 /libstdc++-v3/include/c_global
parentb1c0e8599aa6ff5550dc748679e13c1eb492ee2c (diff)
downloadgcc-9017326e19fe278d5f62898cca4682b17f8e8e07.zip
gcc-9017326e19fe278d5f62898cca4682b17f8e8e07.tar.gz
gcc-9017326e19fe278d5f62898cca4682b17f8e8e07.tar.bz2
libstdc++: Add additional overload of std::lerp [PR101870]
The [cmath.syn] p1 wording about additional overloads sufficient to handle any arithmetic types also applies to std::lerp. This adds a new overload of std::lerp that does the required promotions to support arguments of arbitrary arithmetic types. A new __promoted_t alias template is added, which the C++17 function templates std::hypot and std::lerp can use to avoid instantiating the __promote_3 class template. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/101870 * include/c_global/cmath (hypot): Use __promoted_t. (lerp): Add new overload accepting any arithmetic types. * include/ext/type_traits.h (__promoted_t): New alias template. * testsuite/26_numerics/lerp.cc: Moved to... * testsuite/26_numerics/lerp/1.cc: ...here. * testsuite/26_numerics/lerp/constexpr.cc: New test. * testsuite/26_numerics/lerp/version.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/c_global')
-rw-r--r--libstdc++-v3/include/c_global/cmath16
1 files changed, 12 insertions, 4 deletions
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index 39a6b03..3233228 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -1844,7 +1844,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif // _GLIBCXX_USE_C99_MATH_TR1
#endif // C++11
-#if __cplusplus > 201402L
+#if __cplusplus >= 201703L
// [c.math.hypot3], three-dimensional hypotenuse
#define __cpp_lib_hypot 201603
@@ -1877,15 +1877,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return std::__hypot3<long double>(__x, __y, __z); }
template<typename _Tp, typename _Up, typename _Vp>
- typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
+ __gnu_cxx::__promoted_t<_Tp, _Up, _Vp>
hypot(_Tp __x, _Up __y, _Vp __z)
{
- using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type;
+ using __type = __gnu_cxx::__promoted_t<_Tp, _Up, _Vp>;
return std::__hypot3<__type>(__x, __y, __z);
}
#endif // C++17
-#if __cplusplus > 201703L
+#if __cplusplus >= 202002L
// linear interpolation
# define __cpp_lib_interpolate 201902L
@@ -1918,6 +1918,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr long double
lerp(long double __a, long double __b, long double __t) noexcept
{ return std::__lerp(__a, __b, __t); }
+
+ template<typename _Tp, typename _Up, typename _Vp>
+ constexpr __gnu_cxx::__promoted_t<_Tp, _Up, _Vp>
+ lerp(_Tp __x, _Up __y, _Vp __z) noexcept
+ {
+ using __type = __gnu_cxx::__promoted_t<_Tp, _Up, _Vp>;
+ return std::__lerp<__type>(__x, __y, __z);
+ }
#endif // C++20
_GLIBCXX_END_NAMESPACE_VERSION