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

Richard O'Keefe ok at cs.otago.ac.nz
Mon Oct 27 21:44:17 EDT 2008


On 27 Oct 2008, at 11:00 pm, Henning Thielemann wrote:

>
> On Mon, 27 Oct 2008, L.Guo wrote:
>
>> I think this is unresonable. then try it in GHC 6.8.3.
>>
>>
>> Prelude> round 3.5
>> 4
>> Prelude> round 2.5
>> 2
>>
>>
>> Is there any explanation about that ?
>
> It's the definition we learnt in school ...

Check

http://en.wikipedia.org/wiki/Rounding

where you will find that the version of rounding
"generally taught in elementary schools" is the
one used in Pascal, namely

	round(X) = truncate(X + 0.5*sign(X))
>
(The Wikipedia entry says that Pascal uses a different
algorithm, but ISO 7185 says
"If x is positive or zero, round(x) shall be equivalent to trunc(x 
+0.5); otherwise, round(x) shall be equivalent to trunc(x-0.5).")

> I think one reason is that repeated rounding should not be worse  
> than rounding in one go.

That would be nice, but while round-to-even _reduces_ the
harm from double rounding, it does not eliminate it.



More information about the Haskell-Cafe mailing list