Improve behaviour of llAtan2 to make it closer to SL's.

Especially regarding NaN inputs. Add regression tests.
This commit is contained in:
Sei Lisa 2016-12-22 01:08:07 +01:00
parent 159fae90bf
commit 14488ddd92
2 changed files with 32 additions and 0 deletions

View file

@ -835,6 +835,14 @@ def llAsin(f):
def llAtan2(y, x): def llAtan2(y, x):
assert isfloat(y) assert isfloat(y)
assert isfloat(x) 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)) return F32(math.atan2(y, x))
def llAxes2Rot(fwd, left, up): def llAxes2Rot(fwd, left, up):

View file

@ -880,6 +880,30 @@ def do_tests():
test('llAsin(2.0)', NaN) test('llAsin(2.0)', NaN)
test('llAcos(2.0)', NaN) test('llAcos(2.0)', NaN)
test('llAtan2(0.0, 0.0)', 0.0) 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 # nan and -nan in llList2CSV
test('llList2CSV([llSin(F32(4e38))])', u'-nan') test('llList2CSV([llSin(F32(4e38))])', u'-nan')