xref: /minix3/external/bsd/libc++/dist/libcxx/test/numerics/complex.number/cmplx.over/pow.pass.cpp (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc 
10*4684ddb6SLionel Sambuc // <complex>
11*4684ddb6SLionel Sambuc 
12*4684ddb6SLionel Sambuc // template<Arithmetic T, Arithmetic U>
13*4684ddb6SLionel Sambuc //   complex<promote<T, U>::type>
14*4684ddb6SLionel Sambuc //   pow(const T& x, const complex<U>& y);
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc // template<Arithmetic T, Arithmetic U>
17*4684ddb6SLionel Sambuc //   complex<promote<T, U>::type>
18*4684ddb6SLionel Sambuc //   pow(const complex<T>& x, const U& y);
19*4684ddb6SLionel Sambuc 
20*4684ddb6SLionel Sambuc // template<Arithmetic T, Arithmetic U>
21*4684ddb6SLionel Sambuc //   complex<promote<T, U>::type>
22*4684ddb6SLionel Sambuc //   pow(const complex<T>& x, const complex<U>& y);
23*4684ddb6SLionel Sambuc 
24*4684ddb6SLionel Sambuc #include <complex>
25*4684ddb6SLionel Sambuc #include <type_traits>
26*4684ddb6SLionel Sambuc #include <cassert>
27*4684ddb6SLionel Sambuc 
28*4684ddb6SLionel Sambuc #include "../cases.h"
29*4684ddb6SLionel Sambuc 
30*4684ddb6SLionel Sambuc template <class T>
31*4684ddb6SLionel Sambuc double
32*4684ddb6SLionel Sambuc promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0);
33*4684ddb6SLionel Sambuc 
34*4684ddb6SLionel Sambuc float promote(float);
35*4684ddb6SLionel Sambuc double promote(double);
36*4684ddb6SLionel Sambuc long double promote(long double);
37*4684ddb6SLionel Sambuc 
38*4684ddb6SLionel Sambuc template <class T, class U>
39*4684ddb6SLionel Sambuc void
test(T x,const std::complex<U> & y)40*4684ddb6SLionel Sambuc test(T x, const std::complex<U>& y)
41*4684ddb6SLionel Sambuc {
42*4684ddb6SLionel Sambuc     typedef decltype(promote(x)+promote(real(y))) V;
43*4684ddb6SLionel Sambuc     static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
44*4684ddb6SLionel Sambuc     assert(std::pow(x, y) == pow(std::complex<V>(x, 0), std::complex<V>(y)));
45*4684ddb6SLionel Sambuc }
46*4684ddb6SLionel Sambuc 
47*4684ddb6SLionel Sambuc template <class T, class U>
48*4684ddb6SLionel Sambuc void
test(const std::complex<T> & x,U y)49*4684ddb6SLionel Sambuc test(const std::complex<T>& x, U y)
50*4684ddb6SLionel Sambuc {
51*4684ddb6SLionel Sambuc     typedef decltype(promote(real(x))+promote(y)) V;
52*4684ddb6SLionel Sambuc     static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
53*4684ddb6SLionel Sambuc     assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y, 0)));
54*4684ddb6SLionel Sambuc }
55*4684ddb6SLionel Sambuc 
56*4684ddb6SLionel Sambuc template <class T, class U>
57*4684ddb6SLionel Sambuc void
test(const std::complex<T> & x,const std::complex<U> & y)58*4684ddb6SLionel Sambuc test(const std::complex<T>& x, const std::complex<U>& y)
59*4684ddb6SLionel Sambuc {
60*4684ddb6SLionel Sambuc     typedef decltype(promote(real(x))+promote(real(y))) V;
61*4684ddb6SLionel Sambuc     static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
62*4684ddb6SLionel Sambuc     assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y)));
63*4684ddb6SLionel Sambuc }
64*4684ddb6SLionel Sambuc 
65*4684ddb6SLionel Sambuc template <class T, class U>
66*4684ddb6SLionel Sambuc void
test(typename std::enable_if<std::is_integral<T>::value>::type * =0,typename std::enable_if<!std::is_integral<U>::value>::type * =0)67*4684ddb6SLionel Sambuc test(typename std::enable_if<std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
68*4684ddb6SLionel Sambuc {
69*4684ddb6SLionel Sambuc     test(T(3), std::complex<U>(4, 5));
70*4684ddb6SLionel Sambuc     test(std::complex<U>(3, 4), T(5));
71*4684ddb6SLionel Sambuc }
72*4684ddb6SLionel Sambuc 
73*4684ddb6SLionel Sambuc template <class T, class U>
74*4684ddb6SLionel Sambuc void
test(typename std::enable_if<!std::is_integral<T>::value>::type * =0,typename std::enable_if<!std::is_integral<U>::value>::type * =0)75*4684ddb6SLionel Sambuc test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
76*4684ddb6SLionel Sambuc {
77*4684ddb6SLionel Sambuc     test(T(3), std::complex<U>(4, 5));
78*4684ddb6SLionel Sambuc     test(std::complex<T>(3, 4), U(5));
79*4684ddb6SLionel Sambuc     test(std::complex<T>(3, 4), std::complex<U>(5, 6));
80*4684ddb6SLionel Sambuc }
81*4684ddb6SLionel Sambuc 
main()82*4684ddb6SLionel Sambuc int main()
83*4684ddb6SLionel Sambuc {
84*4684ddb6SLionel Sambuc     test<int, float>();
85*4684ddb6SLionel Sambuc     test<int, double>();
86*4684ddb6SLionel Sambuc     test<int, long double>();
87*4684ddb6SLionel Sambuc 
88*4684ddb6SLionel Sambuc     test<unsigned, float>();
89*4684ddb6SLionel Sambuc     test<unsigned, double>();
90*4684ddb6SLionel Sambuc     test<unsigned, long double>();
91*4684ddb6SLionel Sambuc 
92*4684ddb6SLionel Sambuc     test<long long, float>();
93*4684ddb6SLionel Sambuc     test<long long, double>();
94*4684ddb6SLionel Sambuc     test<long long, long double>();
95*4684ddb6SLionel Sambuc 
96*4684ddb6SLionel Sambuc     test<float, double>();
97*4684ddb6SLionel Sambuc     test<float, long double>();
98*4684ddb6SLionel Sambuc 
99*4684ddb6SLionel Sambuc     test<double, float>();
100*4684ddb6SLionel Sambuc     test<double, long double>();
101*4684ddb6SLionel Sambuc 
102*4684ddb6SLionel Sambuc     test<long double, float>();
103*4684ddb6SLionel Sambuc     test<long double, double>();
104*4684ddb6SLionel Sambuc }
105