std::sqrt(std::complex)
Min standard notice:
Header: <complex>
Computes the square root of the complex number z with a branch cut along the negative real axis.
# Declarations
template< class T >
std::complex<T> sqrt( const std::complex<T>& z );
# Parameters
z: complex number to take the square root of
# Return value
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).
# Notes
The semantics of this function are intended to be consistent with the C function csqrt.
# Example
#include <complex>
#include <iostream>
int main()
{
std::cout << "Square root of -4 is "
<< std::sqrt(std::complex<double>(-4.0, 0.0)) << '\n'
<< "Square root of (-4,-0) is "
<< std::sqrt(std::complex<double>(-4.0, -0.0))
<< " (the other side of the cut)\n";
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2597 | C++98 | specification mishandles signed zero imaginary parts | erroneous requirement removed |