[bug[fix]] (round 0.5) -> 0

Started by hartrock, November 15, 2013, 05:14:28 PM

Previous topic - Next topic

hartrock


> (round 5 1)
10
> (round 0.5)
0
> (round 0.05 -1)
0.1

Seems to be a bug: at least not consistent.



My version: newLISP v.10.5.4 64-bit on Linux IPv4/6 UTF-8 libffi.

hartrock

#1
Fix:

sr@free:~/tmp/newlisp-10.5.4$ diff -u nl-math.c_orig nl-math.c
--- nl-math.c_orig      2013-10-01 17:52:03.000000000 +0200
+++ nl-math.c   2013-11-16 02:49:02.000000000 +0100
@@ -717,7 +717,7 @@
 if(params != nilCell)
     getInteger(params, (UINT*)&digits);
 
-if(digits > 0)
+if(digits >= 0)
     {
     precision = pow(10.0, (double)(digits > 20 ? 20 : digits));
     fNum = precision * floor(fNum/precision + 0.5);

Lutz

#2
Good catch. Thanks!



Corrected here:



http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/









Ps: your doc changes are also online here:



http://www.newlisp.org/downloads/newlisp_manual.html">http://www.newlisp.org/downloads/newlisp_manual.html

hartrock

#3
Appearing twice (two text lines in between):
(myarray 0 -1)      → 4