Difference between revisions of "cpp/numeric/complex/pow"
From cppreference.com
(detail, example) |
LittleFlower (Talk | contribs) m (Add numbers for consistency) |
||
Line 3: | Line 3: | ||
{{dcl begin}} | {{dcl begin}} | ||
{{dcl header | complex}} | {{dcl header | complex}} | ||
− | {{dcl | 1= | + | {{dcl | num = 1 | 1= |
template< class T > | template< class T > | ||
complex<T> pow( const complex<T>& x, const complex<T>& y); | complex<T> pow( const complex<T>& x, const complex<T>& y); | ||
}} | }} | ||
− | {{dcl | 1= | + | {{dcl | num = 2 | 1= |
template< class T > | template< class T > | ||
complex<T> pow( const complex<T>& x, const T& y); | complex<T> pow( const complex<T>& x, const T& y); | ||
}} | }} | ||
− | {{dcl | 1= | + | {{dcl | num = 3 | 1= |
template< class T > | template< class T > | ||
complex<T> pow( const T& x, const complex<T>& y); | complex<T> pow( const T& x, const complex<T>& y); | ||
}} | }} | ||
− | {{dcl | since=c++11 | 1= | + | {{dcl | num = 4 | since=c++11 | 1= |
template< class T, class U > | template< class T, class U > | ||
complex</*Promoted*/> pow( const complex<T>& x, const complex<U>& y); | complex</*Promoted*/> pow( const complex<T>& x, const complex<U>& y); | ||
}} | }} | ||
− | {{dcl | since=c++11 | 1= | + | {{dcl | num = 5 | since=c++11 | 1= |
template< class T, class U > | template< class T, class U > | ||
complex</*Promoted*/> pow( const complex<T>& x, const U& y); | complex</*Promoted*/> pow( const complex<T>& x, const U& y); | ||
}} | }} | ||
− | {{dcl | since=c++11 | 1= | + | {{dcl | num = 6 | since=c++11 | 1= |
template< class T, class U > | template< class T, class U > | ||
complex</*Promoted*/> pow( const T& x, const complex<U>& y); | complex</*Promoted*/> pow( const T& x, const complex<U>& y); | ||
Line 29: | Line 29: | ||
{{dcl end}} | {{dcl end}} | ||
− | Computes complex {{tt|x}} raised to a complex power {{tt|y}} with a branch cut along the negative real axis for the first argument. | + | @1-3@ Computes complex {{tt|x}} raised to a complex power {{tt|y}} with a branch cut along the negative real axis for the first argument. |
− | {{ | + | {{rev begin}} |
+ | {{rev|since=c++11| | ||
+ | @4-6@ Additional overloads are provided for all arithmetic types, such that | ||
:1. If either argument is {{c|long double}} or {{c|std::complex<long double>}}, then both arguments are cast to {{c|std::complex<long double>}} | :1. If either argument is {{c|long double}} or {{c|std::complex<long double>}}, then both arguments are cast to {{c|std::complex<long double>}} | ||
:2. Otherwise, if either argument is {{c|double}}, {{c|std::complex<double>}} or integer type, then both arguments are cast to {{c|std::complex<double>}} | :2. Otherwise, if either argument is {{c|double}}, {{c|std::complex<double>}} or integer type, then both arguments are cast to {{c|std::complex<double>}} | ||
− | :3. Otherwise, if either argument is {{c|float}} or {{c|std::complex<float>}}, then both arguments are cast to {{c|std::complex<float>}} | + | :3. Otherwise, if either argument is {{c|float}} or {{c|std::complex<float>}}, then both arguments are cast to {{c|std::complex<float>}} |
+ | }} | ||
+ | {{rev end}} | ||
===Parameters=== | ===Parameters=== |
Revision as of 01:40, 24 April 2019
Defined in header <complex>
|
||
template< class T > complex<T> pow( const complex<T>& x, const complex<T>& y); |
(1) | |
template< class T > complex<T> pow( const complex<T>& x, const T& y); |
(2) | |
template< class T > complex<T> pow( const T& x, const complex<T>& y); |
(3) | |
template< class T, class U > complex</*Promoted*/> pow( const complex<T>& x, const complex<U>& y); |
(4) | (since C++11) |
template< class T, class U > complex</*Promoted*/> pow( const complex<T>& x, const U& y); |
(5) | (since C++11) |
template< class T, class U > complex</*Promoted*/> pow( const T& x, const complex<U>& y); |
(6) | (since C++11) |
1-3) Computes complex
x
raised to a complex power y
with a branch cut along the negative real axis for the first argument.
4-6) Additional overloads are provided for all arithmetic types, such that
|
(since C++11) |
Contents |
Parameters
x | - | base as a complex value |
y | - | exponent as a complex value |
Return value
If no errors occur, the complex power xy, 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.
Example
Run this code
#include <iostream> #include <complex> int main() { std::cout << std::fixed; std::complex<double> z(1, 2); std::cout << "(1,2)^2 = " << std::pow(z, 2) << '\n'; std::complex<double> z2(-1, 0); // square root of -1 std::cout << "-1^0.5 = " << std::pow(z2, 0.5) << '\n'; std::complex<double> z3(-1, -0.0); // other side of the cut std::cout << "(-1, -0)^0.5 = " << std::pow(z3, 0.5) << '\n'; std::complex<double> i(0, 1); // 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
complex square root in the range of the right half-plane (function template) | |
(C++11)(C++11) |
raises a number to the given power (xy) (function) |
applies the function std::pow to two valarrays or a valarray and a value (function template) | |
C documentation for cpow
|