diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index f9bdccf..2a987e2 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -669,8 +669,6 @@ def div(a, b, f32=True): if b == 0: raise ELSLMathError if ta in (int, float): - if math.isnan(a): # NaN/anything gives math error - raise ELSLMathError if ta == int and tb == int: # special case if a == -2147483648 and b == -1: @@ -679,7 +677,10 @@ def div(a, b, f32=True): # 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 F32(ff(a)/ff(b), f32) + ret = F32(ff(a)/ff(b), f32) + if math.isnan(res): # A NaN result gives a math error. + raise ELSLMathError + return ret if ta == Vector: a = v2f(a) b = ff(b) diff --git a/testfuncs.py b/testfuncs.py index 2a3920e..8eb17fe 100644 --- a/testfuncs.py +++ b/testfuncs.py @@ -493,6 +493,9 @@ def do_tests(): shouldexcept('div(1.0, 0.0)', ELSLMathError) shouldexcept('div(1, 0)', ELSLMathError) + shouldexcept('div(NaN, 1)', ELSLMathError) + shouldexcept('div(1, NaN)', ELSLMathError) + shouldexcept('div(F32(1e40), F32(1e40))', ELSLMathError) shouldexcept('zstr("blah")', ELSLInvalidType) test(r'zstr(Key(u"xy\0zzy"))', Key(u'xy')) test('typecast(Infinity, unicode)', u'Infinity')