<div dir="ltr">On Fri, Sep 20, 2013 at 6:17 PM, damodar kulkarni <span dir="ltr">&lt;<a href="mailto:kdamodar2000@gmail.com" target="_blank">kdamodar2000@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>Ok, let&#39;s say it is the effect of truncation. But then how do you explain this?<br>

<br><span style="font-family:&#39;courier new&#39;,monospace">Prelude&gt; sqrt 10.0 == 3.1622776601683795<br>True<br>Prelude&gt; sqrt 10.0 == 3.1622776601683796<br>

True<br></span><br></div></div></div></blockquote><div><br></div><div>Well, that&#39;s easy: </div><div> </div><div><div>    ë: decodeFloat 3.1622776601683795</div><div>    (7120816245988179,-51)</div><div>    ë: decodeFloat 3.1622776601683796</div>

<div>    (7120816245988179,-51)</div></div><div><br></div><div>On my machine, they are equal. Note that ...4 and ...7 are also equal, after they are truncated to fit in 53 (which is what `floatDigits 42.0` tells me) bits (`floatRadix 42.0 == 2`).</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>Ok, again something like truncation or rounding seems at work but the precision rules the GHC is using seem to be elusive, to me.</div>

</div></div></blockquote><div><br></div><div>It seems to me that you&#39;re not familiar with the intricacies of floating-point arithmetic. You&#39;re not alone, it&#39;s one of the top questions on StackOverflow.</div><div>

<br></div><div>Please find yourself a copy of &quot;What Every Computer Scientist Should Know About Floating-Point Arithmetic&quot; by David Goldberg, and read it. It should be very enlightening. It explains a bit about how IEEE754, pretty much the golden standard for floating point math, defines these precision rules.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>

But more importantly, if one is advised NOT to test equality of two floating point values, what is the point in defining an Eq instance?<br></div></div></blockquote><div><br></div><div>Although equality is defined in IEEE754, it&#39;s not extremely useful after arithmetic (except perhaps for zero tests). Eq is a superclass of Ord, however, which is vital to using floating point numbers.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>Is the Eq instance there just to make __the floating point types__ members of the Num class?</div>

</div></div></div></blockquote><div><br></div><div>That was also a reason before GHC 7.4 (Eq is no longer a superclass of Num).</div></div></div></div>