[Haskell-cafe] Mystery of an Eq instance
Brandon Allbery
allbery.b at gmail.com
Fri Sep 20 18:31:38 CEST 2013
On Fri, Sep 20, 2013 at 12:17 PM, damodar kulkarni
<kdamodar2000 at gmail.com>wrote:
> Ok, let's say it is the effect of truncation. But then how do you explain
> this?
>
> Prelude> sqrt 10.0 == 3.1622776601683795
> True
> Prelude> sqrt 10.0 == 3.1622776601683796
> True
>
Because there's no reliable difference there. The truncation is in bits
(machine's binary representation) NOT decimal digits. A difference of 1 in
the final digit is probably within a bit that gets truncated.
I suggest you study IEEE floating point a bit. Also, study why computers do
not generally store anything like full precision for real numbers. (Hint:
you *cannot* store random real numbers in finite space. Only rationals are
guaranteed to be storable in their full precision; irrationals require
infinite space, unless you have a very clever representation that can store
in terms of some operation like sin(x) or ln(x).)
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130920/c50e5cfb/attachment.htm>
More information about the Haskell-Cafe
mailing list