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