-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
angle of complex zeros #20924
Comments
none of the above is incorrect (as we have 2pi periodicity) and for sure should not be NaN. |
The limit of |
I can see that defining |
I might be biased here, as i live happily with matlabs angle(complex(0,0)) =0 ... and some parts of my simulator survive singularities on that (antenna patterns with an NaN angle tend to be undefined). |
Yes,
produces a result in the wrong quadrant. |
The argument of a complex number with modulus zero is undefined (see Wolfram). |
Wikipedia means: "The polar angle for the complex number 0 is indeterminate, but arbitrary choice of the angle 0 is common." https://en.wikipedia.org/wiki/Complex_number 0 is a valid arbitray choice. |
So there are two issues here:
And tests, of course. This is ready for action if anyone wants to tackle it. |
I'm marking this as a bug based on the following analysis:
If they are not relying on either of these things, then their code will not be affected by a fix. |
The current behavior of |
|
Part of the confusion here is due to the fact that julia> z = Complex(-0.0, 0.0)
-0.0 + 0.0im
julia> real(z)
-0.0
julia> angle(z)
3.141592653589793
julia> atan2(imag(z), real(z))
3.141592653589793
julia> w = -0.0 + 0.0im
0.0 + 0.0im
julia> real(w)
0.0
julia> angle(w)
0.0 This stems from the lack of an imaginary type (see also #5468 and #10000), since IEEE rules give |
I removed the "bug" label and added the "decision" label. I think the correct decision is "leave as-is". This behavior of For example, in Python I also get: >>> import cmath
>>> cmath.phase(complex(-0.0, 0.0))
3.141592653589793
>>> cmath.phase(complex(-0.0, -0.0))
-3.141592653589793
>>> cmath.phase(-0.0 + 0.0j)
0.0 Note that Python has the same problem with the lack of an imaginary type, so you need to call the |
In gfortran-6 compilation of the following code gives an error:
If both the real and the imaginary part are zero, the most logical thing we can do is to throw an |
The problem arises from the fact that we are evaluating a limit:
|
I'd much prefer to stay with the current behavior (and document it). When writing things in polar form, for example, it is annoying to have an exception thrown at 0+0im, even though any angle is valid there. Similarly I suspect that most programs would rather atan2 pick something at (0,0) rather than throw an exception, since any angle at (0,0) will usually be acceptable. Fortran's behavior for atan2 was probably set in the 60s or 70s, long before IEEE floating-point standards, and I'd much rather agree with the ISO C standard's choice of behavior on this. |
(I'm extremely suspicious of discarding the ISO C behavior of a basic mathematical function based on people's gut reactions in a github issue. If the ISO |
I think this behaviour is what you really want to get out of angle for signed zeros.
Unfortunately it doesn't hold for
|
By the way, even though julia> 0.0^0.0
1.0
julia> (0.0 + 0.0im) ^ (0.0 + 0.0im)
1.0 + 0.0im |
See also the discussion of this when it came up in Octave; they decided to follow ISO/IEC. Matlab's |
The R |
Also, the behaviour of Another advantage of the current behaviour is that |
On the other hand, |
@GunnarFarneback's comment is equivalent, but he is correct in that this doesn't hold for
which as he correctly points out, is due to
The IEEE754-2008 spec has the following to say on the matter:
However ISO 10967-2 says that arcF (x, y) (which is their name for So basically, the two specs disagree. |
For what it's worth, the OS X libm (unlike openlibm and glibc) appears to follow the ISO 10967 spec:
|
And of course, this issue was discussed on the Octave lists as well |
I don't think we're realistically going to change the behaviour of |
Could we have a note in the docs for |
@StefanKarpinski I’m down to write a pull request to add this to the docs. Is there any particular format notices like this are usually put in, or can it just be appended? |
Use Lines 96 to 116 in e58bc72
|
One of these things is not like the other ones:
Arguably, these should all be
NaN
.The text was updated successfully, but these errors were encountered: