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 // T 13 // norm(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() 23 { 24 std::complex<T> z(3, 4); 25 assert(norm(z) == 25); 26 } 27 28 void test_edges() 29 { 30 const unsigned N = sizeof(testcases) / sizeof(testcases[0]); 31 for (unsigned i = 0; i < N; ++i) 32 { 33 double r = norm(testcases[i]); 34 switch (classify(testcases[i])) 35 { 36 case zero: 37 assert(r == 0); 38 assert(!std::signbit(r)); 39 break; 40 case non_zero: 41 assert(std::isfinite(r) && r > 0); 42 break; 43 case inf: 44 assert(std::isinf(r) && r > 0); 45 break; 46 case NaN: 47 assert(std::isnan(r)); 48 break; 49 case non_zero_nan: 50 assert(std::isnan(r)); 51 break; 52 } 53 } 54 } 55 56 int main(int, char**) 57 { 58 test<float>(); 59 test<double>(); 60 test<long double>(); 61 test_edges(); 62 63 return 0; 64 } 65