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 // sqrt(const complex<T>& x);
18 #include "test_macros.h"
23 test(const std::complex<T
>& c
, std::complex<T
> x
)
25 std::complex<T
> a
= sqrt(c
);
26 is_about(real(a
), real(x
));
27 assert(std::abs(imag(c
)) < 1.e
-6);
34 test(std::complex<T
>(64, 0), std::complex<T
>(8, 0));
39 const unsigned N
= sizeof(testcases
) / sizeof(testcases
[0]);
40 for (unsigned i
= 0; i
< N
; ++i
)
42 std::complex<double> r
= sqrt(testcases
[i
]);
43 if (testcases
[i
].real() == 0 && testcases
[i
].imag() == 0)
45 assert(!std::signbit(r
.real()));
46 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
48 else if (std::isinf(testcases
[i
].imag()))
50 assert(std::isinf(r
.real()));
52 assert(std::isinf(r
.imag()));
53 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
55 else if (std::isfinite(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
57 assert(std::isnan(r
.real()));
58 assert(std::isnan(r
.imag()));
60 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isfinite(testcases
[i
].imag()))
62 assert(r
.real() == 0);
63 assert(!std::signbit(r
.real()));
64 assert(std::isinf(r
.imag()));
65 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
67 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isfinite(testcases
[i
].imag()))
69 assert(std::isinf(r
.real()));
71 assert(r
.imag() == 0);
72 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
74 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isnan(testcases
[i
].imag()))
76 assert(std::isnan(r
.real()));
77 assert(std::isinf(r
.imag()));
79 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isnan(testcases
[i
].imag()))
81 assert(std::isinf(r
.real()));
83 assert(std::isnan(r
.imag()));
85 else if (std::isnan(testcases
[i
].real()) && (std::isfinite(testcases
[i
].imag()) || std::isnan(testcases
[i
].imag())))
87 assert(std::isnan(r
.real()));
88 assert(std::isnan(r
.imag()));
90 else if (std::signbit(testcases
[i
].imag()))
92 assert(!std::signbit(r
.real()));
93 assert(std::signbit(r
.imag()));
97 assert(!std::signbit(r
.real()));
98 assert(!std::signbit(r
.imag()));
103 int main(int, char**)