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// template<Arithmetic T, Arithmetic U>
12// complex<promote<T, U>::type>
13// pow(const T& x, const complex<U>& y);
14
15// template<Arithmetic T, Arithmetic U>
16// complex<promote<T, U>::type>
17// pow(const complex<T>& x, const U& y);
18
19// template<Arithmetic T, Arithmetic U>
20// complex<promote<T, U>::type>
21// pow(const complex<T>& x, const complex<U>& y);
22
23#include <complex>
24#include <type_traits>
25#include <cassert>
26
27#include "test_macros.h"
28#include "../cases.h"
29
30template <class T>
31double
32promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0);
33
34float promote(float);
35double promote(double);
36long double promote(long double);
37
38template <class T, class U>
39void
40test(T x, const std::complex<U>& y)
41{
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)));
45}
46
47template <class T, class U>
48void
49test(const std::complex<T>& x, U y)
50{
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)));
54}
55
56template <class T, class U>
57void
58test(const std::complex<T>& x, const std::complex<U>& y)
59{
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)));
63}
64
65template <class T, class U>
66void
67test(typename std::enable_if<std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
68{
69 test(T(3), std::complex<U>(4, 5));
70 test(std::complex<U>(3, 4), T(5));
71}
72
73template <class T, class U>
74void
75test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
76{
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));
80}
81
82int main(int, char**)
83{
84 test<int, float>();
85 test<int, double>();
86 test<int, long double>();
87
88 test<unsigned, float>();
89 test<unsigned, double>();
90 test<unsigned, long double>();
91
92 test<long long, float>();
93 test<long long, double>();
94 test<long long, long double>();
95
96 test<float, double>();
97 test<float, long double>();
98
99 test<double, float>();
100 test<double, long double>();
101
102 test<long double, float>();
103 test<long double, double>();
104
105 return 0;
106}
107

source code of libcxx/test/std/numerics/complex.number/cmplx.over/pow.pass.cpp