From ...
From: Erik Naggum
Subject: Re: Why is (round 2.5) = 2?
Date: 1995/04/16
Message-ID: <19950416T033512Z.enag@naggum.no>#1/1
X-Deja-AN: 101008874
references:
supersedes: <19950416T031255Z.enag@naggum.no>
organization: Naggum Software; +47 2295 0313
newsgroups: comp.lang.lisp
[Jim Meehan]
| In Common Lisp, round, when applied to a number of the form
| integer+0.5, returns either integer or integer+1, whichever is even.
| Does anyone remember why it was defined that way?
I don't "remember", but when I asked the same question not long ago, I was
told that it was mathematically correct, which indeed it is.
(loop for x from 0 to 99 sum (+ 1/2 x))
=> 5000
(loop for x from 0 to 99 sum (round (+ 1/2 x)))
=> 5000
if round "rounded up", you would get
(loop for x from 0 to 99 sum (ceiling (+ 1/2 x)))
=> 5050
that is, for a random distribution of numbers, adding values after rounding
will yield Pentium-size errors if (round x) == (floor (+ 1/2 x)).
#
--
sufficiently advanced political correctness is indistinguishable from irony