Index: include/cmath =================================================================== --- include/cmath +++ include/cmath @@ -296,6 +296,10 @@ float truncf(float x); long double truncl(long double x); +constexpr float lerp(float a, float b, float t); +constexpr double lerp(double a, double b, double t); +constexpr long double lerp(long double a, long double b, long double t); + } // std */ @@ -606,6 +610,31 @@ return isfinite(__lcpp_x); } +#if _LIBCPP_STD_VER > 17 + +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR float +lerp(float __a, float __b, float __t) +{ + return (1 - __t) * __a + __t * __b; +} + +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR double +lerp(double __a, double __b, double __t) +{ + return (1 - __t) * __a + __t * __b; +} + +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR long double +lerp(long double __a, long double __b, long double __t) +{ + return (1 - __t) * __a + __t * __b; +} + +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CMATH Index: test/std/numerics/c.math/lerp.pass.cpp =================================================================== --- /dev/null +++ test/std/numerics/c.math/lerp.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// cmath + +// constexpr float lerp(float a, float b, float t); +// constexpr double lerp(double a, double b, double t); +// constexpr long double lerp(long double a, long double b, long double t); + +#include "test_macros.h" + +#include + +void test_double() +{ + constexpr double a = 4; + constexpr double b = 0; + constexpr double t = 0.25; + constexpr double r = 3; + + constexpr auto res = std::lerp(a, b, t); + static_assert(res == r); + ASSERT_SAME_TYPE(decltype(t), decltype(res)); +} + +void test_long_double() +{ + constexpr long double a = 4; + constexpr long double b = 0; + constexpr long double t = 0.25; + constexpr long double r = 3; + + constexpr auto res = std::lerp(a, b, t); + static_assert(res == r); + ASSERT_SAME_TYPE(decltype(t), decltype(res)); +} + +void test_float() +{ + constexpr float a = 4; + constexpr float b = 0; + constexpr float t = 0.25; + constexpr float r = 3; + + constexpr auto res = std::lerp(a, b, t); + static_assert(res == r); + ASSERT_SAME_TYPE(decltype(t), decltype(res)); +} + +int main(int, char**) +{ + test_double(); + test_long_double(); + test_float(); + + return 0; +} \ No newline at end of file Index: www/cxx2a_status.html =================================================================== --- www/cxx2a_status.html +++ www/cxx2a_status.html @@ -141,7 +141,7 @@ P0339R6LWGpolymorphic_allocator<> as a vocabulary typeKona P0340R3LWGMaking std::underlying_type SFINAE-friendlyKona P0738R2LWGI Stream, You Stream, We All Stream for istream_iteratorKona - P0811R3LWGWell-behaved interpolation for numbers and pointersKona + P0811R3LWGWell-behaved interpolation for numbers and pointersKonaComplete P0920R2LWGPrecalculated hash values in lookupKona P1001R2LWGTarget Vectorization Policies from Parallelism V2 TS to C++20Kona P1024R3LWGUsability Enhancements for std::spanKonaComplete9.0