New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math/cmplx: wrong value for Sqrt(-1-0i) #29219
Comments
/cc @griesemer @robpike |
Note that this is the correct behavior of the Sqrt function along the branch cut on the negative real axis. This issue was previously corrected in #6888. For reference see "Branch Cuts for Complex Elementary Functions or Much Ado About Nothing's Sign Bit" W. Kahan: https://people.freebsd.org/~das/kahan86branch.pdf Eq. 4.2
|
Seems to me to be working as intended. |
Thanks for the link. I agree, the behaviour of cmplx.Sqrt is correct. I am more surprised how negation works: This translates to complex numbers, where taking a square root has the aforementioned effect. |
What you're getting confused by is constants. See https://blog.golang.org/constants Notably, there are no negative zero constants. It's not a IEEE 754 floating point number until it's in memory. The expression I agree that can be confusing. |
Thank you for the explanation. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
Also in playground.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/fB9f-yYvErS
Negating a complex128 with the value 1 results in (-1-0i), while negating complex(1,0) results in (-1+0i).
This might still be acceptable, but taking the sqrt of the former results in (0-1i)
What did you expect to see?
(0+1i)
What did you see instead?
(0-1i)
The text was updated successfully, but these errors were encountered: