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<Arithmetic T>
12 //   T
13 //   norm(T x);
14 
15 #include <complex>
16 #include <type_traits>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "../cases.h"
21 
22 template <class T>
23 void
test(T x,typename std::enable_if<std::is_integral<T>::value>::type * =0)24 test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
25 {
26     static_assert((std::is_same<decltype(std::norm(x)), double>::value), "");
27     assert(std::norm(x) == norm(std::complex<double>(static_cast<double>(x), 0)));
28 }
29 
30 template <class T>
31 void
test(T x,typename std::enable_if<!std::is_integral<T>::value>::type * =0)32 test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
33 {
34     static_assert((std::is_same<decltype(std::norm(x)), T>::value), "");
35     assert(std::norm(x) == norm(std::complex<T>(x, 0)));
36 }
37 
38 template <class T>
39 void
test()40 test()
41 {
42     test<T>(0);
43     test<T>(1);
44     test<T>(10);
45 }
46 
main(int,char **)47 int main(int, char**)
48 {
49     test<float>();
50     test<double>();
51     test<long double>();
52     test<int>();
53     test<unsigned>();
54     test<long long>();
55 
56   return 0;
57 }
58