<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Verdana","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Sounds good to me.&nbsp;
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">It would be fantastic if someone could investigate Levent&#8217;s suggestion &#8220;</span><span style="font-family:&quot;Courier New&quot;">Of course, implementations can take advantage
 of the underlying CPU's native floating-point abs/sign functions if available as well, avoiding explicit tests at the Haskell code; based on the underlying platform</span><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">&#8221;
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Otherwise we&#8217;ll just end up adding an extra test and everyone&#8217;s code will run a little bit slower.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org]
<b>On Behalf Of </b>Levent Erkok<br>
<b>Sent:</b> 10 April 2013 19:25<br>
<b>To:</b> libraries@haskell.org<br>
<b>Subject:</b> Fix prelude definitions of abs/signum for Floats/Doubles<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">The current definition of &quot;abs&quot; and &quot;signum&quot; for the types Float/Double is not IEEE-754 compliant. To wit:</span><o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp;Prelude&gt; abs (-0.0::Float)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp;-0.0</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp;Prelude&gt; signum (-0.0::Float)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp;0.0</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">The correct result should be the other way around; abs returning 0.0 and signum returning -0.0 when they receive a negative-zero. The same also holds for the type Double.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">The issue came up several times in several forums, with general consensus that the behavior should match the IEEE-754 specs. Here're three different discussions on this matter:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href="http://www.haskell.org/pipermail/libraries/2011-January/015761.html">http://www.haskell.org/pipermail/libraries/2011-January/015761.html</a></span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href="http://stackoverflow.com/questions/10395761/absolute-value-of-negative-zero-bug-or-a-part-of-the-floating-point-standard">http://stackoverflow.com/questions/10395761/absolute-value-of-negative-zero-bug-or-a-part-of-the-floating-point-standard</a></span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href="http://www.haskell.org/pipermail/haskell-cafe/2013-April/107471.html">http://www.haskell.org/pipermail/haskell-cafe/2013-April/107471.html</a></span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">Proposed fix: Section 6.4.4 of the report&nbsp;<a href="http://www.haskell.org/onlinereport/basic.html#sect6.4">http://www.haskell.org/onlinereport/basic.html#sect6.4</a>&nbsp;gives &quot;default&quot; definitions for
 abs/signum; which fails to take into account of negative-zero values for floating-point types. An easy fix would be to add to the report a note on the status of negative-zero for Real/Float instances; with individual implementations explicitly checking for
 negative-0 first. For instance GHC's implementation can be changed as follows:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">instance Num Float where</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; signum x | isNegativeZero x = x</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| x == 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| x &gt; 0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| otherwise &nbsp; &nbsp; &nbsp; &nbsp;= negate 1</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; abs x &nbsp; &nbsp;| isNegativeZero x = 0</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| x &gt;= 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = x</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| otherwise &nbsp; &nbsp; &nbsp; &nbsp;= negate x</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">A similar change would need to be done for the &quot;Num Double&quot; instance as well. Of course, implementations can take advantage of the underlying CPU's native floating-point abs/sign functions if available
 as well, avoiding explicit tests at the Haskell code; based on the underlying platform.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">Library guidelines suggest a discussion period of 2 weeks on this issue. I'm hoping that we can resolve the issue in a timely manner, and at least GHC's implementation can match the desired semantics
 in the next release. If there's consensus at the end of 2-weeks; I'll go ahead and create a corresponding ticket for GHC.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">Thanks,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">-Levent.</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>