[Haskell-cafe] Mystery of an Eq instance
damodar kulkarni
kdamodar2000 at gmail.com
Fri Sep 20 13:47:10 CEST 2013
Hello,
There were some recent discussions on the floating point support in Haskell
and some not-so-pleasant "surprises" people encountered.
There is an Eq instance defined for these types!
So I tried this:
*Main> sqrt (10.0) ==3.1622776601683795
True
*Main> sqrt (10.0) ==3.16227766016837956
True
*Main> sqrt (10.0) ==3.1622776601683795643
True
*Main> sqrt (10.0) ==3.16227766016837956435443343
True
It seems strange.
So my doubts are:
1. I wonder how the Eq instance is defined in case of floating point types
in Haskell?
2. Can the Eq instance for floating point types be considered "meaningful"?
If yes, how?
In general, programmers are **advised** not to base conditional branching
on tests for **equality** of two floating point values.
3. Is this particular behaviour GHC specific? (I am using GHC 6.12.1)
If there are references on this please share.
Thanks and regards,
-Damodar Kulkarni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130920/ec31da15/attachment.htm>
More information about the Haskell-Cafe
mailing list