• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // void real(T val);
13 // void imag(T val);
14 
15 #include <complex>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 template <class T>
21 void
test_constexpr()22 test_constexpr()
23 {
24 #if TEST_STD_VER > 11
25     constexpr std::complex<T> c1;
26     static_assert(c1.real() == 0, "");
27     static_assert(c1.imag() == 0, "");
28     constexpr std::complex<T> c2(3);
29     static_assert(c2.real() == 3, "");
30     static_assert(c2.imag() == 0, "");
31     constexpr std::complex<T> c3(3, 4);
32     static_assert(c3.real() == 3, "");
33     static_assert(c3.imag() == 4, "");
34 #endif
35 }
36 
37 template <class T>
38 void
test()39 test()
40 {
41     std::complex<T> c;
42     assert(c.real() == 0);
43     assert(c.imag() == 0);
44     c.real(3.5);
45     assert(c.real() == 3.5);
46     assert(c.imag() == 0);
47     c.imag(4.5);
48     assert(c.real() == 3.5);
49     assert(c.imag() == 4.5);
50     c.real(-4.5);
51     assert(c.real() == -4.5);
52     assert(c.imag() == 4.5);
53     c.imag(-5.5);
54     assert(c.real() == -4.5);
55     assert(c.imag() == -5.5);
56 
57     test_constexpr<T> ();
58 }
59 
main()60 int main()
61 {
62     test<float>();
63     test<double>();
64     test<long double>();
65     test_constexpr<int> ();
66 }
67