[clang-format] Write in text mode with LF in dump_format_[help|style].py
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.transcendentals / acosh.pass.cpp
blob424a3b1b82e1a036a2ad0052f88e5d4493eb3bce
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 // acosh(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(acosh(c) == x);
28 template <class T>
29 void
30 test()
32 test(std::complex<T>(INFINITY, 1), std::complex<T>(INFINITY, 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 = 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);
47 else
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);
63 else
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()));
69 assert(r.real() > 0);
70 if (std::signbit(testcases[i].imag()))
71 is_about(r.imag(), -pi/2);
72 else
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()));
83 assert(r.real() > 0);
84 if (std::signbit(testcases[i].imag()))
85 is_about(r.imag(), -pi);
86 else
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()));
92 assert(r.real() > 0);
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()));
99 assert(r.real() > 0);
100 if (std::signbit(testcases[i].imag()))
101 is_about(r.imag(), -0.75 * pi);
102 else
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);
111 else
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()));
136 else
138 assert(!std::signbit(r.real()));
139 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
144 int main(int, char**)
146 test<float>();
147 test<double>();
148 test<long double>();
149 test_edges();
151 return 0;