Commit graph

102 commits

Author SHA1 Message Date
Sei Lisa
f243f3a3c1 New copyright year 2019-01-01 22:54:34 +01:00
Sei Lisa
c62773ad3f Refine the denormal check for Mono
The threshold for returning 0 for denormals is slightly different.
2018-05-09 19:04:09 +02:00
Sei Lisa
091f06cccc Fix threshold value for denormal to be taken as 0
(float)"1.1754944e-38" is != 0
(float)"1.1754943e-38" is == 0

Yet, 1.1754944e-38 == 1.1754943e-38.

The fix is to perform the operations as doubles, and convert to F32 *after* comparing the denormal range.
2018-04-27 23:44:27 +02:00
Sei Lisa
d0d6d6744b Bump copyright year
The help text in main.py was still at 2015. Oops.
2018-03-23 16:36:45 +01:00
Sei Lisa
fd815f0bdb Fix compare and llListSort for LSO.
In LSO, they compare UTF-8 bytes, not Unicode codepoints.
2017-10-21 12:32:41 +02:00
Sei Lisa
028b244a9e lslbasefuncs: Rewrite some things in a different way.
Also some formatting changes. No functionality changes.
2017-10-18 15:20:19 +02:00
Sei Lisa
e051d49338 llAsin and llAcos return indet for indet input. 2017-10-18 02:42:58 +02:00
Sei Lisa
f77590df67 Fix sign of NaN*Indet and NaN/Indet.
In Python, NaN*Indet in any order returns the second operand, and NaN/Indet in any order returns the first operand. LSL consistently returns NaN in all cases.
2017-10-14 15:16:18 +02:00
Sei Lisa
0dc8629007 Raise ELSLInvalidType on invalid type passed to cond(). 2017-10-14 14:17:42 +02:00
Sei Lisa
6faa7816e6 Change ELSLInvalidType to ELSLTypeMismatch where appropriate.
The force type functions ff(), fi(), fs()... should normally trigger ELSLTypeMismatch when the input is not in the expected range of types, rather than ELSLInvalidType, which is reserved for the case where the type is not a valid LSL type.
2017-10-14 11:33:18 +02:00
Sei Lisa
9e7a5d1cdf Change strategy for the checking of function input types.
Rather than assert that the types are correct, use the force type functions on the parameters:
ff, fk, fs, q2f, v2f, and the new fi, fl.

These functions have also been modified to ensure that the input type supports an implicit typecast to the target type and perform it, or emit ELSLInvalidType otherwise, rather than an assertion failure. fl in particular returns the original list if it isn't changed, or a copy if it is.

A couple bugs were found in testfuncs.py as a result, which have been fixed as well. A test has been added to ensure that the exception that caught these bugs remains in place.

The isxxxx functions are no longer necessary, so they are removed. Same goes for the painful cast handling process in foldconst, which was basically performing this task, and not necessarily well.

This approach is much more robust and should have been used since the beginning, but I didn't figure it out then.
2017-10-12 17:16:16 +02:00
Sei Lisa
b97b2a78e8 Fix return value for some detection functions.
When the index is good, on non-touch functions:
 - llDetectedTouchFace returns -1.
 - llDetectedTouchST and llDetectedTouchUV return TOUCH_INVALID_TEXCOORD.

We were returning 0 and ZERO_VECTOR respectively.
2017-08-30 19:23:38 +02:00
Sei Lisa
fe574bb462 Bump copyright year.
'bout time.
2017-08-09 19:45:46 +02:00
Sei Lisa
9a1421aeeb Fix (float)"nan" and (vector)"<nan,-nan..." on Windows.
We were letting Python typecast, and that causes the wrong result on Windows. Return the correct result explicitly when "nan" is found in the string.

Also, small reformatting of an else if -> elif.
2017-02-12 06:05:57 +01:00
Sei Lisa
37a4c86516 Change the llRotBetween algorithm.
The former ones don't match LSL's behaviour, in particular llRotBetween(<1,0,0>,<-1,0,0>) should return <0,0,1,0> but it didn't. Fix by using an algorithm that is closer to the one used by the sim.
2017-01-27 19:50:05 +01:00
Sei Lisa
48e1035ac3 Minor comment fix. 2017-01-26 03:01:34 +01:00
Sei Lisa
813bdf36e9 Comment out Moon Metty's llRotBetween algorithm. 2017-01-25 19:29:57 +01:00
Sei Lisa
e8852ad124 Fix llFabs with corner cases.
Minus zero is returned unchanged. Indet and NaN are returned unchanged too.
2017-01-24 06:02:45 +01:00
Sei Lisa
27adfdbfb9 Fix llRound behaviour in corner cases.
We had too much precision. In LSL, llRound(0.49999997) gives 1, not 0, because the loss of precision after adding 0.5 to that makes the result 1. Fixed by converting to F32 prior to flooring.
2017-01-24 05:50:07 +01:00
Sei Lisa
80cbaf8fd5 Fix llEuler2Rot's sign.
LL's algorithm for llEuler2Rot involves calculating a rotation matrix from the Eulers, then transforming the rotation matrix to quaternion. This generates sign discrepancies with our direct quaternion calculation algorithm.

Fixed by making only the necessary calculations to find the correct sign. Unfortunately, they are still heavy (notably, six more trig functions).
2017-01-24 05:45:42 +01:00
Sei Lisa
390de46bdb Fix more issues with llRot2Euler.
Mainly, the input quaternion wasn't being normalized prior to using it for calculations, and that broke compatibility. But even then, sometimes the arc sine of a value greater than 1 could be calculated, so we clamp it.
2017-01-23 18:55:30 +01:00
Sei Lisa
250438dfe9 Simplify the llRot2Euler equations.
We save a few multiplications by dividing both atan2 arguments by 2.
2017-01-23 16:41:56 +01:00
Sei Lisa
6ac02854aa Fix llRot2Euler's return types.
It didn't return Vector in the singularity case. Also, it neglected to truncate the result to single precision.
2017-01-23 16:39:58 +01:00
Sei Lisa
84648dadea Fix a couple mismatches of llAxes2Rot with actual behaviour.
For all zeros input, the result was <1,0,0,0> but we were producing <0,0,0,.5> because the first branch was taken. Fixed.

We forgot to take the square root when calculating the magnitude of the quaternion while normalizing. Fixed.

Use qnz instead of special casing.
2017-01-23 02:06:16 +01:00
Sei Lisa
13c7b0ef17 Convert output of llAxes2Rot to F32. 2017-01-23 01:18:19 +01:00
Sei Lisa
dd1b7ed594 Fix llAngleBetween when given a quaternion with all zeros.
LSL behaves as if it was ZERO_ROTATION instead, so we fix it by creating a function that returns ZERO_ROTATION when given <0,0,0,0>. Use it for llRot2{Fwd,Left,Up} as well.
2017-01-23 00:08:24 +01:00
Sei Lisa
1262934baf Fix llAbs raising a run-time exception in Mono.
llAbs(-2147483648) raises this:
 System.OverflowException: Value is too small.
  at System.Math.Abs (Int32 value) [0x00000] in <filename unknown>:0
  at LindenLab.SecondLife.Library.llAbs (Int32 i) [0x00000] in <filename unknown>:0

So it's actually not computable. In LSO it returns -2147483648, though.
2017-01-22 19:54:01 +01:00
Sei Lisa
ac775c9999 Join Internal{Get|Delete}SubSequence, fixing a bug in Get.
llGetSubString and llList2List could produce output longer than the input for some params. Fix that, and join the functions into one unique function for uniformity. Also, get rid of the special case of empty elements, because it can be treated properly by the general case, and it's not so common as to merit special attention.
2017-01-22 18:08:44 +01:00
Sei Lisa
9b812a2d2a Add no-coverage markers to Windows-specific code.
It won't be reached. Also, simplify the expected errors line to make it shorter.
2017-01-22 01:32:50 +01:00
Sei Lisa
007a726bee Fix llUnescapeURL with % in place of the second hex character.
When the input was of the form e.g. "%4%40", the second "%" was erroneously starting another quoted character. LSL doesn't behave that way: parsing resumes without starting another quoted character. Disturbingly, the expected result in the corresponding test was wrong. Fixed both the test case and the code to match actual LSL behaviour.
2017-01-20 01:59:59 +01:00
Sei Lisa
b0f8b7036b A bit of reordering, to put some similar tests together. 2017-01-20 01:40:19 +01:00
Sei Lisa
551a6ece12 Make llGetListEntryType of a list-type element return 0 (TYPE_INVALID).
It was triggering ELSLInvalidType, which is not a good approach.
2017-01-20 01:18:13 +01:00
Sei Lisa
d1ff8a86dd Additional fixes to llBase64ToString behaviour.
llBase64ToString hid another surprise: characters in range from U+0000 to U+001F are substituted by "?" except for tabs (\x09), form feeds (\x0A), shift ins (\x0F) and unit separators (\x1F), which were kept verbatim. So, mimic this behaviour.
2017-01-19 07:00:06 +01:00
Sei Lisa
a6955c4057 Fix llGetListEntryType. 2017-01-19 04:46:57 +01:00
Sei Lisa
94550af95a Minor style change. 2017-01-19 03:31:02 +01:00
Sei Lisa
7c2b76949e Make one more llXorBase64[StringsCorrect] case computable.
When the input string is at most 1 byte (2 base64 characters), the result is computable because the first byte is always zero.
2017-01-19 02:58:42 +01:00
Sei Lisa
7f8cb4ec58 Fix llAbs corner case.
As an exception, llAbs(-2147483648) equals -2147483648.
2017-01-18 00:50:59 +01:00
Sei Lisa
a65300ed49 Typo in a comment. 2017-01-17 02:53:26 +01:00
Sei Lisa
c8bfd40c66 Ensure that floats are compared with 32-bit precision.
The equality operator was comparing the raw floats when two were given. Also, type() was called when it was not needed.
2017-01-17 02:38:52 +01:00
Sei Lisa
6591b5dfd8 Fix return type of cross product.
mod(Vector, Vector) was returning tuple, not Vector.
2017-01-17 02:22:10 +01:00
Sei Lisa
f657d3e875 Use hex notation for a denormal float. 2017-01-16 23:33:49 +01:00
Sei Lisa
1a06bf4eb9 Fix minus zero in llFrand().
llFrand returns minus zero when given a negative denormal.
2017-01-16 20:37:11 +01:00
Sei Lisa
4ec9396688 (float)"-NaN" should produce NaN, not Indet.
But (vector)"<-NaN, 0, 0>" produces Indet, not NaN.
2017-01-12 03:29:38 +01:00
Sei Lisa
19dec1d79e Allow llModPow and llXorBase64Strings to work in calculator mode.
e16fad0 was somewhat hurried. Revert it and use ELSLCantCompute, which is intended exactly for that purpose.
2017-01-07 20:46:14 +01:00
Sei Lisa
8609c38451 In LSO, lists of 1 element also evaluate to false (SVC-689). 2017-01-04 05:06:56 +01:00
Sei Lisa
e16fad0366 llXorBase64Strings and llModPow are not safe to precompute.
The reason is they have an embedded delay. A script might rely on it, therefore substituting the call with its value is not equivalent to leaving the call. They were both already excluded from the SEF table for the same reason.
2016-12-25 05:25:24 +01:00
Sei Lisa
d54ba42330 Fix more test failures on Windows.
On Windows, float('nan') produces Indeterminate. To fix, set Indet first and then set NaN to the opposite.
2016-12-22 06:05:47 +01:00
Sei Lisa
efcf1cb1df Fix llListSort problem on Windows.
Apparently, under Windows, Python does a UTF-16 word-by-word comparison when comparing two strings:

>>> u'\ud700' < u'\U0001d41a'
True
>>> u'\ue000' < u'\U0001d41a'
False

Fix it by encoding as UTF-32 big endian before comparison, when that happens.
2016-12-22 05:50:18 +01:00
Sei Lisa
91fd9734c8 Fix llRot2Fwd/llRot2Left/llRot2Up and add regression tests. 2016-12-22 03:06:56 +01:00
Sei Lisa
14488ddd92 Improve behaviour of llAtan2 to make it closer to SL's.
Especially regarding NaN inputs. Add regression tests.
2016-12-22 01:08:07 +01:00