[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.members / real_imag.pass.cpp
blob26db8ddf3b4caa73c0a95a1b05c3fb0e91b433fb
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 //===----------------------------------------------------------------------===//
9 // <complex>
11 // void real(T val); // constexpr in C++20
12 // void imag(T val); // constexpr in C++20
14 #include <complex>
15 #include <cassert>
17 #include "test_macros.h"
19 template <class T>
20 TEST_CONSTEXPR_CXX20
21 void
22 test_constexpr()
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
37 template <class T>
38 TEST_CONSTEXPR_CXX20
39 bool
40 test()
42 std::complex<T> c;
43 assert(c.real() == 0);
44 assert(c.imag() == 0);
45 c.real(3.5);
46 assert(c.real() == 3.5);
47 assert(c.imag() == 0);
48 c.imag(4.5);
49 assert(c.real() == 3.5);
50 assert(c.imag() == 4.5);
51 c.real(-4.5);
52 assert(c.real() == -4.5);
53 assert(c.imag() == 4.5);
54 c.imag(-5.5);
55 assert(c.real() == -4.5);
56 assert(c.imag() == -5.5);
58 test_constexpr<T>();
59 return true;
62 int main(int, char**) {
63 test<float>();
64 test<double>();
65 test<long double>();
66 test_constexpr<int>();
68 #if TEST_STD_VER >= 20
69 static_assert(test<float>());
70 static_assert(test<double>());
71 static_assert(test<long double>());
72 #endif
74 return 0;