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 //===----------------------------------------------------------------------===// 8 9 // <complex> 10 11 // template<class T> 12 // complex<T> 13 // exp(const complex<T>& x); 14 15 #include <complex> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "../cases.h" 20 21 template <class T> 22 void test(const std::complex<T> & c,std::complex<T> x)23test(const std::complex<T>& c, std::complex<T> x) 24 { 25 assert(exp(c) == x); 26 } 27 28 template <class T> 29 void test()30test() 31 { 32 test(std::complex<T>(0, 0), std::complex<T>(1, 0)); 33 } 34 test_edges()35void test_edges() 36 { 37 const unsigned N = sizeof(testcases) / sizeof(testcases[0]); 38 for (unsigned i = 0; i < N; ++i) 39 { 40 std::complex<double> r = exp(testcases[i]); 41 if (testcases[i].real() == 0 && testcases[i].imag() == 0) 42 { 43 assert(r.real() == 1.0); 44 assert(r.imag() == 0); 45 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag())); 46 } 47 else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag())) 48 { 49 assert(std::isnan(r.real())); 50 assert(std::isnan(r.imag())); 51 } 52 else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag())) 53 { 54 assert(std::isnan(r.real())); 55 assert(std::isnan(r.imag())); 56 } 57 else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && testcases[i].imag() == 0) 58 { 59 assert(std::isinf(r.real())); 60 assert(r.real() > 0); 61 assert(r.imag() == 0); 62 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag())); 63 } 64 else if (std::isinf(testcases[i].real()) && testcases[i].real() < 0 && std::isinf(testcases[i].imag())) 65 { 66 assert(r.real() == 0); 67 assert(r.imag() == 0); 68 } 69 else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && std::isinf(testcases[i].imag())) 70 { 71 assert(std::isinf(r.real())); 72 assert(std::isnan(r.imag())); 73 } 74 else if (std::isinf(testcases[i].real()) && testcases[i].real() < 0 && std::isnan(testcases[i].imag())) 75 { 76 assert(r.real() == 0); 77 assert(r.imag() == 0); 78 } 79 else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && std::isnan(testcases[i].imag())) 80 { 81 assert(std::isinf(r.real())); 82 assert(std::isnan(r.imag())); 83 } 84 else if (std::isnan(testcases[i].real()) && testcases[i].imag() == 0) 85 { 86 assert(std::isnan(r.real())); 87 assert(r.imag() == 0); 88 assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag())); 89 } 90 else if (std::isnan(testcases[i].real()) && testcases[i].imag() != 0) 91 { 92 assert(std::isnan(r.real())); 93 assert(std::isnan(r.imag())); 94 } 95 else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag())) 96 { 97 assert(std::isnan(r.real())); 98 assert(std::isnan(r.imag())); 99 } 100 else if (std::isfinite(testcases[i].imag()) && std::abs(testcases[i].imag()) <= 1) 101 { 102 assert(!std::signbit(r.real())); 103 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag())); 104 } 105 } 106 } 107 main(int,char **)108int main(int, char**) 109 { 110 test<float>(); 111 test<double>(); 112 test<long double>(); 113 test_edges(); 114 115 return 0; 116 } 117