1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // acosh(const complex<T>& x);
18 #include "test_macros.h"
23 test(const std::complex<T
>& c
, std::complex<T
> x
)
25 assert(acosh(c
) == x
);
32 test(std::complex<T
>(INFINITY
, 1), std::complex<T
>(INFINITY
, 0));
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
= acosh(testcases
[i
]);
42 if (testcases
[i
].real() == 0 && testcases
[i
].imag() == 0)
44 assert(!std::signbit(r
.real()));
45 if (std::signbit(testcases
[i
].imag()))
46 is_about(r
.imag(), -pi
/2);
48 is_about(r
.imag(), pi
/2);
50 else if (testcases
[i
].real() == 1 && testcases
[i
].imag() == 0)
52 assert(r
.real() == 0);
53 assert(!std::signbit(r
.real()));
54 assert(r
.imag() == 0);
55 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
57 else if (testcases
[i
].real() == -1 && testcases
[i
].imag() == 0)
59 assert(r
.real() == 0);
60 assert(!std::signbit(r
.real()));
61 if (std::signbit(testcases
[i
].imag()))
62 is_about(r
.imag(), -pi
);
64 is_about(r
.imag(), pi
);
66 else if (std::isfinite(testcases
[i
].real()) && std::isinf(testcases
[i
].imag()))
68 assert(std::isinf(r
.real()));
70 if (std::signbit(testcases
[i
].imag()))
71 is_about(r
.imag(), -pi
/2);
73 is_about(r
.imag(), pi
/2);
75 else if (std::isfinite(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
77 assert(std::isnan(r
.real()));
78 assert(std::isnan(r
.imag()));
80 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isfinite(testcases
[i
].imag()))
82 assert(std::isinf(r
.real()));
84 if (std::signbit(testcases
[i
].imag()))
85 is_about(r
.imag(), -pi
);
87 is_about(r
.imag(), pi
);
89 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isfinite(testcases
[i
].imag()))
91 assert(std::isinf(r
.real()));
93 assert(r
.imag() == 0);
94 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
96 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isinf(testcases
[i
].imag()))
98 assert(std::isinf(r
.real()));
100 if (std::signbit(testcases
[i
].imag()))
101 is_about(r
.imag(), -0.75 * pi
);
103 is_about(r
.imag(), 0.75 * pi
);
105 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isinf(testcases
[i
].imag()))
107 assert(std::isinf(r
.real()));
108 assert(r
.real() > 0);
109 if (std::signbit(testcases
[i
].imag()))
110 is_about(r
.imag(), -0.25 * pi
);
112 is_about(r
.imag(), 0.25 * pi
);
114 else if (std::isinf(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
116 assert(std::isinf(r
.real()));
117 assert(r
.real() > 0);
118 assert(std::isnan(r
.imag()));
120 else if (std::isnan(testcases
[i
].real()) && std::isfinite(testcases
[i
].imag()))
122 assert(std::isnan(r
.real()));
123 assert(std::isnan(r
.imag()));
125 else if (std::isnan(testcases
[i
].real()) && std::isinf(testcases
[i
].imag()))
127 assert(std::isinf(r
.real()));
128 assert(r
.real() > 0);
129 assert(std::isnan(r
.imag()));
131 else if (std::isnan(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
133 assert(std::isnan(r
.real()));
134 assert(std::isnan(r
.imag()));
138 assert(!std::signbit(r
.real()));
139 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
144 int main(int, char**)