From 23e71354c585941d3227dbf56ec453129845821d Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 1 Feb 2025 12:00:18 +0100 Subject: [PATCH] llModPow precision has been fixed and the delay removed --- fndata.txt | 2 +- lslopt/lslbasefuncs.py | 10 +--- run-tests.py | 2 - unit_tests/expr.suite/llmodpow.out | 62 ++++++++++---------- unit_tests/regression.suite/side-effects.lsl | 1 - unit_tests/regression.suite/side-effects.out | 1 - 6 files changed, 34 insertions(+), 44 deletions(-) diff --git a/fndata.txt b/fndata.txt index c09af73..3359f9f 100644 --- a/fndata.txt +++ b/fndata.txt @@ -1144,7 +1144,7 @@ void llMessageLinked(integer linknum, integer num, string str, key id) void llMinEventDelay(float delay) integer llModPow(integer a, integer b, integer c) -- delay 1.0 +- SEF void llModifyLand(integer action, integer brush) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 05c4847..841e0cc 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -1797,15 +1797,9 @@ def llModPow(base, exp, mod): base = fi(base) exp = fi(exp) mod = fi(mod) - if not lslcommon.IsCalc: - # This function has a delay, therefore it's not safe to compute it - # unless in calculator mode. - raise ELSLCantCompute # With some luck, this works fully with native ints on 64 bit machines. if mod in (0, 1): return 0 - if exp == 0: - return 1 # Convert all numbers to unsigned base &= 0xFFFFFFFF exp &= 0xFFFFFFFF @@ -1814,11 +1808,11 @@ def llModPow(base, exp, mod): ret = 1 while True: if exp & 1: - ret = ((ret * prod) & 0xFFFFFFFF) % mod + ret = ((ret * prod) % mod) & 0xFFFFFFFF exp = exp >> 1 if exp == 0: break - prod = ((prod * prod) & 0xFFFFFFFF) % mod + prod = ((prod * prod) % mod) & 0xFFFFFFFF return S32(ret) diff --git a/run-tests.py b/run-tests.py index b680aea..2d40b2f 100755 --- a/run-tests.py +++ b/run-tests.py @@ -541,8 +541,6 @@ class UnitTestCoverage(UnitTestCase): # The SEF table prevents this assertion from being reachable via script. self.assertRaises(lslfuncs.ELSLCantCompute, lslfuncs.llXorBase64Strings, u"AABA", u"AABA") - self.assertRaises(lslfuncs.ELSLCantCompute, lslfuncs.llModPow, - 3, 5, 7) # Check invalid type in llGetListEntryType self.assertRaises(lslfuncs.ELSLInvalidType, lslfuncs.llGetListEntryType, [b'a'], 0) diff --git a/unit_tests/expr.suite/llmodpow.out b/unit_tests/expr.suite/llmodpow.out index b465d92..965f9ab 100644 --- a/unit_tests/expr.suite/llmodpow.out +++ b/unit_tests/expr.suite/llmodpow.out @@ -1,29 +1,29 @@ [ 0 , 34 , 196607 -, 131071 +, 65541 , 1769445 -, 1572843 -, 1966047 +, 1376283 +, 2162607 , 142 -, 1966045 +, 2031553 , 1769445 -, 1572845 -, 98302 -, 216275 -, 876887 -, 230066 +, 1507337 +, 65538 +, 229363 +, 884663 +, 253138 , 54345 , 161343 -, 346875 -, 690307 -, 139309 -, 146813 -, 389875 -, 301047 -, 36839 -, 115989 -, 83681 +, 713029 +, 567153 +, 209161 +, 38513 +, 486049 +, 101347 +, 377011 +, 130123 +, 3151 , 23425 , 64819 , 66641 @@ -33,28 +33,28 @@ , 112231 , 54343 , 84733 -, 49913 -, 85865 -, 2379 +, 118153 +, 155593 +, 100545 , 78307 , 99163 -, 254367 -, 90487 +, 21663 +, 134302 , 19663 , 29663 -, 49367 -, 164967 -, 137017 +, 215863 +, 118663 +, 256033 , 64183 , 237863 -, 162132 -, 85797 +, 104023 +, 77287 , 157054 , 1416 , 257065 -, 85797 -, 251271 -, 251271 +, 77287 +, 227313 +, 42471 , 0 , 0 , 0 diff --git a/unit_tests/regression.suite/side-effects.lsl b/unit_tests/regression.suite/side-effects.lsl index 6a48df2..0951ac7 100644 --- a/unit_tests/regression.suite/side-effects.lsl +++ b/unit_tests/regression.suite/side-effects.lsl @@ -1,5 +1,4 @@ // Check that the LSL functions with side effects are not computed. default{timer(){ - llModPow(4, 1, 2); llXorBase64Strings("AB", "CD"); }} diff --git a/unit_tests/regression.suite/side-effects.out b/unit_tests/regression.suite/side-effects.out index f2a8c9c..0eb3abe 100644 --- a/unit_tests/regression.suite/side-effects.out +++ b/unit_tests/regression.suite/side-effects.out @@ -2,7 +2,6 @@ default { timer() { - llModPow(4, 1, 2); llXorBase64Strings("AB", "CD"); } }