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 // log(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
>(0, 0), std::complex<T
>(-INFINITY
, 0));
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
= log(testcases
[i
]);
42 if (testcases
[i
].real() == 0 && testcases
[i
].imag() == 0)
44 if (std::signbit(testcases
[i
].real()))
46 assert(std::isinf(r
.real()));
48 if (std::signbit(testcases
[i
].imag()))
49 is_about(r
.imag(), -pi
);
51 is_about(r
.imag(), pi
);
55 assert(std::isinf(r
.real()));
57 assert(r
.imag() == 0);
58 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
61 else if (std::isfinite(testcases
[i
].real()) && std::isinf(testcases
[i
].imag()))
63 assert(std::isinf(r
.real()));
65 if (testcases
[i
].imag() > 0)
66 is_about(r
.imag(), pi
/2);
68 is_about(r
.imag(), -pi
/2);
70 else if (std::isfinite(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
72 assert(std::isnan(r
.real()));
73 assert(std::isnan(r
.imag()));
75 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isfinite(testcases
[i
].imag()))
77 assert(std::isinf(r
.real()) && r
.real() > 0);
79 is_about(r
.imag(), pi
);
81 is_about(r
.imag(), -pi
);
83 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isfinite(testcases
[i
].imag()))
85 assert(std::isinf(r
.real()) && r
.real() > 0);
86 assert(r
.imag() == 0);
87 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
89 else if (testcases
[i
].real() == 1 && testcases
[i
].imag() == 0)
91 assert(r
.real() == 0);
92 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
94 else if (testcases
[i
].real() == 0 && testcases
[i
].imag() == 1)
96 assert(r
.real() == 0);
97 is_about(r
.imag(), pi
/2);
99 else if (testcases
[i
].real() == -1 && testcases
[i
].imag() == 0)
101 assert(r
.real() == 0);
102 if (std::signbit(testcases
[i
].imag()))
103 is_about(r
.imag(), -pi
);
105 is_about(r
.imag(), pi
);
107 else if (testcases
[i
].real() == 0 && testcases
[i
].imag() == -1)
109 assert(r
.real() == 0);
110 is_about(r
.imag(), -pi
/2);
112 else if (std::isfinite(testcases
[i
].real()) && std::isfinite(testcases
[i
].imag()) && abs(testcases
[i
]) < 1)
114 assert( std::signbit(r
.real()));
115 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
117 else if (std::isfinite(testcases
[i
].real()) && std::isfinite(testcases
[i
].imag()) && abs(testcases
[i
]) > 1)
119 assert(!std::signbit(r
.real()));
120 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
125 int main(int, char**)