Class RealFrac: round
Joe Bowers
Joe.Bowers@CanopySystems.com
Wed, 9 May 2001 09:09:46 -0400
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C0D889.5242C2C0
Content-Type: text/plain
I'm not one of the implementors, but this sort of behavior
can reduce error in fields where X.5 is a common result-
a rule like "The nearest even integer" moves upward half
the time and downward half the time- hopefully cancelling
itself out.
Or maybe they had other reasons...
Joe
> -----Original Message-----
> From: Rijk-Jan van Haaften [mailto:rjchaaft@cs.uu.nl]
> Sent: Wednesday, May 09, 2001 8:06 AM
> To: haskell@haskell.org
> Subject: Class RealFrac: round
>
>
> Hello,
>
> While I were writing a RealFrac implementation for BigDouble's (for
> high-precision computations) I found a strange implementation of
> round in the standard prelude (from the haskell definition):
...
> The strange case is if signum (abs r - 0.5) is 0:
> such numbers are round to the nearest EVEN integer. In mathematics,
> computer science (the studies I'm doing) and physics, as far as I
> know, it is usual to round such numbers up, rather than to the nearest
> integer. For example:
>
> Number Hugs Math
> 0.5 0 1
> 1.5 2 2
> -3.5 -4 -4
> 6.5 6 7
>
> Why did the Haskell designers choose this behaviour?
>
> Thanks in advance,
>
> Rijk-Jan van Haaften
>
>
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
------_=_NextPart_001_01C0D889.5242C2C0
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DUS-ASCII">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>RE: Class RealFrac: round</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>I'm not one of the implementors, but this sort of =
behavior</FONT>
<BR><FONT SIZE=3D2>can reduce error in fields where X.5 is a common =
result-</FONT>
<BR><FONT SIZE=3D2>a rule like "The nearest even integer" =
moves upward half</FONT>
<BR><FONT SIZE=3D2>the time and downward half the time- hopefully =
cancelling</FONT>
<BR><FONT SIZE=3D2>itself out.</FONT>
</P>
<P><FONT SIZE=3D2>Or maybe they had other reasons...</FONT>
<BR><FONT SIZE=3D2>Joe</FONT>
</P>
<P><FONT SIZE=3D2>> -----Original Message-----</FONT>
<BR><FONT SIZE=3D2>> From: Rijk-Jan van Haaften [<A =
HREF=3D"mailto:rjchaaft@cs.uu.nl">mailto:rjchaaft@cs.uu.nl</A>]</FONT>
<BR><FONT SIZE=3D2>> Sent: Wednesday, May 09, 2001 8:06 AM</FONT>
<BR><FONT SIZE=3D2>> To: haskell@haskell.org</FONT>
<BR><FONT SIZE=3D2>> Subject: Class RealFrac: round</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> Hello,</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> While I were writing a RealFrac implementation =
for BigDouble's (for</FONT>
<BR><FONT SIZE=3D2>> high-precision computations) I found a strange =
implementation of</FONT>
<BR><FONT SIZE=3D2>> round in the standard prelude (from the haskell =
definition):</FONT>
</P>
<P><FONT SIZE=3D2>...</FONT>
</P>
<P><FONT SIZE=3D2>> The strange case is if signum (abs r - 0.5) is =
0:</FONT>
<BR><FONT SIZE=3D2>> such numbers are round to the nearest EVEN =
integer. In mathematics,</FONT>
<BR><FONT SIZE=3D2>> computer science (the studies I'm doing) and =
physics, as far as I</FONT>
<BR><FONT SIZE=3D2>> know, it is usual to round such numbers up, =
rather than to the nearest</FONT>
<BR><FONT SIZE=3D2>> integer. For example:</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> Number Hugs =
Math</FONT>
<BR><FONT SIZE=3D2>> 0.5 =
0 1</FONT>
<BR><FONT SIZE=3D2>> 1.5 =
2 2</FONT>
<BR><FONT SIZE=3D2>> -3.5 =
-4 -4</FONT>
<BR><FONT SIZE=3D2>> 6.5 =
6 7</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> Why did the Haskell designers choose this =
behaviour?</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> Thanks in advance,</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> Rijk-Jan van Haaften</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> =
_______________________________________________</FONT>
<BR><FONT SIZE=3D2>> Haskell mailing list</FONT>
<BR><FONT SIZE=3D2>> Haskell@haskell.org</FONT>
<BR><FONT SIZE=3D2>> <A =
HREF=3D"http://www.haskell.org/mailman/listinfo/haskell" =
TARGET=3D"_blank">http://www.haskell.org/mailman/listinfo/haskell</A></F=
ONT>
<BR><FONT SIZE=3D2>> </FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C0D889.5242C2C0--