[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.value.ops / arg.pass.cpp
blob49c54372a8e0029430826a87585d44a896c8b6f0
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 // T
13 // arg(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()
25 std::complex<T> z(1, 0);
26 assert(arg(z) == 0);
29 void test_edges()
31 const double pi = std::atan2(+0., -0.);
32 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
33 for (unsigned i = 0; i < N; ++i)
35 double r = arg(testcases[i]);
36 if (std::isnan(testcases[i].real()) || std::isnan(testcases[i].imag()))
37 assert(std::isnan(r));
38 else
40 switch (classify(testcases[i]))
42 case zero:
43 if (std::signbit(testcases[i].real()))
45 if (std::signbit(testcases[i].imag()))
46 is_about(r, -pi);
47 else
48 is_about(r, pi);
50 else
52 assert(std::signbit(testcases[i].imag()) == std::signbit(r));
54 break;
55 case non_zero:
56 if (testcases[i].real() == 0)
58 if (testcases[i].imag() < 0)
59 is_about(r, -pi/2);
60 else
61 is_about(r, pi/2);
63 else if (testcases[i].imag() == 0)
65 if (testcases[i].real() < 0)
67 if (std::signbit(testcases[i].imag()))
68 is_about(r, -pi);
69 else
70 is_about(r, pi);
72 else
74 assert(r == 0);
75 assert(std::signbit(testcases[i].imag()) == std::signbit(r));
78 else if (testcases[i].imag() > 0)
79 assert(r > 0);
80 else
81 assert(r < 0);
82 break;
83 case inf:
84 if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
86 if (testcases[i].real() < 0)
88 if (testcases[i].imag() > 0)
89 is_about(r, 0.75 * pi);
90 else
91 is_about(r, -0.75 * pi);
93 else
95 if (testcases[i].imag() > 0)
96 is_about(r, 0.25 * pi);
97 else
98 is_about(r, -0.25 * pi);
101 else if (std::isinf(testcases[i].real()))
103 if (testcases[i].real() < 0)
105 if (std::signbit(testcases[i].imag()))
106 is_about(r, -pi);
107 else
108 is_about(r, pi);
110 else
112 assert(r == 0);
113 assert(std::signbit(r) == std::signbit(testcases[i].imag()));
116 else
118 if (testcases[i].imag() < 0)
119 is_about(r, -pi/2);
120 else
121 is_about(r, pi/2);
123 break;
129 int main(int, char**)
131 test<float>();
132 test<double>();
133 test<long double>();
134 test_edges();
136 return 0;