]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/complex/requirements/more_constexpr.cc
1 // { dg-options "-std=gnu++2a" }
2 // { dg-do compile { target c++2a } }
4 // Copyright (C) 2018-2019 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #include <testsuite_common_types.h>
26 // Test constexpr real(val) imag(val).
27 template<typename _Tp
, const int _Val
= 42>
29 set_real(std::complex<_Tp
>& a
)
32 template<typename _Tp
, const int _Val
= 42>
34 set_imag(std::complex<_Tp
>& a
)
37 template<typename _Tp
>
41 constexpr std::complex<_Tp
> a
{1.1, 2.2};
43 std::complex<_Tp
> z
= a
;
49 // Test operators @=complex and @=real.
50 template<typename _Tp
, typename _Up
>
51 constexpr std::complex<_Tp
>
52 sum(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
54 std::complex<_Tp
> x
= z
;
59 template<typename _Tp
, typename _Up
>
60 constexpr std::complex<_Tp
>
61 sum(const std::complex<_Tp
>& z
, _Up w
)
63 std::complex<_Tp
> x
= z
;
68 template<typename _Tp
, typename _Up
>
69 constexpr std::complex<_Tp
>
70 dif(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
72 std::complex<_Tp
> x
= z
;
77 template<typename _Tp
, typename _Up
>
78 constexpr std::complex<_Tp
>
79 dif(const std::complex<_Tp
>& z
, _Up w
)
81 std::complex<_Tp
> x
= z
;
86 template<typename _Tp
, typename _Up
>
87 constexpr std::complex<_Tp
>
88 prod(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
90 std::complex<_Tp
> x
= z
;
95 template<typename _Tp
, typename _Up
>
96 constexpr std::complex<_Tp
>
97 prod(const std::complex<_Tp
>& z
, _Up w
)
99 std::complex<_Tp
> x
= z
;
104 template<typename _Tp
, typename _Up
>
105 constexpr std::complex<_Tp
>
106 quot(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
108 std::complex<_Tp
> x
= z
;
113 template<typename _Tp
, typename _Up
>
114 constexpr std::complex<_Tp
>
115 quot(const std::complex<_Tp
>& z
, _Up w
)
117 std::complex<_Tp
> x
= z
;
122 template<typename _Tp
, typename _Up
>
124 test_operator_members()
126 constexpr std::complex<_Tp
> a
{10, 20};
127 constexpr std::complex<_Up
> b
{6, 8};
130 constexpr auto apc
= sum(a
, c
);
131 static_assert(apc
== std::complex<_Tp
>{20, 20});
132 constexpr auto amc
= dif(a
, c
);
133 static_assert(amc
== std::complex<_Tp
>{0, 20});
134 constexpr auto atc
= prod(a
, c
);
135 static_assert(atc
== std::complex<_Tp
>{100, 200});
136 constexpr auto adc
= quot(a
, c
);
137 static_assert(adc
== std::complex<_Tp
>{1, 2});
139 constexpr auto apb
= sum(a
, b
);
140 static_assert(apb
== std::complex<_Tp
>{16, 28});
141 constexpr auto amb
= dif(a
, b
);
142 static_assert(amb
== std::complex<_Tp
>{4, 12});
143 constexpr auto atb
= prod(a
, b
);
144 static_assert(atb
== std::complex<_Tp
>{-100, 200});
145 constexpr auto adb
= quot(a
, b
);
146 static_assert(adb
== std::complex<_Tp
>{11/_Tp
{5}, 2/_Tp
{5}});
152 __gnu_test::test_members
<float>();
153 __gnu_test::test_members
<double>();
154 __gnu_test::test_members
<long double>();
156 __gnu_test::test_operator_members
<float, float>();
157 __gnu_test::test_operator_members
<float, double>();
158 __gnu_test::test_operator_members
<float, long double>();
159 __gnu_test::test_operator_members
<double, float>();
160 __gnu_test::test_operator_members
<double, double>();
161 __gnu_test::test_operator_members
<double, long double>();
162 #ifndef __LONG_DOUBLE_IBM128__ // IBM128 format is not constexpr foldable
163 __gnu_test::test_operator_members
<long double, float>();
164 __gnu_test::test_operator_members
<long double, double>();
165 __gnu_test::test_operator_members
<long double, long double>();
168 #if defined(_GLIBCXX_USE_FLOAT128)
169 // Test primary template.
170 __gnu_test::test_operator_members
<__float128
, __float128
>();