Skip to content

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

Merged
charris merged 1 commit into
numpy:masterfrom
ewmoore:scalar_neg_power
Mar 22, 2016
Merged

charris merged 1 commit into
numpy:masterfrom
ewmoore:scalar_neg_power

Conversation

@ewmoore

@ewmoore ewmoore commented Mar 22, 2016

Copy link
Copy Markdown
Contributor

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

ewmoore commented Mar 22, 2016

Copy link
Copy Markdown
Contributor Author

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

@charris

charris commented Mar 22, 2016

Copy link
Copy Markdown
Member

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

charris commented Mar 22, 2016

Copy link
Copy Markdown
Member

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

charris commented Mar 22, 2016

Copy link
Copy Markdown
Member

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.

2 participants