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 30 template <class T> 31 double 32 promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0); 33 34 float promote(float); 35 double promote(double); 36 long double promote(long double); 37 38 template <class T, class U> 39 void 40 test(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 47 template <class T, class U> 48 void 49 test(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 56 template <class T, class U> 57 void 58 test(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 65 template <class T, class U> 66 void 67 test(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 73 template <class T, class U> 74 void 75 test(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 82 int 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