Menu

#3318 Rounding function incorrect!

None
wont-fix
nobody
round (4)
5
2017-07-07
2017-07-07
No

Hi, the rounding function works incorrect:

Maxima 5.38.1 http://maxima.sourceforge.net
using Lisp SBCL 1.3.11
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) round(0.5);
(%o1)                                  0

This should return One and not Zero for 0.5.
Also the description in the manual is confusing it says

Multiples of 1/2 are rounded to the nearest even integer.

Why should be only rounded to even integers and not odd integers!?

Also it would be nice if the rounding and truncate functions would distribute over complex number, I always have to do round(realpart(N))+round(imagpart(N))*%i which is an annoying syntax for a simple round(N).

Greetz
Si

Discussion

  • Simon ''the Sorcerer''

    Maxima version: "5.38.1"
    Maxima build date: "2017-01-03 02:05:13"
    Host type: "x86_64-pc-linux-gnu"
    Lisp implementation type: "SBCL"
    Lisp implementation version: "1.3.11"

     
  • Kris Katterjohn

    Kris Katterjohn - 2017-07-07
    • status: open --> wont-fix
     
  • Kris Katterjohn

    Kris Katterjohn - 2017-07-07

    round seems to be working exactly as documented. As you showed, round is documented to round multiples of 1/2 to the nearest even integer, so round(0.5) rounding to 0 is correct (since 0 is even).

    There are various conventions for rounding numbers in this case, such as rounding away from zero, rounding toward zero, rounding to the nearest even, etc. round chooses to round to the nearest even integer.

    Since there is no bug here and the rest of the report is a feature request, I'm closing this as wont-fix.

    As for your feature request, feel free to bring it up on the mailing list. I'm really not sure if that behavior is desired by default, but you may be more likely to get a response there anyway.

     

Log in to post a comment.