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 // log10(const complex<T>& x); 14 15 #include <complex> 16 #include <cassert> 17 18 #include "../cases.h" 19 20 template <class T> 21 void 22 test(const std::complex<T>& c, std::complex<T> x) 23 { 24 assert(log10(c) == x); 25 } 26 27 template <class T> 28 void 29 test() 30 { 31 test(std::complex<T>(0, 0), std::complex<T>(-INFINITY, 0)); 32 } 33 34 void test_edges() 35 { 36 const unsigned N = sizeof(testcases) / sizeof(testcases[0]); 37 for (unsigned i = 0; i < N; ++i) 38 { 39 std::complex<double> r = log10(testcases[i]); 40 std::complex<double> z = log(testcases[i])/std::log(10); 41 if (std::isnan(real(r))) 42 assert(std::isnan(real(z))); 43 else 44 { 45 assert(real(r) == real(z)); 46 assert(std::signbit(real(r)) == std::signbit(real(z))); 47 } 48 if (std::isnan(imag(r))) 49 assert(std::isnan(imag(z))); 50 else 51 { 52 assert(imag(r) == imag(z)); 53 assert(std::signbit(imag(r)) == std::signbit(imag(z))); 54 } 55 } 56 } 57 58 int main(int, char**) 59 { 60 test<float>(); 61 test<double>(); 62 test<long double>(); 63 test_edges(); 64 65 return 0; 66 } 67