Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.transcendentals / atanh.pass.cpp
bloba126032bf8c240b2f4febf4a1bf1e1d9b28523f7
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 // atanh(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(atanh(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 = atanh(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 ( testcases[i].real() == 0 && std::isnan(testcases[i].imag()))
49 assert(r.real() == 0);
50 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
51 assert(std::isnan(r.imag()));
53 else if (std::abs(testcases[i].real()) == 1 && testcases[i].imag() == 0)
55 assert(std::isinf(r.real()));
56 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
57 assert(r.imag() == 0);
58 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
60 else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
62 assert(r.real() == 0);
63 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
64 if (testcases[i].imag() > 0)
65 is_about(r.imag(), pi/2);
66 else
67 is_about(r.imag(), -pi/2);
69 else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
71 assert(std::isnan(r.real()));
72 assert(std::isnan(r.imag()));
74 else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
76 assert(r.real() == 0);
77 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
78 if (std::signbit(testcases[i].imag()))
79 is_about(r.imag(), -pi/2);
80 else
81 is_about(r.imag(), pi/2);
83 else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
85 assert(r.real() == 0);
86 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
87 if (std::signbit(testcases[i].imag()))
88 is_about(r.imag(), -pi/2);
89 else
90 is_about(r.imag(), pi/2);
92 else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
94 assert(r.real() == 0);
95 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
96 assert(std::isnan(r.imag()));
98 else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
100 assert(std::isnan(r.real()));
101 assert(std::isnan(r.imag()));
103 else if (std::isnan(testcases[i].real()) && std::isinf(testcases[i].imag()))
105 assert(r.real() == 0);
106 assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
107 if (std::signbit(testcases[i].imag()))
108 is_about(r.imag(), -pi/2);
109 else
110 is_about(r.imag(), pi/2);
112 else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
114 assert(std::isnan(r.real()));
115 assert(std::isnan(r.imag()));
117 else
119 assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
120 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
125 int main(int, char**)
127 test<float>();
128 test<double>();
129 test<long double>();
130 test_edges();
132 return 0;