Add more NaN-related tests, make NaN checking stricter

reallyequal: Compare the sign of NaN when checking if the args are NaN.

Tests added:

- llAsin, llAcos with out-of-range argument produces NaN.
- llAtan2 with (0, 0) produces 0.
- Sign of NaN is not distinguished in lists, even if NaN compares equal to NaN.
This commit is contained in:
Sei Lisa 2016-05-15 18:25:13 +02:00
parent 23b27bd3af
commit b5dc38e9e6

View file

@ -51,7 +51,9 @@ def reallyequal(actual, expected, tol):
if actual == 0.0:
return repr(actual) == repr(expected)
elif math.isnan(actual):
return math.isnan(expected)
# This compares the sign of NaN as well
from struct import pack
return pack('>f', actual) == pack('>f', expected)
return abs(actual - expected) <= tol
# Deal with tuples and lists (item-by-item, recursively)
@ -830,6 +832,9 @@ def do_tests():
test('llTan(F32(math.pi))', F('0x1.777A5Cp-24'))
test('llTan(F32(math.pi*.5))', -22877330.)
test('llTan(F("0x1.921FB4p0"))', 13245400.)
test('llAsin(2.0)', NaN)
test('llAcos(2.0)', NaN)
test('llAtan2(0.0, 0.0)', 0.0)
# nan and -nan in llList2CSV
test('llList2CSV([llSin(F32(4e38))])', u'-nan')
@ -1023,7 +1028,7 @@ def do_tests():
test('llModPow(41, 1, 17)', 7)
test('llListFindList([], [])', 0)
test('llListFindList([NaN], [NaN])', 0) # I swear
test('llListFindList([NaN, -NaN], [-NaN, NaN])', 0) # I swear
test('llListFindList([-0.], [0.])', 0) # Really.
test('llListFindList([0.], [-0.])', 0) # Yes.
test('llListFindList([1, NaN, 1., NaN], [1., NaN])', 2)