Commit graph

63 commits

Author SHA1 Message Date
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
Sei Lisa
159fae90bf Improve llFrand.
- Remove it from lslextrafuncs, and move all the code to lslbasefuncs.
- Make it behave like SL's more accurately. Denormals return 0 always in SL.
- Use int() for truncation rather then floor/ceil.
- Add test cases.
2016-12-22 01:05:21 +01:00
Sei Lisa
fc97ce42df Be explicit about corner cases for llFrand.
inf and nan already did the right thing in Python, but just in case that doesn't happen in all platforms, we handle them explicitly. Also, that will make it more immune to bugs in future.
2016-12-21 21:49:43 +01:00
Sei Lisa
2327613423 Follow-up to ba9511e: Fix rounding of result. 2016-12-21 20:26:40 +01:00
Sei Lisa
6879037735 Fix type conversion on calling LSL functions.
We had a big chaos with type conversion. That caused a bug where passing a key to a function that required a string, or vice versa, crashed the script.

Diminish the chaos by modifying the parameters just prior to invocation (in lslfoldconst). We also remove the, now unnecessary, calls to force floats, either alone or within vectors or quaternions.
2016-12-21 06:01:03 +01:00
Sei Lisa
5105cee2e4 We already had imported hashlib. 2016-12-21 02:45:17 +01:00
Sei Lisa
7ebd68c7b2 llGenerateKey() returns key, not string 2016-12-21 01:32:54 +01:00
Sei Lisa
ba9511e2ff Implement llFrand and llGenerateKey when in Calc mode. 2016-12-21 01:18:25 +01:00
Sei Lisa
991e811f2d Fix Python gotcha with module globals, and missing 'cond' in lslextrafuncs.
The previous commit didn't work as expected. "from module import var" freezes the value at load time; changing it later has no effect. A reference to the module needs to be used.

Fix that and the similar problem with LSO. Also revert some "from lslcommon import *" introduced earlier.

That also revealed another bug about missing 'cond' in the import list of lslextrafuncs. This should fix all functions that return values on null key input.
2016-12-21 00:22:49 +01:00
Sei Lisa
39261cbfc8 Make Unicode some strings that should be, and improve error reporting in builtins.txt
Also work towards the convention that strings that represent text (possibly translatable) are in double quotes, not single.
2016-12-20 20:13:53 +01:00
Sei Lisa
43beb767f2 Fix llBase64ToString's behaviour with invalid UTF-8.
llBase64ToString doesn't behave like llUnescapeURL wrt invalid UTF-8. First, the last NUL if any is removed, and the remaining NULs are converted to "?". Second, all overlong sequences are converted to a single "?", *including the 5- and 6-byte UTF-8*.

Implement this behavour and the corresponding unit tests.
2016-12-13 15:04:02 +01:00
Sei Lisa
e8201d6956 Err when invalid UTF-8 should have been generated in LSO mode.
LSO strings are byte arrays, but our strings are made for Mono which uses Unicode, and invalid UTF-8 sequences can't be stored in Unicode without using a custom representation.

One possible representation is to only use the codepoints 0-255 in the Unicode string, to avoid supporting multiple types for strings. Something to study in future.
2016-12-13 14:26:48 +01:00
Sei Lisa
b593141f9f Fix UTF-8 in the surrogate range passing as good.
Our UTF-8 validity checker failed to recognize that characters in the surrogate range (D800-DFFF) were invalid. Fortunately, Python 2 is happy about that, therefore it doesn't crash (Python 3 fixed that range too). Unfortunately, SL isn't, therefore we fix it.

Added corresponding unit tests.
2016-12-13 03:30:32 +01:00
Sei Lisa
47013f87e2 Fix minor typo in a comment. 2016-11-14 03:10:29 +01:00
Sei Lisa
74115345f0 Fix blunder in operator priority
-a//-b did the wrong thing. Use -(a//-b) and add corresponding regression tests.
2016-11-06 04:09:43 +01:00
Sei Lisa
79dff25769 Update copyright years of some files; add legalese to seftable.txt 2016-06-27 20:06:41 +02:00
Sei Lisa
ee091c63a6 Someone's been misusing Python's re.match... O:) 2016-06-26 22:33:10 +02:00
Sei Lisa
51a7e6d199 Fix bug with reduction, and remove useless code.
Oops, we have to reduce *after* testing for range!

Also, the special cases for the tangent are unnecessary, because the results are already correct.
2016-05-21 04:16:34 +02:00
Sei Lisa
9cf9478270 Improve the (in)accuracy of llSin, llCos, llTan
All three functions have in SL the Intel problem of inaccuracy with high values. Since we work in single precision, it's barely detectable usually, but for large input numbers the difference between the imprecise results of SL and the more accurate results of recent glibc become more obvious.

This change brings back the Intel inaccuracy, even across systems (different versions of Python/C might behave differently otherwise).

Reference:
https://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bounds-by-1-3-quintillion/
2016-05-21 03:56:27 +02:00
Sei Lisa
e40c52075b Make ForceFloat more robust on non-float input.
It was designed so that only ints and floats should be accepted. But for safety, and for reuse, make that "any non-float" so that long integers are also truncated to F32.
2016-05-21 03:10:31 +02:00
Sei Lisa
13663ff077 -0x1p63 is not included in the valid range of trig functions. 2016-05-21 02:50:55 +02:00
Sei Lisa
7b70bfe55f Fix precision error in llTan special values. 2016-05-21 02:27:15 +02:00
Sei Lisa
4172f02439 One more way to transform a float to single (commented out) 2016-05-21 01:59:05 +02:00
Sei Lisa
60f257279b Use math.copysign to distinguish indeterminates
We were using a very dubious method to distinguish an indeterminate from a NaN, via struct.unpack. Turns out that math.copysign gets the job done and seems more robust.
2016-05-15 19:55:45 +02:00
Sei Lisa
b06ac33b5f Fix misspelling in the latest commit. 2016-05-15 18:44:45 +02:00
Sei Lisa
23b27bd3af Produce more math errors in division
Besides dividing by zero, any result producing NaN including inf/inf, NaN/anything, anything/NaN causes a math error as well. We only contemplated NaN/anything and neglected the rest, so we generalize it.
2016-05-15 18:21:24 +02:00
Sei Lisa
bb198b3745 Add a (currently disabled) viable and tested alternative to c_float for F32. 2016-05-06 20:11:41 +02:00
Sei Lisa
b0e5a50a59 Fix discrepancy with LSL in llCSV2List.
In LSL, llCSV2List eats the very first space in the string if there's one. This patch implements that behaviour.
2016-03-25 20:52:48 +01:00
Sei Lisa
14f70c93b4 Fix bug in llCSV2List when there's no space after comma but there's a space in the value.
E.g. llCSV2List(",A B") produced ["", "B"].
2016-03-25 20:44:59 +01:00
Sei Lisa
661853be53 Fix llRot2Axis to negate the axis when s is negative. 2016-01-22 20:54:43 +01:00
Sei Lisa
6ec2667bf3 Refine comments 2015-09-24 22:02:46 +02:00
Sei Lisa
57cacf29bb Return a float when typecasting returns zero (fixes inconsistent type) 2015-09-22 14:14:26 +02:00
Sei Lisa
aee638e900 Return denormals as 0 in (float)"number". Found by Pedro Oval. 2015-09-21 21:15:48 +02:00
Sei Lisa
2d72b8e198 Fix llList2CSV with -nan in vector and quaternion (with test case). 2015-09-09 18:14:27 +02:00
Sei Lisa
6b7b366f63 Fix llRot2Euler exception 2015-09-08 03:47:00 +02:00
Sei Lisa
bc4f574b33 Managed to deal with the '-nan' case in llList2CSV. Add test cases. 2015-09-07 02:56:44 +02:00
Sei Lisa
aa74e6ed64 Sadly, Python can't represent -nan, even though llList2CSV can display it. Add a note to that effect. 2015-09-04 05:46:18 +02:00
Sei Lisa
e35431cecf Forgot to truncate llSqrt to F32. 2015-06-16 04:41:36 +02:00
Sei Lisa
d8629f9200 Update behaviour of llListFindList for LSO. 2015-05-24 04:22:31 +02:00
Sei Lisa
c68a1f4ad6 Add copyright notices to all files, to prepare the program for release. 2015-03-05 23:18:41 +01:00