Commit 5fdbfe49 authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Merge pull request #2683 from KPilnacek/2133_exponentiation_of_int

Fix: Exponentiation of integer constants
parents c2de8efb 768b7489
...@@ -11745,6 +11745,12 @@ class PowNode(NumBinopNode): ...@@ -11745,6 +11745,12 @@ class PowNode(NumBinopNode):
error(self.pos, "got unexpected types for C power operator: %s, %s" % error(self.pos, "got unexpected types for C power operator: %s, %s" %
(self.operand1.type, self.operand2.type)) (self.operand1.type, self.operand2.type))
def compute_c_result_type(self, type1, type2):
c_result_type = super(PowNode, self).compute_c_result_type(type1, type2)
if isinstance(self.operand2.constant_result, _py_int_types) and self.operand2.constant_result < 0:
c_result_type = PyrexTypes.widest_numeric_type(c_result_type, PyrexTypes.c_double_type)
return c_result_type
def calculate_result_code(self): def calculate_result_code(self):
# Work around MSVC overloading ambiguity. # Work around MSVC overloading ambiguity.
def typecast(operand): def typecast(operand):
......
...@@ -5,7 +5,6 @@ Since Cython mixes C and Python semantics, some things may be a bit ...@@ -5,7 +5,6 @@ Since Cython mixes C and Python semantics, some things may be a bit
surprising or unintuitive. Work always goes on to make Cython more natural surprising or unintuitive. Work always goes on to make Cython more natural
for Python users, so this list may change in the future. for Python users, so this list may change in the future.
- ``10**-2 == 0``, instead of ``0.01`` like in Python.
- Given two typed ``int`` variables ``a`` and ``b``, ``a % b`` has the - Given two typed ``int`` variables ``a`` and ``b``, ``a % b`` has the
same sign as the second argument (following Python semantics) rather than same sign as the second argument (following Python semantics) rather than
having the same sign as the first (as in C). The C behavior can be having the same sign as the first (as in C). The C behavior can be
......
...@@ -136,6 +136,17 @@ def binop_mul_pow(): ...@@ -136,6 +136,17 @@ def binop_mul_pow():
return (mul_int, mul_large_int, pow_int, pow_large_int) return (mul_int, mul_large_int, pow_int, pow_large_int)
def binop_pow_negative():
"""
>>> print_big_ints(binop_pow_negative())
(4.018775720164609e-06, 8.020807320287816e-38, 0.1)
"""
pow_int = 12 ** -5
pow_large_int = 1234 ** -12
pow_expression_int = 10 ** (1-2)
return (pow_int, pow_large_int, pow_expression_int)
@cython.test_fail_if_path_exists( @cython.test_fail_if_path_exists(
"//SliceIndexNode", "//SliceIndexNode",
) )
......
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