Commit 1e0ed76a authored by Stefan Behnel's avatar Stefan Behnel

prevent 2**N optimisation from breaking 2.0**N

parent 52099c3e
......@@ -9555,6 +9555,7 @@ class PowNode(NumBinopNode):
def py_operation_function(self, code):
if (self.type.is_pyobject and
self.operand1.constant_result == 2 and
isinstance(self.operand1.constant_result, (int, long)) and
self.operand2.type is py_object_type):
code.globalstate.use_utility_code(UtilityCode.load_cached('PyNumberPow2', 'Optimize.c'))
if self.inplace:
......
......@@ -91,4 +91,7 @@ def optimised_pow2(n):
Traceback (most recent call last):
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'str'
"""
if isinstance(n, (int, long)) and 0 <= n < 1000:
assert isinstance(2.0 ** n, float), 'float %s' % n
assert isinstance(2 ** n, (int, long)), 'int %s' % n
return 2 ** n
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment