Skip to content

pow() with negative newint returns always 0 #568

Closed

Description

@pieleric

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.

Activity

  1. pieleric commented on Jul 1, 2020

    @pieleric
    Author

    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
  2. edschofield commented on Feb 21, 2024

    @edschofield
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions