Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / complex.number / cmplx.over / norm.pass.cpp
blobc56123a78e27fe9ce71f83c5d318779e2bbc4472
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 //===----------------------------------------------------------------------===//
9 // <complex>
11 // template<Arithmetic T>
12 // T
13 // norm(T x); // constexpr in C++20
15 #include <complex>
16 #include <type_traits>
17 #include <cassert>
19 #include "test_macros.h"
20 #include "../cases.h"
22 template <class T>
23 TEST_CONSTEXPR_CXX20
24 void
25 test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
27 static_assert((std::is_same<decltype(std::norm(x)), double>::value), "");
28 assert(std::norm(x) == norm(std::complex<double>(static_cast<double>(x), 0)));
31 template <class T>
32 TEST_CONSTEXPR_CXX20
33 void
34 test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
36 static_assert((std::is_same<decltype(std::norm(x)), T>::value), "");
37 assert(std::norm(x) == norm(std::complex<T>(x, 0)));
40 template <class T>
41 TEST_CONSTEXPR_CXX20
42 bool
43 test()
45 test<T>(0);
46 test<T>(1);
47 test<T>(10);
48 return true;
51 int main(int, char**)
53 test<float>();
54 test<double>();
55 test<long double>();
56 test<int>();
57 test<unsigned>();
58 test<long long>();
60 #if TEST_STD_VER >= 20
61 static_assert(test<float>());
62 static_assert(test<double>());
63 static_assert(test<long double>());
64 static_assert(test<int>());
65 static_assert(test<unsigned>());
66 static_assert(test<long long>());
67 #endif
69 return 0;