Skip to content

Commit fc5495f

Browse files
committed
first attempt
1 parent f4a8018 commit fc5495f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

libcxx/include/complex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,18 +1100,38 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> pow(const complex<_Tp>& __x, const com
11001100
return std::exp(__y * std::log(__x));
11011101
}
11021102

1103+
# if _LIBCPP_STD_VER >= 26
1104+
template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
1105+
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, conditional_t<is_integral_v<_Up>, double, _Up>>::type>
1106+
pow(const complex<_Tp>& __x, const complex<_Up>& __y) {
1107+
using _Yp = conditional_t<is_integral_v<_Up>, double, _Up>;
1108+
typedef complex<typename __promote<_Tp, _Yp>::type> result_type;
1109+
return std::pow(result_type(__x), result_type(__y));
1110+
}
1111+
# else
11031112
template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
11041113
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type>
11051114
pow(const complex<_Tp>& __x, const complex<_Up>& __y) {
11061115
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11071116
return std::pow(result_type(__x), result_type(__y));
11081117
}
1118+
# endif
11091119

1120+
# if _LIBCPP_STD_VER >= 26
1121+
template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
1122+
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, conditional_t<is_integral_v<_Up>, double, _Up>>::type>
1123+
pow(const complex<_Tp>& __x, const _Up& __y) {
1124+
using _Yp = conditional_t<is_integral_v<_Up>, double, _Up>;
1125+
typedef complex<typename __promote<_Tp, _Yp>::type> result_type;
1126+
return std::pow(result_type(__x), result_type(__y));
1127+
}
1128+
# else
11101129
template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
11111130
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const complex<_Tp>& __x, const _Up& __y) {
11121131
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11131132
return std::pow(result_type(__x), result_type(__y));
11141133
}
1134+
# endif
11151135

11161136
template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
11171137
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const _Tp& __x, const complex<_Up>& __y) {

libcxx/test/libcxx/numerics/complex.number/cmplx.over.pow.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,8 @@ int main(int, char**) {
8282
assert(pow(ctag, std::complex<long double>(1.0l)) == 4);
8383
assert(pow(std::complex<long double>(1.0l), ctag) == 5);
8484

85+
// Make sure LWG4191: P1467 is respected.
86+
static_assert(std::is_same_v<decltype(std::pow(std::complex<float>(), int())), std::complex<double>>, "");
87+
8588
return 0;
8689
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ int main(int, char**)
101101

102102
test<long double, float>();
103103
test<long double, double>();
104+
105+
// Make sure LWG4191: P1467 is respected.
106+
static_assert(std::is_same_v<decltype(std::pow(std::complex<float>(), int())), std::complex<double>>, "");
104107

105108
return 0;
106109
}

0 commit comments

Comments
 (0)