xref: /aosp_15_r20/external/libcxx/test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <complex>
11 
12 // template<class T>
13 //   complex<T>
14 //   asinh(const complex<T>& x);
15 
16 #include <complex>
17 #include <cassert>
18 
19 #include "../cases.h"
20 
21 template <class T>
22 void
test(const std::complex<T> & c,std::complex<T> x)23 test(const std::complex<T>& c, std::complex<T> x)
24 {
25     assert(asinh(c) == x);
26 }
27 
28 template <class T>
29 void
test()30 test()
31 {
32     test(std::complex<T>(0, 0), std::complex<T>(0, 0));
33 }
34 
test_edges()35 void test_edges()
36 {
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)
40     {
41         std::complex<double> r = asinh(testcases[i]);
42         if (testcases[i].real() == 0 && testcases[i].imag() == 0)
43         {
44             assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
45             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
46         }
47         else if (testcases[i].real() == 0 && std::abs(testcases[i].imag()) == 1)
48         {
49             assert(r.real() == 0);
50             assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
51             if (std::signbit(testcases[i].imag()))
52                 is_about(r.imag(), -pi/2);
53             else
54                 is_about(r.imag(),  pi/2);
55         }
56         else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
57         {
58             assert(std::isinf(r.real()));
59             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
60             if (std::signbit(testcases[i].imag()))
61                 is_about(r.imag(), -pi/2);
62             else
63                 is_about(r.imag(),  pi/2);
64         }
65         else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
66         {
67             assert(std::isnan(r.real()));
68             assert(std::isnan(r.imag()));
69         }
70         else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
71         {
72             assert(std::isinf(r.real()));
73             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
74             assert(r.imag() == 0);
75             assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
76         }
77         else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
78         {
79             assert(std::isinf(r.real()));
80             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
81             if (std::signbit(testcases[i].imag()))
82                 is_about(r.imag(), -pi/4);
83             else
84                 is_about(r.imag(),  pi/4);
85         }
86         else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
87         {
88             assert(std::isinf(r.real()));
89             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
90             assert(std::isnan(r.imag()));
91         }
92         else if (std::isnan(testcases[i].real()) && testcases[i].imag() == 0)
93         {
94             assert(std::isnan(r.real()));
95             assert(r.imag() == 0);
96             assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
97         }
98         else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
99         {
100             assert(std::isnan(r.real()));
101             assert(std::isnan(r.imag()));
102         }
103         else if (std::isnan(testcases[i].real()) && std::isinf(testcases[i].imag()))
104         {
105             assert(std::isinf(r.real()));
106             assert(std::isnan(r.imag()));
107         }
108         else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
109         {
110             assert(std::isnan(r.real()));
111             assert(std::isnan(r.imag()));
112         }
113         else
114         {
115             assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
116             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
117         }
118     }
119 }
120 
main()121 int main()
122 {
123     test<float>();
124     test<double>();
125     test<long double>();
126     test_edges();
127 }
128