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

Lennart Augustsson lennart at augustsson.net
Mon Oct 27 09:24:03 EDT 2008


It is certainly what I learnt in school.  But that was another school.

On Mon, Oct 27, 2008 at 12:15 PM, Janis Voigtlaender
<voigt at tcs.inf.tu-dresden.de> wrote:
> 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 ...
>
> Hmm, Henning, this is strange. The two of us went to the very same
> school, but I know for a fact that I learnt 2.5 to round to 3, not 2 as
> above. ;-)
>
>> I think one reason is that repeated rounding should not be worse than
>> rounding in one go. Consider the rule 'use ceiling when the first removed
>> digit is 5'. Then
>>
>> 0.45 - (round to one place) -> 0.5 - (round to integer) -> 1
>>
>> but
>>
>> 0.45 - (round to integer) -> 0
>
> That is of course true (and was the topic of heated discussion with my
> fourth grade math teacher), but does not explain 2.5 -> 2.
>
> Ciao, Janis.
>
> --
> Dr. Janis Voigtlaender
> http://wwwtcs.inf.tu-dresden.de/~voigt/
> mailto:voigt at tcs.inf.tu-dresden.de
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list