[Haskell-cafe] Re: Why 'round' does not just round numbers ?
David Roundy
droundy at darcs.net
Tue Oct 28 12:26:53 EDT 2008
On Tue, Oct 28, 2008 at 04:07:12PM +0000, Bart Massey wrote:
> I'm just saying that the name "round" is unfortunate, since
> there's no single universally accepted mathematical
> definition for it. For this reason many programming
> languages either don't provide it or provide a different
> version. The names "roundHalfUp" and "roundHalfEven" are
> much better: they each correspond to a well-known
> mathematical function that is codified in an IEEE standards
> document.
>
> If it were up to me, I'd deprecate round in Haskell' and
> make the documentation point to these other rounding
> functions.
>
> Our solution in Nickle (http://nickle.org), BTW, was to
> provide floating point with user-settable mantissa precision
> and a default precision of 256 bits. For all practical
> purposes we know of, this makes worrying about the edge
> cases for rounding pointless. Kahan has a nice paper on
> this that I can't find right now.
Isn't it quite common to have numbers like 0.5 as input? (as an
example of a number that's exactly representable in any binary
floating point format, but whose rounded value depends on rounding
convention.
I don't feel strongly on the question, but was somewhat surprised to
find that round is present, for the reasons you mention. floor (x+0.5)
is not a bad way to round... no one will mistakenly thing that it'll
do something smart with half-integers.
David
More information about the Haskell-Cafe
mailing list