1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <complex> 11 12 // template<class T> 13 // complex<T> 14 // log10(const complex<T>& x); 15 16 #include <complex> 17 #include <cassert> 18 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(log10(c) == x); 26 } 27 28 template <class T> 29 void test()30test() 31 { 32 test(std::complex<T>(0, 0), std::complex<T>(-INFINITY, 0)); 33 } 34 test_edges()35void test_edges() 36 { 37 const double pi = std::atan2(+0., -0.); 38 const unsigned N = sizeof(x) / sizeof(x[0]); 39 for (unsigned i = 0; i < N; ++i) 40 { 41 std::complex<double> r = log10(x[i]); 42 std::complex<double> z = log(x[i])/std::log(10); 43 if (std::isnan(real(r))) 44 assert(std::isnan(real(z))); 45 else 46 { 47 assert(real(r) == real(z)); 48 assert(std::signbit(real(r)) == std::signbit(real(z))); 49 } 50 if (std::isnan(imag(r))) 51 assert(std::isnan(imag(z))); 52 else 53 { 54 assert(imag(r) == imag(z)); 55 assert(std::signbit(imag(r)) == std::signbit(imag(z))); 56 } 57 } 58 } 59 main()60int main() 61 { 62 test<float>(); 63 test<double>(); 64 test<long double>(); 65 test_edges(); 66 } 67