summaryrefslogtreecommitdiffstats
path: root/libcxx/include
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include')
-rw-r--r--libcxx/include/cmath27
1 files changed, 27 insertions, 0 deletions
diff --git a/libcxx/include/cmath b/libcxx/include/cmath
index 3af9f548190..f618b1bf467 100644
--- a/libcxx/include/cmath
+++ b/libcxx/include/cmath
@@ -302,6 +302,7 @@ long double truncl(long double x);
#include <__config>
#include <math.h>
+#include <algorithm>
#include <version>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -606,6 +607,32 @@ __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
return isfinite(__lcpp_x);
}
+#if _LIBCPP_STD_VER > 17
+template <typename _Fp>
+constexpr
+_Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
+ if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
+ return __t * __b + (1 - __t) * __a;
+
+ if (__t == 1) return __b;
+ const _Fp __x = __a + __t * (__b - __a);
+ if (__t > 1 == __b > __a)
+ return __b < __x ? __x : __b;
+ else
+ return __x < __b ? __x : __b;
+}
+
+constexpr float
+lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
+
+constexpr double
+lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
+
+constexpr long double
+lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
+
+#endif // _LIBCPP_STD_VER > 17
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CMATH
OpenPOWER on IntegriCloud