[Haskell-cafe] Re: Why 'round' does not just round numbers ?
wnoise at ofb.net
Tue Oct 28 00:08:26 EDT 2008
On 2008-10-27, Bart Massey <bart at cs.pdx.edu> wrote:
> Peter Gavin <pgavin <at> gmail.com> writes:
>> The reason for doing it this way is that e.g. 2.5 is
>> exactly between 2 and 3, and rounding *up* every time
>> would cause an uneven bias toward 3. To counteract that
>> effect, rounding to the nearest even integer is used,
>> which causes the half of the x.5 values to round up, and
>> the other half to round down.
> Everyone keeps providing this rationale, but of course if
> you want "half the values to round up and the other half
> down" it does just as well to round positive values up and
> negative values down.
Except, of course, that it is quite common to work with just positive
numbers. Working just with numbers near (even + 0.5) or (odd + 0.5)
is extremely rare.
> I have written floating point code that depends on
> consistent rounding in the past. Being able to depend on
> round (1 + x) = 1 + round x
> is sometimes useful, but not possible for round-to-even.
Also not for round-up -- consider floating point values where the
precision changes and it rounds differently than you, or the point where
adjacent floating point values are now 2 apart. You basically can't
depend on any nice behaviour once floating point enters the room.
More information about the Haskell-Cafe