-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Reciprocal of complex 0 and 1 / numpy.array(0+0j)
give different results
#17425
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
Comments
What does the IEEE-754 spec say is the correct result? |
I'm not sure what the spec itself says--evidently I'd have to pay for it to find out. I don't see any mention of complex numbers on the wikipedia page, so maybe it's not covered: https://en.wikipedia.org/wiki/IEEE_754 For what it's worth, my version of g++ claims to support IEEE-754 for floats, and I get |
Right, my question is about what
and
which suggests that the behavior of The implementation is here: numpy/numpy/core/src/umath/loops.c.src Lines 2853 to 2871 in f4a4ddd
|
C99 Annex G.5.1.4: the result from np.reciprocal is wrong, and the result from There's also something else strange here:
Python doesn't consider
so it seems there's deviation from C99 spec also there. (In C99, |
Ah, that makes sense. Thanks! I can try to make a PR to change |
This change makes `np.reciprocal(0+0j)` return the same result as `1 / np.array(0+0j)`. See numpy#17425
This change makes `np.reciprocal(0+0j)` return the same result as `1 / np.array(0+0j)`. See numpy#17425
This change makes `np.reciprocal(0+0j)` return the same result as `1 / np.array(0+0j)`. See numpy#17425
@pv, now it's a bug: python/cpython#119372. Here is a corresponding NumPy issue: #26560 |
numpy.reciprocal(a)
and1 / a
give different results witha = numpy.array(0 + 0j)
.reciprocal
givesnan+nanj
, and1 / a
givesinf+nanj
.It seems like neither of these results is correct, but I could certainly be wrong. I feel like the result in both cases should be
inf+0j
, since we getinf
when we use real numbers:1 / numpy.array(0.0)
andnumpy.reciprocal(numpy.array(0.0))
.Reproducing code example:
NumPy/Python version information:
OS
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
The text was updated successfully, but these errors were encountered: