Commit 5de4e6bd authored by Robert Bradshaw's avatar Robert Bradshaw

More overflow testing.

parent 9d493a05
......@@ -106,12 +106,12 @@ def test_mul(INT a, INT b):
return int(a * b)
@cython.overflowcheck(True)
def test_nested(INT a, INT b, INT c):
def test_nested_add(INT a, INT b, INT c):
"""
>>> test_nested(1, 2, 3)
>>> test_nested_add(1, 2, 3)
6
>>> expect_overflow(test_nested, half + 1, half + 1, half + 1)
>>> expect_overflow(test_nested, half - 1, half - 1, half - 1)
>>> expect_overflow(test_nested_add, half + 1, half + 1, half + 1)
>>> expect_overflow(test_nested_add, half - 1, half - 1, half - 1)
"""
return int(a + b + c)
......@@ -154,6 +154,25 @@ cdef INT called(INT value):
print("called(%s)" % format(value))
return value
@cython.overflowcheck(True)
def test_nested(INT a, INT b, INT c, INT d):
"""
>>> test_nested_func(1, 2, 3)
called(5)
6
>>> expect_overflow(test_nested, half, half, 1, 1)
>>> expect_overflow(test_nested, half, 1, half, half)
>>> expect_overflow(test_nested, half, 2, half, 2)
>>> print(format(test_nested(half, 2, 0, 1)))
half + half - 0
>>> print(format(test_nested(1, 0, half, 2)))
half + half - 0
>>> print(format(test_nested(half, 1, 1, half)))
half + half - 0
"""
return int(a * b + c * d)
@cython.overflowcheck(True)
def test_nested_func(INT a, INT b, INT c):
"""
......@@ -166,7 +185,6 @@ def test_nested_func(INT a, INT b, INT c):
>>> print(format(test_nested_func(1, half - 1, half - 1)))
called(half + half - 2)
half + half - 1
>>>
"""
return int(a + called(b + c))
......
# cython: overflowcheck.fold = True
ctypedef int INT
include "overflow_check.pxi"
# cython: overflowcheck.fold = False
ctypedef long long INT
include "overflow_check.pxi"
# cython: overflowcheck.fold = False
ctypedef unsigned int INT
include "overflow_check.pxi"
# cython: overflowcheck.fold = True
ctypedef unsigned long long INT
include "overflow_check.pxi"
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