Defined in header <complex> | ||
|---|---|---|
template< class T > complex<T> sqrt( const complex<T>& z ); |
Computes the square root of the complex number z with a branch cut along the negative real axis.
| z | - | complex number to take the square root of |
If no errors occur, returns the square root of z, in the range of the right half-plane, including the imaginary axis ([0; +∞) along the real axis and (−∞; +∞) along the imaginary axis.).
If the argument is a negative real number, the result lies on the positive imaginary axis.
Errors are reported consistent with math_errhandling.
If the implementation supports IEEE floating-point arithmetic,
std::sqrt(std::conj(z)) == std::conj(std::sqrt(z)) z is (±0,+0), the result is (+0,+0) z is (x,+∞), the result is (+∞,+∞) even if x is NaN z is (x,NaN), the result is (NaN,NaN) (unless x is ±∞) and FE_INVALID may be raised z is (-∞,y), the result is (+0,+∞) for finite positive y z is (+∞,y), the result is (+∞,+0) for finite positive y z is (-∞,NaN), the result is (NaN,∞) (sign of imaginary part unspecified) z is (+∞,NaN), the result is (+∞,NaN) z is (NaN,y), the result is (NaN,NaN) and FE_INVALID may be raised z is (NaN,NaN), the result is (NaN,NaN) #include <iostream>
#include <complex>
int main()
{
std::cout << "Square root of -4 is "
<< std::sqrt(std::complex<double>(-4, 0)) << '\n'
<< "Square root of (-4,-0), the other side of the cut, is "
<< std::sqrt(std::complex<double>(-4, -0.0)) << '\n';
}Output:
Square root of -4 is (0,2) Square root of (-4,-0), the other side of the cut, is (0,-2)
| complex power, one or both arguments may be a complex number (function template) |
|
| computes square root (√x) (function) |
|
applies the function std::sqrt to each element of valarray (function template) |
|
C documentation for csqrt |
|
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/numeric/complex/sqrt