diff --git a/libcxx/include/cmath b/libcxx/include/cmath --- a/libcxx/include/cmath +++ b/libcxx/include/cmath @@ -636,6 +636,23 @@ constexpr long double lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } +template +inline _LIBCPP_HIDE_FROM_ABI +constexpr typename enable_if_t +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value && + is_arithmetic<_A3>::value, + __promote<_A1, _A2, _A3> +>::type +lerp(_A1 __a, _A2 __b, _A3 __t) noexcept +{ + typedef typename __promote<_A1, _A2, _A3>::type __result_type; + static_assert(!(_IsSame<_A1, __result_type>::value && + _IsSame<_A2, __result_type>::value && + _IsSame<_A3, __result_type>::value)); + return __lerp((__result_type)__a, (__result_type)__b, (__result_type)__t); +} #endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/test/std/numerics/c.math/cmath.pass.cpp b/libcxx/test/std/numerics/c.math/cmath.pass.cpp --- a/libcxx/test/std/numerics/c.math/cmath.pass.cpp +++ b/libcxx/test/std/numerics/c.math/cmath.pass.cpp @@ -82,6 +82,7 @@ Ambiguous hypot(Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous hypot(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous ilogb(Ambiguous){ return Ambiguous(); } +Ambiguous lerp(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous lgamma(Ambiguous){ return Ambiguous(); } Ambiguous llrint(Ambiguous){ return Ambiguous(); } Ambiguous llround(Ambiguous){ return Ambiguous(); } @@ -1137,7 +1138,6 @@ static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); - static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); @@ -1174,6 +1174,34 @@ assert(std::ilogb(1) == 0); } +void test_lerp() +{ +#if TEST_STD_VER > 17 + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + + assert(std::lerp(2, 3, 1) == 3); + assert(std::lerp(1, 3, 0.5) == 2); + assert(std::lerp(0, 4.0, 0) == 0); + static_assert(std::lerp(2, 3, 1) == 3); + static_assert(std::lerp(1, 3, 0.5) == 2); + static_assert(std::lerp(0, 4.0, 0) == 0); +#endif +} + void test_lgamma() { static_assert((std::is_same::value), ""); @@ -1607,6 +1635,7 @@ test_fmin(); test_hypot(); test_ilogb(); + test_lerp(); test_lgamma(); test_llrint(); test_llround();