Commit 0e658851 authored by Robert Bradshaw's avatar Robert Bradshaw

Test (and fix) corner case in C division

parent 02e4e0a4
......@@ -5717,7 +5717,7 @@ static INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s, %(type)s); /* proto */
impl="""
static INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s a, %(type)s b) {
%(type)s res = fmod%(math_h_modifier)s(a, b);
res += ((res < 0) ^ (b < 0)) * b;
res += ((res != 0) & ((a < 0) ^ (b < 0))) * b;
return res;
}
""")
......@@ -5728,9 +5728,9 @@ static INLINE %(type)s __Pyx_div_%(type_name)s(%(type)s, %(type)s); /* proto */
""",
impl="""
static INLINE %(type)s __Pyx_div_%(type_name)s(%(type)s a, %(type)s b) {
%(type)s res = a / b;
res -= (res < 0);
return res;
%(type)s q = a / b;
q -= ((q*b != a) & ((a < 0) ^ (b < 0)));
return q;
}
""")
......
......@@ -27,6 +27,10 @@ True
>>> [test_cdiv_cmod(a, b) for a, b in v]
[(1, 7), (-1, -7), (1, -7), (-1, 7)]
>>> all([mod_int_py(a,b) == a % b for a in range(-10, 10) for b in range(-10, 10) if b != 0])
True
>>> all([div_int_py(a,b) == a // b for a in range(-10, 10) for b in range(-10, 10) if b != 0])
True
>>> def simple_warn(msg, *args): print msg
>>> import warnings
......
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