Computes the square root of the complex number z with a branch cut along the negative real axis.
[edit] Parameters z - complex number to take the square root of [edit] Return valueIf 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).
[edit] Error handling and special valuesErrors are reported consistent with math_errhandling.
If the implementation supports IEEE floating-point arithmetic,
(±0,+0)
, the result is (+0,+0)
(x,+â)
, the result is (+â,+â)
even if x is NaN(x,NaN)
, the result is (NaN,NaN)
(unless x is ±â) and FE_INVALID may be raised(-â,y)
, the result is (+0,+â)
for finite positive y(+â,y)
, the result is (+â,+0)
for finite positive y(-â,NaN)
, the result is (NaN,â)
(sign of imaginary part unspecified)(+â,NaN)
, the result is (+â,NaN)
(NaN,y)
, the result is (NaN,NaN)
and FE_INVALID may be raised(NaN,NaN)
, the result is (NaN,NaN)
The semantics of this function are intended to be consistent with the C function csqrt.
[edit] 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"; }
Output:
Square root of -4 is (0,2) Square root of (-4,-0) is (0,-2) (the other side of the cut)[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 2597 C++98 specification mishandles signed zero imaginary parts erroneous requirement removed [edit] See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4