8000 pow() with negative newint returns always 0 · Issue #568 · PythonCharmers/python-future · GitHub
[go: up one dir, main page]

Skip to content

pow() with negative newint returns always 0 #568

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

Closed
pieleric opened this issue Jul 1, 2020 · 2 comments
Closed

pow() with negative newint returns always 0 #568

pieleric opened this issue Jul 1, 2020 · 2 comments

Comments

@pieleric
Copy link
pieleric commented Jul 1, 2020

On Python 2 & 3:

10 ** -9 == 10 ** int(-9) == pow(10, -9) == 10e-9

However, with newint, any negative power still returns a newint, which becomes 0:

from future.builtins import int as newint
pow(10, newint(-9)) == 0

In such case, __pow__() should return a float.

@pieleric
Copy link
Author
pieleric commented Jul 1, 2020

BTW, I've looked quickly at the code in future/types/newint.py and it seems that something similar to __mul__() works:

    def __rpow__(self, other):
        value = super(newint, self).__rpow__(other)
        if isint(value):
            return newint(value)
        elif value is NotImplemented:
            return other ** long(self)
        return value

@edschofield
6E34
Copy link
Contributor

Thanks @pieleric . I've added your fix in master.

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

No branches or pull requests

2 participants
0