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