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 // arg(const complex<T>& x);
18 #include "test_macros.h"
25 std::complex<T
> z(1, 0);
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
));
40 switch (classify(testcases
[i
]))
43 if (std::signbit(testcases
[i
].real()))
45 if (std::signbit(testcases
[i
].imag()))
52 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
));
56 if (testcases
[i
].real() == 0)
58 if (testcases
[i
].imag() < 0)
63 else if (testcases
[i
].imag() == 0)
65 if (testcases
[i
].real() < 0)
67 if (std::signbit(testcases
[i
].imag()))
75 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
));
78 else if (testcases
[i
].imag() > 0)
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
);
91 is_about(r
, -0.75 * pi
);
95 if (testcases
[i
].imag() > 0)
96 is_about(r
, 0.25 * pi
);
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()))
113 assert(std::signbit(r
) == std::signbit(testcases
[i
].imag()));
118 if (testcases
[i
].imag() < 0)
129 int main(int, char**)