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(); } @@ -110,43 +111,37 @@ template struct has_abs : decltype(has_abs_imp(0)) {}; -void test_abs() { +void test_abs() +{ + // See also "abs.pass.cpp" + #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wabsolute-value" #endif - 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(!has_abs::value, ""); - static_assert(!has_abs::value, ""); - static_assert(!has_abs::value, ""); - static_assert(!has_abs::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(!has_abs::value, ""); + static_assert(!has_abs::value, ""); + static_assert(!has_abs::value, ""); + static_assert(!has_abs::value, ""); #ifdef __clang__ #pragma clang diagnostic pop #endif - assert(std::abs(-1.) == 1); + assert(std::abs(-1.) == 1); } @@ -1173,6 +1168,36 @@ assert(std::ilogb(1) == 0); } +void test_lerp() +{ + // See also "lerp.pass.cpp" + +#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), ""); @@ -1606,6 +1631,7 @@ test_fmin(); test_hypot(); test_ilogb(); + test_lerp(); test_lgamma(); test_llrint(); test_llround(); diff --git a/libcxx/test/std/numerics/c.math/c.math.lerp/c.math.lerp.pass.cpp b/libcxx/test/std/numerics/c.math/lerp.pass.cpp rename from libcxx/test/std/numerics/c.math/c.math.lerp/c.math.lerp.pass.cpp rename to libcxx/test/std/numerics/c.math/lerp.pass.cpp