]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/complex/requirements/more_constexpr.cc
1 // { dg-do compile { target c++20 } }
3 // Copyright (C) 2018-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 #include <testsuite_common_types.h>
25 // Test constexpr real(val) imag(val).
26 template<typename _Tp
, const int _Val
= 42>
28 set_real(std::complex<_Tp
>& a
)
31 template<typename _Tp
, const int _Val
= 42>
33 set_imag(std::complex<_Tp
>& a
)
36 template<typename _Tp
>
40 constexpr std::complex<_Tp
> a
{1.1, 2.2};
42 std::complex<_Tp
> z
= a
;
48 // Test operators @=complex and @=real.
49 template<typename _Tp
, typename _Up
>
50 constexpr std::complex<_Tp
>
51 sum(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
53 std::complex<_Tp
> x
= z
;
58 template<typename _Tp
, typename _Up
>
59 constexpr std::complex<_Tp
>
60 sum(const std::complex<_Tp
>& z
, _Up w
)
62 std::complex<_Tp
> x
= z
;
67 template<typename _Tp
, typename _Up
>
68 constexpr std::complex<_Tp
>
69 dif(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
71 std::complex<_Tp
> x
= z
;
76 template<typename _Tp
, typename _Up
>
77 constexpr std::complex<_Tp
>
78 dif(const std::complex<_Tp
>& z
, _Up w
)
80 std::complex<_Tp
> x
= z
;
85 template<typename _Tp
, typename _Up
>
86 constexpr std::complex<_Tp
>
87 prod(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
89 std::complex<_Tp
> x
= z
;
94 template<typename _Tp
, typename _Up
>
95 constexpr std::complex<_Tp
>
96 prod(const std::complex<_Tp
>& z
, _Up w
)
98 std::complex<_Tp
> x
= z
;
103 template<typename _Tp
, typename _Up
>
104 constexpr std::complex<_Tp
>
105 quot(const std::complex<_Tp
>& z
, const std::complex<_Up
>& w
)
107 std::complex<_Tp
> x
= z
;
112 template<typename _Tp
, typename _Up
>
113 constexpr std::complex<_Tp
>
114 quot(const std::complex<_Tp
>& z
, _Up w
)
116 std::complex<_Tp
> x
= z
;
121 template<typename _Tp
, typename _Up
>
123 test_operator_members()
125 constexpr std::complex<_Tp
> a
{10, 20};
126 constexpr std::complex<_Up
> b
{6, 8};
129 constexpr auto apc
= sum(a
, c
);
130 static_assert(apc
== std::complex<_Tp
>{20, 20});
131 constexpr auto amc
= dif(a
, c
);
132 static_assert(amc
== std::complex<_Tp
>{0, 20});
133 constexpr auto atc
= prod(a
, c
);
134 static_assert(atc
== std::complex<_Tp
>{100, 200});
135 constexpr auto adc
= quot(a
, c
);
136 static_assert(adc
== std::complex<_Tp
>{1, 2});
138 constexpr auto apb
= sum(a
, b
);
139 static_assert(apb
== std::complex<_Tp
>{16, 28});
140 constexpr auto amb
= dif(a
, b
);
141 static_assert(amb
== std::complex<_Tp
>{4, 12});
142 constexpr auto atb
= prod(a
, b
);
143 static_assert(atb
== std::complex<_Tp
>{-100, 200});
144 constexpr auto adb
= quot(a
, b
);
145 static_assert(adb
== std::complex<_Tp
>{11/_Tp
{5}, 2/_Tp
{5}});
151 __gnu_test::test_members
<float>();
152 __gnu_test::test_members
<double>();
153 __gnu_test::test_members
<long double>();
155 __gnu_test::test_operator_members
<float, float>();
156 __gnu_test::test_operator_members
<float, double>();
157 __gnu_test::test_operator_members
<float, long double>();
158 __gnu_test::test_operator_members
<double, float>();
159 __gnu_test::test_operator_members
<double, double>();
160 __gnu_test::test_operator_members
<double, long double>();
161 #ifndef __LONG_DOUBLE_IBM128__ // IBM128 format is not constexpr foldable
162 __gnu_test::test_operator_members
<long double, float>();
163 __gnu_test::test_operator_members
<long double, double>();
164 __gnu_test::test_operator_members
<long double, long double>();
167 #if defined(_GLIBCXX_USE_FLOAT128)
168 // Test primary template.
169 __gnu_test::test_operator_members
<__float128
, __float128
>();