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

Q&A's, tips, howto's
Locked
hartrock
Posts: 136
Joined: Wed Aug 07, 2013 9:37 pm

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

Post by hartrock »

Code: Select all

> (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.
Last edited by hartrock on Sat Nov 16, 2013 2:02 am, edited 2 times in total.

hartrock
Posts: 136
Joined: Wed Aug 07, 2013 9:37 pm

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

Post by hartrock »

Fix:

Code: Select all

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Post by Lutz »

Good catch. Thanks!

Corrected here:

http://www.newlisp.org/downloads/develo ... nprogress/




Ps: your doc changes are also online here:

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

hartrock
Posts: 136
Joined: Wed Aug 07, 2013 9:37 pm

Re: PS doc changes

Post by hartrock »

Appearing twice (two text lines in between):

Code: Select all

(myarray 0 -1)      → 4

Locked