1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<Arithmetic T, Arithmetic U>
12 // complex<promote<T, U>::type>
13 // pow(const T& x, const complex<U>& y);
15 // template<Arithmetic T, Arithmetic U>
16 // complex<promote<T, U>::type>
17 // pow(const complex<T>& x, const U& y);
19 // template<Arithmetic T, Arithmetic U>
20 // complex<promote<T, U>::type>
21 // pow(const complex<T>& x, const complex<U>& y);
24 #include <type_traits>
27 #include "test_macros.h"
32 promote(T
, typename
std::enable_if
<std::is_integral
<T
>::value
>::type
* = 0);
35 double promote(double);
36 long double promote(long double);
38 template <class T
, class U
>
40 test(T x
, const std::complex<U
>& y
)
42 typedef decltype(promote(x
)+promote(real(y
))) V
;
43 static_assert((std::is_same
<decltype(std::pow(x
, y
)), std::complex<V
> >::value
), "");
44 assert(std::pow(x
, y
) == pow(std::complex<V
>(x
, 0), std::complex<V
>(y
)));
47 template <class T
, class U
>
49 test(const std::complex<T
>& x
, U y
)
51 typedef decltype(promote(real(x
))+promote(y
)) V
;
52 static_assert((std::is_same
<decltype(std::pow(x
, y
)), std::complex<V
> >::value
), "");
53 assert(std::pow(x
, y
) == pow(std::complex<V
>(x
), std::complex<V
>(y
, 0)));
56 template <class T
, class U
>
58 test(const std::complex<T
>& x
, const std::complex<U
>& y
)
60 typedef decltype(promote(real(x
))+promote(real(y
))) V
;
61 static_assert((std::is_same
<decltype(std::pow(x
, y
)), std::complex<V
> >::value
), "");
62 assert(std::pow(x
, y
) == pow(std::complex<V
>(x
), std::complex<V
>(y
)));
65 template <class T
, class U
>
67 test(typename
std::enable_if
<std::is_integral
<T
>::value
>::type
* = 0, typename
std::enable_if
<!std::is_integral
<U
>::value
>::type
* = 0)
69 test(T(3), std::complex<U
>(4, 5));
70 test(std::complex<U
>(3, 4), T(5));
73 template <class T
, class U
>
75 test(typename
std::enable_if
<!std::is_integral
<T
>::value
>::type
* = 0, typename
std::enable_if
<!std::is_integral
<U
>::value
>::type
* = 0)
77 test(T(3), std::complex<U
>(4, 5));
78 test(std::complex<T
>(3, 4), U(5));
79 test(std::complex<T
>(3, 4), std::complex<U
>(5, 6));
86 test
<int, long double>();
88 test
<unsigned, float>();
89 test
<unsigned, double>();
90 test
<unsigned, long double>();
92 test
<long long, float>();
93 test
<long long, double>();
94 test
<long long, long double>();
96 test
<float, double>();
97 test
<float, long double>();
99 test
<double, float>();
100 test
<double, long double>();
102 test
<long double, float>();
103 test
<long double, double>();