Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.value.ops / polar.pass.cpp
blob2b9c764abb591b48b693852c32b98044f754ba20
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<class T>
12 // complex<T>
13 // polar(const T& rho, const T& theta = T()); // changed from '0' by LWG#2870
15 #include <complex>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "../cases.h"
21 template <class T>
22 void
23 test(const T& rho, std::complex<T> x)
25 assert(std::polar(rho) == x);
28 template <class T>
29 void
30 test(const T& rho, const T& theta, std::complex<T> x)
32 assert(std::polar(rho, theta) == x);
35 template <class T>
36 void
37 test()
39 test(T(0), std::complex<T>(0, 0));
40 test(T(1), std::complex<T>(1, 0));
41 test(T(100), std::complex<T>(100, 0));
42 test(T(0), T(0), std::complex<T>(0, 0));
43 test(T(1), T(0), std::complex<T>(1, 0));
44 test(T(100), T(0), std::complex<T>(100, 0));
47 void test_edges()
49 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
50 for (unsigned i = 0; i < N; ++i)
52 double r = real(testcases[i]);
53 double theta = imag(testcases[i]);
54 std::complex<double> z = std::polar(r, theta);
55 switch (classify(r))
57 case zero:
58 if (std::signbit(r) || classify(theta) == inf || classify(theta) == NaN)
60 int c = classify(z);
61 assert(c == NaN || c == non_zero_nan);
63 else
65 assert(z == std::complex<double>());
67 break;
68 case non_zero:
69 if (std::signbit(r) || classify(theta) == inf || classify(theta) == NaN)
71 int c = classify(z);
72 assert(c == NaN || c == non_zero_nan);
74 else
76 is_about(std::abs(z), r);
78 break;
79 case inf:
80 if (r < 0)
82 int c = classify(z);
83 assert(c == NaN || c == non_zero_nan);
85 else
87 assert(classify(z) == inf);
88 if (classify(theta) != NaN && classify(theta) != inf)
90 assert(classify(real(z)) != NaN);
91 assert(classify(imag(z)) != NaN);
94 break;
95 case NaN:
96 case non_zero_nan:
98 int c = classify(z);
99 assert(c == NaN || c == non_zero_nan);
101 break;
106 int main(int, char**)
108 test<float>();
109 test<double>();
110 test<long double>();
111 test_edges();
113 return 0;