Debian Codegraph @

libcxx/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp

raw
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 "test_macros.h"
19 #include "../cases.h"
20
21 template <class T>
22 void
23 test()
24 {
25 std::complex<T> z(3, 4);
26 assert(norm(z) == 25);
27 }
28
29 void test_edges()
30 {
31 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
32 for (unsigned i = 0; i < N; ++i)
33 {
34 double r = norm(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
57 int main(int, char**)
58 {
59 test<float>();
60 test<double>();
61 test<long double>();
62 test_edges();
63
64 return 0;
65 }