rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Rounding function incorrect! #605

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 02:08:06 Created by sur3 on 2017-07-07 12:30:26 Original: https://sourceforge.net/p/maxima/bugs/3318


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

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 02:08:07 Created by sur3 on 2017-07-07 12:31:56 Original: https://sourceforge.net/p/maxima/bugs/3318/#7f95


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"

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 02:08:10 Created by kjak on 2017-07-07 19:24:02 Original: https://sourceforge.net/p/maxima/bugs/3318/#7399


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.