1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // constexpr float lerp(float a, float b, float t) noexcept;
12 // constexpr double lerp(double a, double b, double t) noexcept;
13 // constexpr long double lerp(long double a, long double b, long double t) noexcept;
17 #include <type_traits>
20 #include "test_macros.h"
21 #include "fp_compare.h"
24 constexpr bool constexpr_test()
26 return std::lerp(T( 0), T(12), T(0)) == T(0)
27 && std::lerp(T(12), T( 0), T(0.5)) == T(6)
28 && std::lerp(T( 0), T(12), T(2)) == T(24);
35 ASSERT_SAME_TYPE(T
, decltype(std::lerp(T(), T(), T())));
36 LIBCPP_ASSERT_NOEXCEPT( std::lerp(T(), T(), T()));
38 // constexpr T minV = std::numeric_limits<T>::min();
39 constexpr T maxV
= std::numeric_limits
<T
>::max();
40 constexpr T inf
= std::numeric_limits
<T
>::infinity();
42 // Things that can be compared exactly
43 assert((std::lerp(T( 0), T(12), T(0)) == T(0)));
44 assert((std::lerp(T( 0), T(12), T(1)) == T(12)));
45 assert((std::lerp(T(12), T( 0), T(0)) == T(12)));
46 assert((std::lerp(T(12), T( 0), T(1)) == T(0)));
48 assert((std::lerp(T( 0), T(12), T(0.5)) == T(6)));
49 assert((std::lerp(T(12), T( 0), T(0.5)) == T(6)));
50 assert((std::lerp(T( 0), T(12), T(2)) == T(24)));
51 assert((std::lerp(T(12), T( 0), T(2)) == T(-12)));
53 assert((std::lerp(maxV
, maxV
/10, T(0)) == maxV
));
54 assert((std::lerp(maxV
/10, maxV
, T(1)) == maxV
));
56 assert((std::lerp(T(2.3), T(2.3), inf
) == T(2.3)));
58 assert(std::lerp(T( 0), T( 0), T(23)) == T(0));
59 assert(std::isnan(std::lerp(T( 0), T( 0), inf
)));
65 static_assert(constexpr_test
<float>(), "");
66 static_assert(constexpr_test
<double>(), "");
67 static_assert(constexpr_test
<long double>(), "");