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 &quot;The nearest even integer&quot; =
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>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=3D2>&gt; From: Rijk-Jan van Haaften [<A =
HREF=3D"mailto:rjchaaft@cs.uu.nl">mailto:rjchaaft@cs.uu.nl</A>]</FONT>
<BR><FONT SIZE=3D2>&gt; Sent: Wednesday, May 09, 2001 8:06 AM</FONT>
<BR><FONT SIZE=3D2>&gt; To: haskell@haskell.org</FONT>
<BR><FONT SIZE=3D2>&gt; Subject: Class RealFrac: round</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Hello,</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; While I were writing a RealFrac implementation =
for BigDouble's (for</FONT>
<BR><FONT SIZE=3D2>&gt; high-precision computations) I found a strange =
implementation of</FONT>
<BR><FONT SIZE=3D2>&gt; round in the standard prelude (from the haskell =
definition):</FONT>
</P>

<P><FONT SIZE=3D2>...</FONT>
</P>

<P><FONT SIZE=3D2>&gt; The strange case is if signum (abs r - 0.5) is =
0:</FONT>
<BR><FONT SIZE=3D2>&gt; such numbers are round to the nearest EVEN =
integer. In mathematics,</FONT>
<BR><FONT SIZE=3D2>&gt; computer science (the studies I'm doing) and =
physics, as far as I</FONT>
<BR><FONT SIZE=3D2>&gt; know, it is usual to round such numbers up, =
rather than to the nearest</FONT>
<BR><FONT SIZE=3D2>&gt; integer. For example:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Number&nbsp;&nbsp; Hugs&nbsp;&nbsp;&nbsp; =
Math</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 0.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 1.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2</FONT>
<BR><FONT SIZE=3D2>&gt; -3.5&nbsp;&nbsp;&nbsp;&nbsp; =
-4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -4</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 6.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Why did the Haskell designers choose this =
behaviour?</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Thanks in advance,</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Rijk-Jan van Haaften</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; =
_______________________________________________</FONT>
<BR><FONT SIZE=3D2>&gt; Haskell mailing list</FONT>
<BR><FONT SIZE=3D2>&gt; Haskell@haskell.org</FONT>
<BR><FONT SIZE=3D2>&gt; <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>&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C0D889.5242C2C0--