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