Defined in header <complex> | ||||
---|---|---|---|---|
| ||||
| ||||
| ||||
| (since C++11) | |||
| (since C++11) | |||
| (since C++11) |
Computes complex x
raised to a complex power y
with a branch cut along the negative real axis for the first argument.
(since C++11)Additional overloads are provided for all arithmetic types, such that.
- 1. If either argument is
long double
orstd::complex<long double>
, then both arguments are cast tostd::complex<long double>
- 2. Otherwise, if either argument is
double
,std::complex<double>
or integer type, then both arguments are cast tostd::complex<double>
- 3. Otherwise, if either argument is
float
orstd::complex<float>
, then both arguments are cast tostd::complex<float>
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #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 3 4 | (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) | |
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 |
Please login to continue.