std::pow(std::complex)(3)
β¨ NAME β¨
std::pow(std::complex) β literally std::pow(std::complex), bestie. This is the complex-power glow-up from the C++ Standard Libary, man page section 3, and it's giving βraise a complex number to a powerβ main character energy. π
πΈ Synopsis πΈ
Defined in header <complex>
template< class T > (1) (until C++11)
std::complex<T> pow( const std::complex<T>& x, int y );
template< class T > (2)
std::complex<T> pow( const std::complex<T>& x, const std::complex<T>& y );
template< class T > (3)
std::complex<T> pow( const std::complex<T>& x, const T& y );
template< class T > (4)
std::complex<T> pow( const T& x, const std::complex<T>& y );
Additional overloads (since C++11)
Defined in header <complex>
template< class T1, class T2 > (until C++23)
std::complex</* common-type */> pow( const std::complex<T1>& x, const std::complex<T2>& y );
template< class T1, class T2 > (since C++23)
std::complex<std::common_type_t<T1, T2>> pow( const std::complex<T1>& x, const std::complex<T2>& y );
template< class T, class NonComplex > (A) (until C++23)
std::complex</* common-type */> pow( const std::complex<T>& x, const NonComplex& y );
template< class T, class NonComplex > (B) (since C++23)
std::complex<std::common_type_t<T, NonComplex>> pow( const std::complex<T>& x, const NonComplex& y );
template< class T, class NonComplex > (C) (until C++23)
std::complex</* common-type */> pow( const NonComplex& x, const std::complex<T>& y );
template< class T, class NonComplex > (since C++23)
std::complex<std::common_type_t<T, NonComplex>> pow( const NonComplex& x, const std::complex<T>& y );
1-4) Computes complex x raised to a complex power y with a branch cut along the negative real axis for the first argument. Non-complex arguments are treated as complex numbers with positive zero imaginary component.
A-C) Additional overloads are provided (since C++11). NonComplex is not a specialization of std::complex.
π Parameters π
xβ base. The thing getting powered up. πyβ exponent. The power level. π₯
π Return value π
1-4) If no errors occur, the complex power x^y is returned. Errors and special cases are handled as if the operation is implemented by std::exp(y * std::log(x)).
The result of std::pow(0, 0) is implementation-defined. No cap, that's just how it is. π
A-C) Same as (2-4).
π¦ Notes π¦
Overload (1) was provided in C++98 to match the extra overloads (2) of std::pow. Those overloads were removed by the resolution of LWG issue 550, and overload (1) was removed by the resolution of LWG issue 844.
The additional overloads are not required to be provided exactly as (A-C). They only need to be sufficient to ensure that for their first argument base and second argument exponent:
- If
baseand/orexponenthas typestd::complex<T>:- If
baseand/orexponenthas typestd::complex<long double>orlong double, thenstd::pow(base, exponent)has the same effect asstd::pow(std::complex<long double>(base), std::complex<long double>(exponent)). - Otherwise, if
baseand/orexponenthas typestd::complex<double>,double, or an integer type, thenstd::pow(base, exponent)has the same effect asstd::pow(std::complex<double>(base), std::complex<double>(exponent)). (until C++23) - Otherwise, if
baseand/orexponenthas typestd::complex<float>orfloat, thenstd::pow(base, exponent)has the same effect asstd::pow(std::complex<float>(base), std::complex<float>(exponent)).
- If
- If one argument has type
std::complex<T1>and the other argument has typeT2orstd::complex<T2>, thenstd::pow(base, exponent)has the same effect asstd::pow(std::complex<std::common_type_t<T1, T2>>(base), std::complex<std::common_type_t<T1, T2>>(exponent)). (since C++23) - If
std::common_type_t<T1, T2>is not well-formed, then the program is ill-formed. π©
β¨ Example β¨
// Run this code
#include <complex>
#include <iostream>
int main()
{
std::cout << std::fixed;
std::complex<double> z(1.0, 2.0);
std::cout << "(1,2)^2 = " << std::pow(z, 2) << '\n';
std::complex<double> z2(-1.0, 0.0); // square root of -1
std::cout << "-1^0.5 = " << std::pow(z2, 0.5) << '\n';
std::complex<double> z3(-1.0, -0.0); // other side of the cut
std::cout << "(-1,-0)^0.5 = " << std::pow(z3, 0.5) << '\n';
std::complex<double> i(0.0, 1.0); // i^i = exp(-pi / 2)
std::cout << "i^i = " << std::pow(i, i) << '\n';
}
π Output: π
(1,2)^2 = (-3.000000,4.000000)
-1^0.5 = (0.000000,1.000000)
(-1,-0)^0.5 = (0.000000,-1.000000)
i^i = (0.207880,0.000000)
π See also π
sqrt(std::complex)β complex square root in the range of the right half-plane (function template).pow,powf,powlβ raises a number to the given power ((\(\small{x^y}\)x^y)) (function) (C++11) (C++11).pow(std::valarray)β applies the functionstd::powto two valarrays or a valarray and a value (function template).- C documentation for
cpowβ the C cousin has its own page, periodt.
From http://cppreference.com, version/date 2024.06.10, page std::pow(std::complex)(3) β thatβs the footer, bestie, and we ate. Bye! πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms