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 // exp(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
>(1, 0));
37 const unsigned N
= sizeof(testcases
) / sizeof(testcases
[0]);
38 for (unsigned i
= 0; i
< N
; ++i
)
40 std::complex<double> r
= exp(testcases
[i
]);
41 if (testcases
[i
].real() == 0 && testcases
[i
].imag() == 0)
43 assert(r
.real() == 1.0);
44 assert(r
.imag() == 0);
45 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
47 else if (std::isfinite(testcases
[i
].real()) && std::isinf(testcases
[i
].imag()))
49 assert(std::isnan(r
.real()));
50 assert(std::isnan(r
.imag()));
52 else if (std::isfinite(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
54 assert(std::isnan(r
.real()));
55 assert(std::isnan(r
.imag()));
57 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && testcases
[i
].imag() == 0)
59 assert(std::isinf(r
.real()));
61 assert(r
.imag() == 0);
62 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
64 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isinf(testcases
[i
].imag()))
66 assert(r
.real() == 0);
67 assert(r
.imag() == 0);
69 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isinf(testcases
[i
].imag()))
71 assert(std::isinf(r
.real()));
72 assert(std::isnan(r
.imag()));
74 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() < 0 && std::isnan(testcases
[i
].imag()))
76 assert(r
.real() == 0);
77 assert(r
.imag() == 0);
79 else if (std::isinf(testcases
[i
].real()) && testcases
[i
].real() > 0 && std::isnan(testcases
[i
].imag()))
81 assert(std::isinf(r
.real()));
82 assert(std::isnan(r
.imag()));
84 else if (std::isnan(testcases
[i
].real()) && testcases
[i
].imag() == 0)
86 assert(std::isnan(r
.real()));
87 assert(r
.imag() == 0);
88 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
90 else if (std::isnan(testcases
[i
].real()) && testcases
[i
].imag() != 0)
92 assert(std::isnan(r
.real()));
93 assert(std::isnan(r
.imag()));
95 else if (std::isnan(testcases
[i
].real()) && std::isnan(testcases
[i
].imag()))
97 assert(std::isnan(r
.real()));
98 assert(std::isnan(r
.imag()));
100 else if (std::isfinite(testcases
[i
].imag()) && std::abs(testcases
[i
].imag()) <= 1)
102 assert(!std::signbit(r
.real()));
103 assert(std::signbit(r
.imag()) == std::signbit(testcases
[i
].imag()));
105 else if (std::isinf(r
.real()) && testcases
[i
].imag() == 0) {
106 assert(r
.imag() == 0);
107 assert(std::signbit(testcases
[i
].imag()) == std::signbit(r
.imag()));
112 int main(int, char**)