std::sqrt(std::complex)

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

# 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

DRApplied toBehavior as publishedCorrect behavior
LWG 2597C++98specification mishandles signed zero imaginary partserroneous requirement removed

# See also