mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-02 08:08:20 +00:00
Rewrite Mono float to string conversion; fix llDumpList2String
llDumpList2String has changed its behaviour with respect to minus zero. Now it converts -0.0 to a string without the minus sign. While testing this, we noticed several mismatches in the float to string conversions; the existing routine did not properly convert some values because as we discovered later, it is subject to double rounding; one of them is the built-in round-to-nearest-or-even while getting the first 7 significant digits, and the other is just an increment when the digit is a 5 or more, so round to nearest, ties away from zero, and is performed on the digit past the five or six visible digits that LSL shows. The new code is a tad easier to understand and more robust. A first variant of the new code is left commented out for history's sake, and will be removed in the next commit.
This commit is contained in:
parent
281ff4d96a
commit
d2e64e25a6
3 changed files with 194 additions and 54 deletions
38
unit_tests/expr.suite/dumplist2string.lsl
Normal file
38
unit_tests/expr.suite/dumplist2string.lsl
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Change in behaviour for llDumpList2String
|
||||
[ "String cast in various ways except DumpList2String"
|
||||
, (string)<-0.0, 0, 0>
|
||||
, (string)[<-0.0, 0, 0>]
|
||||
, (string)[-0.0]
|
||||
, (string)[<4.999999418942025e-07, 0, 0>]
|
||||
, (string)<4.999999418942025e-07, 0, 0>
|
||||
, (string)4.999999418942025e-07
|
||||
, (string)[<1.4999999393694452e-06, 0, 0>]
|
||||
, (string)<1.4999999393694452e-06, 0, 0>
|
||||
, (string)1.4999999393694452e-06
|
||||
, (string)[<2.499999936844688e-06, 0, 0>]
|
||||
, (string)<2.499999936844688e-06, 0, 0>
|
||||
, (string)[2.499999936844688e-06]
|
||||
, (string)2.499999936844688e-06
|
||||
, (string)[<1e11,0,0>]
|
||||
, (string)<1e11,0,0>
|
||||
, (string)[1e11]
|
||||
, (string)1e11
|
||||
, llList2String([<-0.0, 0, 0>], 0)
|
||||
, llList2String([<1e11, 0, 0>], 0)
|
||||
, llList2CSV([<-0.0, 0, 0>])
|
||||
, llList2CSV([<1e11, 0, 0>])
|
||||
, "DumpList2String:"
|
||||
, llDumpList2String([<-0.0, -0.0, -0.0, -0.0>], "")
|
||||
, llDumpList2String([<-1e-40, -1e-40, -1e-40, -1e-40>], "")
|
||||
, llDumpList2String([-0.0], "")
|
||||
, llDumpList2String([<5e-7, 0, 0>], "")
|
||||
, llDumpList2String([<-5e-7, 0, 0>], "")
|
||||
, llDumpList2String([<4.999999418942025e-07, 0, 0>], "")
|
||||
, llDumpList2String([<-4.999999418942025e-07, 0, 0>], "")
|
||||
, llDumpList2String([<1.4999999393694452e-06, 0, 0>], "")
|
||||
, llDumpList2String([<-1.4999999393694452e-06, 0, 0>], "")
|
||||
, llDumpList2String([<2.499999936844688e-06, 0, 0>], "")
|
||||
, llDumpList2String([<-2.499999936844688e-06, 0, 0>], "")
|
||||
, llDumpList2String([100000000000.000000], "")
|
||||
, "------"
|
||||
]
|
37
unit_tests/expr.suite/dumplist2string.out
Normal file
37
unit_tests/expr.suite/dumplist2string.out
Normal file
|
@ -0,0 +1,37 @@
|
|||
[ "String cast in various ways except DumpList2String"
|
||||
, "<-0.00000, 0.00000, 0.00000>"
|
||||
, "<-0.000000, 0.000000, 0.000000>"
|
||||
, "-0.000000"
|
||||
, "<0.000000, 0.000000, 0.000000>"
|
||||
, "<0.00000, 0.00000, 0.00000>"
|
||||
, "0.000000"
|
||||
, "<0.000002, 0.000000, 0.000000>"
|
||||
, "<0.00000, 0.00000, 0.00000>"
|
||||
, "0.000002"
|
||||
, "<0.000003, 0.000000, 0.000000>"
|
||||
, "<0.00000, 0.00000, 0.00000>"
|
||||
, "0.000003"
|
||||
, "0.000003"
|
||||
, "<100000000000.000000, 0.000000, 0.000000>"
|
||||
, "<100000000000.00000, 0.00000, 0.00000>"
|
||||
, "100000000000.000000"
|
||||
, "100000000000.000000"
|
||||
, "<-0.000000, 0.000000, 0.000000>"
|
||||
, "<100000000000.000000, 0.000000, 0.000000>"
|
||||
, "<-0.000000, 0.000000, 0.000000>"
|
||||
, "<99999997952.000000, 0.000000, 0.000000>"
|
||||
, "DumpList2String:"
|
||||
, "<0.000000, 0.000000, 0.000000, 0.000000>"
|
||||
, "<0.000000, 0.000000, 0.000000, 0.000000>"
|
||||
, "0.000000"
|
||||
, "<0.000001, 0.000000, 0.000000>"
|
||||
, "<-0.000001, 0.000000, 0.000000>"
|
||||
, "<0.000000, 0.000000, 0.000000>"
|
||||
, "<0.000000, 0.000000, 0.000000>"
|
||||
, "<0.000002, 0.000000, 0.000000>"
|
||||
, "<-0.000002, 0.000000, 0.000000>"
|
||||
, "<0.000003, 0.000000, 0.000000>"
|
||||
, "<-0.000003, 0.000000, 0.000000>"
|
||||
, "100000000000.000000"
|
||||
, "------"
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue