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 //   atan(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(atan(c) == x);
28 }
29 
30 template <class T>
31 void
32 test()
33 {
34     test(std::complex<T>(0, 0), std::complex<T>(0, 0));
35 }
36 
37 void test_edges()
38 {
39     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
40     for (unsigned i = 0; i < N; ++i)
41     {
42         std::complex<double> r = atan(testcases[i]);
43         std::complex<double> t1(-imag(testcases[i]), real(testcases[i]));
44         std::complex<double> t2 = atanh(t1);
45         std::complex<double> z(imag(t2), -real(t2));
46         if (std::isnan(real(r)))
47             assert(std::isnan(real(z)));
48         else
49         {
50             assert(real(r) == real(z));
51             assert(std::signbit(real(r)) == std::signbit(real(z)));
52         }
53         if (std::isnan(imag(r)))
54             assert(std::isnan(imag(z)));
55         else
56         {
57             assert(imag(r) == imag(z));
58             assert(std::signbit(imag(r)) == std::signbit(imag(z)));
59         }
60     }
61 }
62 
63 int main(int, char**)
64 {
65     test<float>();
66     test<double>();
67     test<long double>();
68     test_edges();
69 
70   return 0;
71 }
72