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 // acos(const complex<T>& x);
18 #include "test_macros.h"
23 test(const std::complex<T
>& c
, std::complex<T
> x
)
32 test(std::complex<T
>(INFINITY
, 1), std::complex<T
>(0, -INFINITY
));
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
= acos(testcases
[i
]);
42 if (testcases
[i
].real() == 0 && testcases
[i
].imag() == 0)
44 is_about(r
.real(), pi
/2);
45 assert(r
.imag() == 0);
46 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
48 else if (testcases
[i
].real() == 0 && std::isnan(testcases
[i
].imag()))
50 is_about(r
.real(), pi
/2);
51 assert(std::isnan(r
.imag()));
53 else if (std::isfinite(testcases
[i
].real()) && std::isinf(testcases
[i
].imag()))
55 is_about(r
.real(), pi
/2);
56 assert(std::isinf(r
.imag()));
57 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
59 else if (std::isfinite(testcases
[i
].real()) && testcases
[i
].real() != 0 && std::isnan(testcases
[i
].imag()))
61 assert(std::isnan(r
.real()));
62 assert(std::isnan(r
.imag()));
64 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isfinite(testcases
[i
].imag()))
66 is_about(r
.real(), pi
);
67 assert(std::isinf(r
.imag()));
68 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
70 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isfinite(testcases
[i
].imag()))
72 assert(r
.real() == 0);
73 assert(!std::signbit(r
.real()));
74 assert(std::isinf(r
.imag()));
75 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
77 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isinf(testcases
[i
].imag()))
79 is_about(r
.real(), 0.75 * pi
);
80 assert(std::isinf(r
.imag()));
81 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
83 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isinf(testcases
[i
].imag()))
85 is_about(r
.real(), 0.25 * pi
);
86 assert(std::isinf(r
.imag()));
87 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
89 else if (std::isinf(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
91 assert(std::isnan(r
.real()));
92 assert(std::isinf(r
.imag()));
94 else if (std::isnan(testcases
[i
].real()) && std::isfinite(testcases
[i
].imag()))
96 assert(std::isnan(r
.real()));
97 assert(std::isnan(r
.imag()));
99 else if (std::isnan(testcases
[i
].real()) && std::isinf(testcases
[i
].imag()))
101 assert(std::isnan(r
.real()));
102 assert(std::isinf(r
.imag()));
103 assert(std::signbit(testcases
[i
].imag()) != std::signbit(r
.imag()));
105 else if (std::isnan(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
107 assert(std::isnan(r
.real()));
108 assert(std::isnan(r
.imag()));
110 else if (!std::signbit(testcases
[i
].real()) && !std::signbit(testcases
[i
].imag()))
112 assert(!std::signbit(r
.real()));
113 assert( std::signbit(r
.imag()));
115 else if (std::signbit(testcases
[i
].real()) && !std::signbit(testcases
[i
].imag()))
117 assert(!std::signbit(r
.real()));
118 assert( std::signbit(r
.imag()));
120 else if (std::signbit(testcases
[i
].real()) && std::signbit(testcases
[i
].imag()))
122 assert(!std::signbit(r
.real()));
123 assert(!std::signbit(r
.imag()));
125 else if (!std::signbit(testcases
[i
].real()) && std::signbit(testcases
[i
].imag()))
127 assert(!std::signbit(r
.real()));
128 assert(!std::signbit(r
.imag()));
133 int main(int, char**)