Strings representing denormals no longer give 0 when cast to float

This annoyance and discrepancy with LSO was finally fixed by Linden Lab. The change has prompted some modifications to the test suite to accommodate for the new results. A further improvement has been to make these tests more friendly to be run in SL, making it easier to verify the results.

Fixes #17.

Reported by SaladDais@users.noreply.github.com - thanks!
This commit is contained in:
Sei Lisa 2022-05-17 13:39:31 +02:00
parent 7c630f4ce4
commit 281ff4d96a
8 changed files with 65 additions and 41 deletions

View file

@ -500,16 +500,25 @@ def InternalTypecast(val, out, InList, f32):
return 0.0
if match.group(1):
ret = float.fromhex(match.group(0))
elif match.group(2):
# (float)"-nan" produces NaN instead of Indet, even though
# (vector)"<-nan,0,0>" produces <Indet, 0., 0.>. Go figure.
ret = NaN
# The following is no longer true as of Server 2022-05-05.571557;
# exact date of change is unknown.
# (float)"-nan" returns -nan now.
#elif match.group(2):
# # (float)"-nan" produces NaN instead of Indet, even though
# # (vector)"<-nan,0,0>" produces <Indet, 0., 0.>. Go figure.
# ret = NaN
else:
ret = float(match.group(0))
if not lslcommon.LSO and abs(ret) < 1.1754943157898259e-38:
# Mono doesn't return denormals when using (float)"val"
# (but it returns them when using (vector)"<val,...>")
ret = 0.0
# The following is no longer true as of Server 2022-05-05.571557;
# exact date of change is unknown.
# Thanks to SaladDais@users.noreply.github.com for noticing.
# Note that if the code needs to be resurrected, the sign needs
# to be verified for the case (float)"-0.0"; we can no longer
# check how it worked before.
#if not lslcommon.LSO and abs(ret) < 1.1754943157898259e-38:
# # Mono doesn't return denormals when using (float)"val"
# # (but it returns them when using (vector)"<val,...>")
# ret = 0.0
return F32(ret, f32)
if out == int:
match = int_re.search(val)

View file

@ -27,13 +27,12 @@
, (float)"-3.14e+0a"
, (float)"--3.14e+0a"
, (float)"0x3.14p+0a"
, (float)"1.1754944e-38"
, (float)"1.1754943e-38"
, (float)"1.1754942e-38"
, (float)"1.1754943157898258346e-38"
, (float)"1.17549431578982583459e-38"
// Known Mismatch:
//, (float)"1.175494315789825834599e-38" // should give 0 but it fails
, (float)"1.1754944e-38"*85070591730234615865843651857942052864.*16777216.
, (float)"1.1754943e-38"*85070591730234615865843651857942052864.*16777216.
, (float)"1.1754942e-38"*85070591730234615865843651857942052864.*16777216.
, (float)"1.1754943157898258346e-38"*85070591730234615865843651857942052864.*16777216.
, (float)"1.17549431578982583459e-38"*85070591730234615865843651857942052864.*16777216.
, (float)"1.175494315789825834599e-38"*85070591730234615865843651857942052864.*16777216.
, (vector)"<5.31,7.13,0x9.99"
, (vector)"<5.31, 7.13, 0x9.99>"
, (vector)"<5.31 , 7.13 , 0x9.99>"
@ -125,13 +124,14 @@
, (string)(1e39*0)
, llList2CSV([1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13,1e14,
1e15,1e16,1e17,1e18,1e19,1e20,1e21,1e22,1e23,1e24,1e25,1e26,1e27,
1e28,1e29,1e30,1e31,1e32,1e33,1e34,1e35,1e36,1e37,1e38])
1e28,1e29,1e30,1e31,1e32,1e33,1e34])
, llList2CSV([1e35,1e36,1e37,1e38])
, llList2CSV((list)<(float)"NaN", 1e40*0, 1e40, -1e40>)
, llList2CSV((list)"str")
, (string)[1,3.14,(key)"blah",<1.,0.,0.,0.>]
, llSin(-2147483648)
, llSin(2147483647)
, llSin(2147483647.0)
, llSin(-2147483648)*128
, llSin(2147483647)*128
, llSin(2147483647.0)*128
, 2147483647 * 1.0 * 2
, 3 * 1.0 / 2
, 3 / 2

View file

@ -27,11 +27,12 @@
, -3.14
, 0.
, 3.078125
, 1.1754943e-38
, 0.
, 0.
, 1.1754943e-38
, 0.
, 16777216.
, 16777216.
, 16777214.
, 16777216.
, 16777216.
, 16777216.
, <5.31, 7.13, 9.597656>
, <5.31, 7.13, 9.597656>
, <0., 0., 0.>
@ -121,13 +122,14 @@
, "Infinity"
, "-Infinity"
, "NaN"
, "1.000000, 10.000000, 100.000000, 1000.000000, 10000.000000, 100000.000000, 1000000.000000, 10000000.000000, 100000000.000000, 1000000000.000000, 10000000000.000000, 99999997952.000000, 999999995904.000000, 9999999827968.000000, 100000000376832.000000, 999999986991104.000000, 10000000272564224.000000, 99999998430674944.000000, 999999984306749440.000000, 9999999980506447872.000000, 100000002004087734272.000000, 1000000020040877342720.000000, 9999999778196308361216.000000, 99999997781963083612160.000000, 1000000013848427855085568.000000, 9999999562023526247432192.000000, 100000002537764290115403776.000000, 999999988484154753734934528.000000, 9999999442119689768320106496.000000, 100000001504746621987668885504.000000, 1000000015047466219876688855040.000000, 9999999848243207295109594873856.000000, 100000003318135351409612647563264.000000, 999999994495727286427992885035008.000000, 9999999790214767953607394487959552.000000, 100000004091847875962975319375216640.000000, 999999961690316245365415600208216064.000000, 9999999933815812510711506376257961984.000000, 99999996802856924650656260769173209088.000000"
, "1.000000, 10.000000, 100.000000, 1000.000000, 10000.000000, 100000.000000, 1000000.000000, 10000000.000000, 100000000.000000, 1000000000.000000, 10000000000.000000, 99999997952.000000, 999999995904.000000, 9999999827968.000000, 100000000376832.000000, 999999986991104.000000, 10000000272564224.000000, 99999998430674944.000000, 999999984306749440.000000, 9999999980506447872.000000, 100000002004087734272.000000, 1000000020040877342720.000000, 9999999778196308361216.000000, 99999997781963083612160.000000, 1000000013848427855085568.000000, 9999999562023526247432192.000000, 100000002537764290115403776.000000, 999999988484154753734934528.000000, 9999999442119689768320106496.000000, 100000001504746621987668885504.000000, 1000000015047466219876688855040.000000, 9999999848243207295109594873856.000000, 100000003318135351409612647563264.000000, 999999994495727286427992885035008.000000, 9999999790214767953607394487959552.000000"
, "100000004091847875962975319375216640.000000, 999999961690316245365415600208216064.000000, 9999999933815812510711506376257961984.000000, 99999996802856924650656260769173209088.000000"
, "<nan, -nan, inf, -inf>"
, "str"
, "13.140000blah<1.000000, 0.000000, 0.000000, 0.000000>"
, 0.9713102
, -0.9713102
, -0.9713102
, 124.327705
, -124.327705
, -124.327705
, 4294967296.
, 1.5
, 1

View file

@ -0,0 +1,12 @@
// Test cases based on bug report by SaladDais@users.noreply.github.com;
// see https://github.com/Sei-Lisa/LSL-PyOptimizer/issues/17
// The first two cases are a change of behaviour in Mono, which used to return
// zero when a string that represented a denormal was converted to float (LSO
// did not have this problem).
// The last two cases are a screwup on the author's side.
[ (string)((float)"-0.0")
, (string)(1.4e-45 == (float)"1.4e-45")
, (string)0.00000000000001
, (string)-0.00000000000001
]

View file

@ -0,0 +1 @@
["-0.000000", "1", "0.000000", "0.000000"]

View file

@ -30,10 +30,10 @@
, (vector)"<nan(1),nan,nano>"
, (string)<0,0,0>
, (string)[<0,0,0>]
, (list)<(float)"nan", 2, 3>
, (list)[<(float)"nan", 2, 3>]
, (float)"1e-38"
, (vector)"<1e-38,0,0>"
, llList2Vector((list)<(float)"nan", 2, 3>, 0)
, llList2Vector((list)[<(float)"nan", 2, 3>], 0)
, (float)"1e-38"*85070591730234615865843651857942052864.*16777216.
, (vector)"<1e-38,0,0>"*85070591730234615865843651857942052864.*16777216.
, 1e40/1
, 1e40-1e40
, (1e40*0)*(1e40*0)

View file

@ -11,8 +11,8 @@
, 1e20
, "nan"
, "-nan"
, "nan"
, "nan"
, "-nan"
, "-nan"
, "0.000000"
, -0.
, 0.
@ -30,10 +30,10 @@
, <0., 0., 0.>
, "<0.00000, 0.00000, 0.00000>"
, "<0.000000, 0.000000, 0.000000>"
, [<(-1e40*0), 2., 3.>]
, [<(-1e40*0), 2., 3.>]
, 0.
, <1e-38, 0., 0.>
, <(-1e40*0), 2., 3.>
, <(-1e40*0), 2., 3.>
, 14272476.
, <14272476., 0., 0.>
, 1e40
, (1e40*0)
, (1e40*0)

View file

@ -15,8 +15,8 @@ default
, (1e40*0)
, "nan"
, "-nan"
, "nan"
, "nan"
, "-nan"
, "-nan"
, "0.000000"
, (-(float)0)
, ((float)0)
@ -32,7 +32,7 @@ default
, <((float)0), ((float)0), ((float)0)>
, <(-1e40*0), (-1e40*0), (-1e40*0)>
, <((float)0), ((float)0), ((float)0)>
, ((float)0)
, 1e-38
, <1e-38, ((float)0), ((float)0)>
, 1e40
, (1e40*0)