Skip to content
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

BUG: scalar integer negative powers gave wrong results. #7447

Merged
merged 1 commit into from
Mar 22, 2016

Conversation

ewmoore
Copy link
Contributor

@ewmoore ewmoore commented Mar 22, 2016

np.int8(4)**np.int8(-4) gave inf. Since we return a float or
double for these cases, just call those power routines. This
prevents integer overflow from resulting in a divide by zero and
the old nonsense result.

np.int8(4)**np.int8(-4) gave inf.  Since we result a float or
double for these cases, just call those power routines. This
prevents integer overflow from resulting in a divide by zero and
the old nonsense result.
@ewmoore
Copy link
Contributor Author

ewmoore commented Mar 22, 2016

CI failure is curl failing to download python 3.5. So unrelated to these changes.

@charris
Copy link
Member

charris commented Mar 22, 2016

Hmm, arrays just convert inf to 0, which is the standard cast for integers.

In [3]: array(4, dtype=int8) ** -4
Out[3]: 0

also integer result rather than float. So this is a case where numpy scalars behave differently from array scalars. Apart from that inconsistency this looks good to me, but I wonder if we want to stick with it in the long run. Perhaps a note to the mailing list would elicit some discussion.

@charris
Copy link
Member

charris commented Mar 22, 2016

OTOH, it makes it consistent with Python

In [1]: 2 ** -2
Out[1]: 0.25

So let's put this in. The inconsistency is still a bit bothersome.

@charris charris merged commit b479671 into numpy:master Mar 22, 2016
@charris
Copy link
Member

charris commented Mar 22, 2016

Thanks @ewmoore .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants