Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.transcendentals / asin.pass.cpp
blob51da1c002a294cea467cc3e5497adae4e98dbe8e
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 // asin(const complex<T>& x);
15 #include <complex>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "../cases.h"
21 template <class T>
22 void
23 test(const std::complex<T>& c, std::complex<T> x)
25 assert(asin(c) == x);
28 template <class T>
29 void
30 test()
32 test(std::complex<T>(0, 0), std::complex<T>(0, 0));
35 void test_edges()
37 const double pi = std::atan2(+0., -0.);
38 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
39 for (unsigned i = 0; i < N; ++i)
41 std::complex<double> r = asin(testcases[i]);
42 if (testcases[i].real() == 0 && testcases[i].imag() == 0)
44 assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
45 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
47 else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
49 assert(r.real() == 0);
50 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
51 assert(std::isinf(r.imag()));
52 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
54 else if ( testcases[i].real() == 0 && std::isnan(testcases[i].imag()))
56 assert(r.real() == 0);
57 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
58 assert(std::isnan(r.imag()));
60 else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
62 assert(std::isnan(r.real()));
63 assert(std::isnan(r.imag()));
65 else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
67 if (testcases[i].real() > 0)
68 is_about(r.real(), pi/2);
69 else
70 is_about(r.real(), - pi/2);
71 assert(std::isinf(r.imag()));
72 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
74 else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
76 if (std::signbit(testcases[i].real()))
77 is_about(r.real(), -pi/4);
78 else
79 is_about(r.real(), pi/4);
80 assert(std::isinf(r.imag()));
81 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
83 else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
85 assert(std::isnan(r.real()));
86 assert(std::isinf(r.imag()));
87 assert(std::signbit(testcases[i].real()) != std::signbit(r.imag()));
89 else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
91 assert(std::isnan(r.real()));
92 assert(std::isnan(r.imag()));
94 else if (std::isnan(testcases[i].real()) && std::isinf(testcases[i].imag()))
96 assert(std::isnan(r.real()));
97 assert(std::isinf(r.imag()));
99 else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
101 assert(std::isnan(r.real()));
102 assert(std::isnan(r.imag()));
104 else
106 assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
107 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
112 int main(int, char**)
114 test<float>();
115 test<double>();
116 test<long double>();
117 test_edges();
119 return 0;