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 // T 14 // abs(const complex<T>& x); 15 16 #include <complex> 17 #include <cassert> 18 19 #include "../cases.h" 20 21 template <class T> 22 void test()23test() 24 { 25 std::complex<T> z(3, 4); 26 assert(abs(z) == 5); 27 } 28 test_edges()29void test_edges() 30 { 31 const unsigned N = sizeof(testcases) / sizeof(testcases[0]); 32 for (unsigned i = 0; i < N; ++i) 33 { 34 double r = abs(testcases[i]); 35 switch (classify(testcases[i])) 36 { 37 case zero: 38 assert(r == 0); 39 assert(!std::signbit(r)); 40 break; 41 case non_zero: 42 assert(std::isfinite(r) && r > 0); 43 break; 44 case inf: 45 assert(std::isinf(r) && r > 0); 46 break; 47 case NaN: 48 assert(std::isnan(r)); 49 break; 50 case non_zero_nan: 51 assert(std::isnan(r)); 52 break; 53 } 54 } 55 } 56 main()57int main() 58 { 59 test<float>(); 60 test<double>(); 61 test<long double>(); 62 test_edges(); 63 } 64