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 //===----------------------------------------------------------------------===//
8 
9 // XFAIL: LIBCXX-AIX-FIXME
10 
11 // <complex>
12 
13 // template<class T>
14 //   complex<T>
15 //   acosh(const complex<T>& x);
16 
17 #include <complex>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "../cases.h"
22 
23 template <class T>
24 void
25 test(const std::complex<T>& c, std::complex<T> x)
26 {
27     assert(acosh(c) == x);
28 }
29 
30 template <class T>
31 void
32 test()
33 {
34     test(std::complex<T>(INFINITY, 1), std::complex<T>(INFINITY, 0));
35 }
36 
37 void test_edges()
38 {
39     const double pi = std::atan2(+0., -0.);
40     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
41     for (unsigned i = 0; i < N; ++i)
42     {
43         std::complex<double> r = acosh(testcases[i]);
44         if (testcases[i].real() == 0 && testcases[i].imag() == 0)
45         {
46             assert(!std::signbit(r.real()));
47             if (std::signbit(testcases[i].imag()))
48                 is_about(r.imag(), -pi/2);
49             else
50                 is_about(r.imag(),  pi/2);
51         }
52         else if (testcases[i].real() == 1 && testcases[i].imag() == 0)
53         {
54             assert(r.real() == 0);
55             assert(!std::signbit(r.real()));
56             assert(r.imag() == 0);
57             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
58         }
59         else if (testcases[i].real() == -1 && testcases[i].imag() == 0)
60         {
61             assert(r.real() == 0);
62             assert(!std::signbit(r.real()));
63             if (std::signbit(testcases[i].imag()))
64                 is_about(r.imag(), -pi);
65             else
66                 is_about(r.imag(),  pi);
67         }
68         else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
69         {
70             assert(std::isinf(r.real()));
71             assert(r.real() > 0);
72             if (std::signbit(testcases[i].imag()))
73                 is_about(r.imag(), -pi/2);
74             else
75                 is_about(r.imag(),  pi/2);
76         }
77         else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
78         {
79             assert(std::isnan(r.real()));
80             assert(std::isnan(r.imag()));
81         }
82         else if (std::isinf(testcases[i].real()) && testcases[i].real() < 0 && std::isfinite(testcases[i].imag()))
83         {
84             assert(std::isinf(r.real()));
85             assert(r.real() > 0);
86             if (std::signbit(testcases[i].imag()))
87                 is_about(r.imag(), -pi);
88             else
89                 is_about(r.imag(),  pi);
90         }
91         else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && std::isfinite(testcases[i].imag()))
92         {
93             assert(std::isinf(r.real()));
94             assert(r.real() > 0);
95             assert(r.imag() == 0);
96             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
97         }
98         else if (std::isinf(testcases[i].real()) && testcases[i].real() < 0 && std::isinf(testcases[i].imag()))
99         {
100             assert(std::isinf(r.real()));
101             assert(r.real() > 0);
102             if (std::signbit(testcases[i].imag()))
103                 is_about(r.imag(), -0.75 * pi);
104             else
105                 is_about(r.imag(),  0.75 * pi);
106         }
107         else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && std::isinf(testcases[i].imag()))
108         {
109             assert(std::isinf(r.real()));
110             assert(r.real() > 0);
111             if (std::signbit(testcases[i].imag()))
112                 is_about(r.imag(), -0.25 * pi);
113             else
114                 is_about(r.imag(),  0.25 * pi);
115         }
116         else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
117         {
118             assert(std::isinf(r.real()));
119             assert(r.real() > 0);
120             assert(std::isnan(r.imag()));
121         }
122         else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
123         {
124             assert(std::isnan(r.real()));
125             assert(std::isnan(r.imag()));
126         }
127         else if (std::isnan(testcases[i].real()) && std::isinf(testcases[i].imag()))
128         {
129             assert(std::isinf(r.real()));
130             assert(r.real() > 0);
131             assert(std::isnan(r.imag()));
132         }
133         else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
134         {
135             assert(std::isnan(r.real()));
136             assert(std::isnan(r.imag()));
137         }
138         else
139         {
140             assert(!std::signbit(r.real()));
141             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
142         }
143     }
144 }
145 
146 int main(int, char**)
147 {
148     test<float>();
149     test<double>();
150     test<long double>();
151     test_edges();
152 
153   return 0;
154 }
155