From 14488ddd92df383982f67120c186baaf74ceace9 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 22 Dec 2016 01:08:07 +0100 Subject: [PATCH] Improve behaviour of llAtan2 to make it closer to SL's. Especially regarding NaN inputs. Add regression tests. --- lslopt/lslbasefuncs.py | 8 ++++++++ testfuncs.py | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 87cb3c7..459be81 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -835,6 +835,14 @@ def llAsin(f): def llAtan2(y, x): assert isfloat(y) assert isfloat(x) + if math.isnan(x) and math.isnan(y): + if math.copysign(1, x) == -1 and math.copysign(1, y) == -1: + return -NaN + return NaN + elif math.isnan(x): + return x + elif math.isnan(y): + return y return F32(math.atan2(y, x)) def llAxes2Rot(fwd, left, up): diff --git a/testfuncs.py b/testfuncs.py index 63d1c3c..441b907 100644 --- a/testfuncs.py +++ b/testfuncs.py @@ -880,6 +880,30 @@ def do_tests(): test('llAsin(2.0)', NaN) test('llAcos(2.0)', NaN) test('llAtan2(0.0, 0.0)', 0.0) + test('llAtan2(-0.0, -1.0)', F32(-math.pi)) + test('llAtan2(0.0, -1.0)', F32(math.pi)) + test('llAtan2(-Infinity, -1.0)', F32(-math.pi/2)) + test('llAtan2(Infinity, -1.0)', F32(math.pi/2)) + test('llAtan2(NaN, -1.0)', NaN) + test('llAtan2(NaN, -0.0)', NaN) + test('llAtan2(NaN, 0.0)', NaN) + test('llAtan2(NaN, 1.0)', NaN) + test('llAtan2(-NaN, -1.0)', -NaN) + test('llAtan2(-NaN, -0.0)', -NaN) + test('llAtan2(-NaN, 0.0)', -NaN) + test('llAtan2(-NaN, 1.0)', -NaN) + test('llAtan2(-1.0, NaN)', NaN) + test('llAtan2(-0.0, NaN)', NaN) + test('llAtan2( 0.0, NaN)', NaN) + test('llAtan2( 1.0, NaN)', NaN) + test('llAtan2(-1.0, -NaN)', -NaN) + test('llAtan2(-0.0, -NaN)', -NaN) + test('llAtan2( 0.0, -NaN)', -NaN) + test('llAtan2( 1.0, -NaN)', -NaN) + test('llAtan2(-NaN, -NaN)', -NaN) + test('llAtan2(-NaN, NaN)', NaN) + test('llAtan2(NaN, -NaN)', NaN) + test('llAtan2(NaN, NaN)', NaN) # nan and -nan in llList2CSV test('llList2CSV([llSin(F32(4e38))])', u'-nan')