Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / c.math / lerp.pass.cpp
blob6b0b5aba8b84e7c78c45b7f2e0b47d904cec1eb3
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // <cmath>
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;
15 #include <cmath>
16 #include <limits>
17 #include <type_traits>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "fp_compare.h"
23 template <typename T>
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);
32 template <typename T>
33 void test()
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)));
63 int main(int, char**)
65 static_assert(constexpr_test<float>(), "");
66 static_assert(constexpr_test<double>(), "");
67 static_assert(constexpr_test<long double>(), "");
69 test<float>();
70 test<double>();
71 test<long double>();
73 return 0;