From bf505220acb93301ec69af8b361fc3bd03855ea6 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 7 May 2024 00:07:17 +0200 Subject: [PATCH] Calculate llFrand's min and max when possible --- lslopt/lslfuncopt.py | 6 ++++++ unit_tests/expr.suite/llfrand-1.lsl | 1 + unit_tests/expr.suite/llfrand-2.lsl | 1 + unit_tests/expr.suite/llfrand-3.lsl | 23 +++++++++++++++++++++++ unit_tests/expr.suite/llfrand-3.out | 3 +++ unit_tests/regression.suite/llfrand.lsl | 20 ++++++++++++++++++++ unit_tests/regression.suite/llfrand.out | 24 ++++++++++++++++++++++++ unit_tests/regression.suite/llfrand.run | 1 + 8 files changed, 79 insertions(+) create mode 100644 unit_tests/expr.suite/llfrand-3.lsl create mode 100644 unit_tests/expr.suite/llfrand-3.out create mode 100644 unit_tests/regression.suite/llfrand.lsl create mode 100644 unit_tests/regression.suite/llfrand.out create mode 100644 unit_tests/regression.suite/llfrand.run diff --git a/lslopt/lslfuncopt.py b/lslopt/lslfuncopt.py index e7bc4c2..4c71c53 100644 --- a/lslopt/lslfuncopt.py +++ b/lslopt/lslfuncopt.py @@ -528,6 +528,12 @@ def OptimizeFunc(self, parent, index): parent[index] = nr(nt='CONST', t='list', value=[], SEF=True) return + if name == 'llFrand' and child[0].nt == 'CONST': + # We can set a range when the input is a constant + value = child[0].value + node.min = lslfuncs.F32(min(value, 0) * 0.9999999403953552) + node.max = lslfuncs.F32(max(value, 0) * 0.9999999403953552) + def FuncOptSetup(): # Patch the default values list for LSO if lslcommon.LSO: diff --git a/unit_tests/expr.suite/llfrand-1.lsl b/unit_tests/expr.suite/llfrand-1.lsl index 6b00c35..9cad062 100644 --- a/unit_tests/expr.suite/llfrand-1.lsl +++ b/unit_tests/expr.suite/llfrand-1.lsl @@ -1,3 +1,4 @@ +// Test that there's at least one 7-digit number [ llFrand(16777216) , llFrand(16777216) , llFrand(16777216) diff --git a/unit_tests/expr.suite/llfrand-2.lsl b/unit_tests/expr.suite/llfrand-2.lsl index 6b00c35..b1873ba 100644 --- a/unit_tests/expr.suite/llfrand-2.lsl +++ b/unit_tests/expr.suite/llfrand-2.lsl @@ -1,3 +1,4 @@ +// Test that there's at least one 8-digit number [ llFrand(16777216) , llFrand(16777216) , llFrand(16777216) diff --git a/unit_tests/expr.suite/llfrand-3.lsl b/unit_tests/expr.suite/llfrand-3.lsl new file mode 100644 index 0000000..7b36c3f --- /dev/null +++ b/unit_tests/expr.suite/llfrand-3.lsl @@ -0,0 +1,23 @@ +[ llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +, llFrand(-5) +, llFrand(-5.0) +] diff --git a/unit_tests/expr.suite/llfrand-3.out b/unit_tests/expr.suite/llfrand-3.out new file mode 100644 index 0000000..ece9add --- /dev/null +++ b/unit_tests/expr.suite/llfrand-3.out @@ -0,0 +1,3 @@ +REGEX +(?:[\[,] -[0-4]\.[0-9]* +){22}\] \ No newline at end of file diff --git a/unit_tests/regression.suite/llfrand.lsl b/unit_tests/regression.suite/llfrand.lsl new file mode 100644 index 0000000..4f577a6 --- /dev/null +++ b/unit_tests/regression.suite/llfrand.lsl @@ -0,0 +1,20 @@ +default { timer() { + llParticleSystem( + [ llFrand(-5) + , llFrand(-5) > -5 + , llFrand(-5) <= 0 + , llFrand(-5) > 0 + , llFrand(-5.) + , llFrand(-16777216) + , llFrand(-16777216.) + , llFrand(5) + , llFrand(5) < 5 + , llFrand(5) >= 0 + , llFrand(5) < 0 + , llFrand(5.) + , llFrand(16777216) + , llFrand(16777216.) + , llFrand(33554433) + , llFrand(33554433.) + ]); +}} diff --git a/unit_tests/regression.suite/llfrand.out b/unit_tests/regression.suite/llfrand.out new file mode 100644 index 0000000..19ae702 --- /dev/null +++ b/unit_tests/regression.suite/llfrand.out @@ -0,0 +1,24 @@ +default +{ + timer() + { + llParticleSystem( + [ llFrand(((integer)-5)) + , 1 + , 1 + , 0 + , llFrand(((float)-5)) + , llFrand(((integer)-16777216)) + , llFrand(((float)-16777216)) + , llFrand(5) + , 1 + , 1 + , 0 + , llFrand(((float)5)) + , llFrand(16777216) + , llFrand(((float)16777216)) + , llFrand(33554433) + , llFrand(((float)33554432)) + ]); + } +} diff --git a/unit_tests/regression.suite/llfrand.run b/unit_tests/regression.suite/llfrand.run new file mode 100644 index 0000000..6e609ff --- /dev/null +++ b/unit_tests/regression.suite/llfrand.run @@ -0,0 +1 @@ +main.py -O -listadd - \ No newline at end of file