diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index e79e845..fe9afe9 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -679,7 +679,7 @@ def div(a, b, f32=True): return a # this could be handled by using S32 but it's probably faster this way if (a < 0) ^ (b < 0): # signs differ - Python rounds towards -inf, we need rounding towards 0 - return - a//-b # that's -(a//-b) not (-a)//-b + return -(a//-b) return a//b ret = F32(ff(a)/ff(b), f32) if math.isnan(ret): # A NaN result gives a math error. diff --git a/testfuncs.py b/testfuncs.py index 7a10eb2..6f6653d 100644 --- a/testfuncs.py +++ b/testfuncs.py @@ -516,6 +516,15 @@ def do_tests(): shouldexcept('div(1, NaN)', ELSLMathError) shouldexcept('div(F32(1e40), F32(1e40))', ELSLMathError) shouldexcept('zstr("blah")', ELSLInvalidType) + test('div(1, 9)', 0) + test('div(8, 9)', 0) + test('div(9, 9)', 1) + test('div(-1,9)', 0) + test('div(-8,9)', 0) + test('div(-9,9)', -1) + test('div(1,-9)', 0) + test('div(8,-9)', 0) + test('div(9,-9)', -1) test(r'zstr(Key(u"xy\0zzy"))', Key(u'xy')) test('typecast(Infinity, unicode)', u'Infinity') test('typecast(NaN, unicode)', u'NaN')