[Haskell-cafe] Re: Why 'round' does not just round numbers ?

Achim Schneider barsoap at web.de
Mon Oct 27 07:10:13 EDT 2008

"L.Guo" <leaveye.guo at gmail.com> wrote:

> "round x returns the nearest integer to x, the even integer if x is
> equidistant between two integers."
> Is there any explanation about that ?
Yes. math.h, rint() and IEEE.

The Right Way(tm) to round is rounding every other n.5 into a different

round 1.5 = 2
round 2.5 = 2
round 3.5 = 4
round 4.5 = 4

and so on. It's statistically correct, that is, but also more
computationally expensive.

In practise, such things rarely matter, so you just don't need to care.
If you have to care, pray that you know it. You're also bound to slam
your nose into much, much messier issues then, too, wishing you'd
learnt higher numerics in school, kind of like learning Haskell and
wishing the first grade math curriculum was based on categories instead
of sets.

(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

More information about the Haskell-Cafe mailing list