Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / complex.number / cmplx.over / pow.pass.cpp
blob54a6cba9c00118cda840a51fc59fd6f6a0c63afc
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 //===----------------------------------------------------------------------===//
9 // <complex>
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);
23 #include <complex>
24 #include <type_traits>
25 #include <cassert>
27 #include "test_macros.h"
28 #include "../cases.h"
30 template <class T>
31 double
32 promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0);
34 float promote(float);
35 double promote(double);
36 long double promote(long double);
38 template <class T, class U>
39 void
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>
48 void
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>
57 void
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>
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)
69 test(T(3), std::complex<U>(4, 5));
70 test(std::complex<U>(3, 4), T(5));
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)
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));
82 int main(int, char**)
84 test<int, float>();
85 test<int, double>();
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>();
105 return 0;