[Haskell-cafe] instance Enum Double considered not entirely great?
Daniel Fischer
daniel.is.fischer at googlemail.com
Wed Sep 21 00:21:39 CEST 2011
On Tuesday 20 September 2011, 23:56:53, Evan Laforge wrote:
> > I actually think the brokenness of Ord for floating point values is
> > worse in many ways, as demonstrated by the ability to insert a value
> > into a Data.Set.Set and have other values "disappear" from the set as
> > a result. Getting an unexpected element in a list doesn't really seem
> > as bad as silently corrupting entire data structures.
>
> Whoah, that's scary. What are some examples of this happening? Does
> this mean it's unsafe to store Doubles in a Map?
Too lazy to work out the details, but since
NaN ? x = False
for ? any of <, >, <=, >=, (==, /=) and compare is defined on terms of
these, all results of compare involving a NaN are GT.
member and insert in Data.set use compare to find out where to go, so
inserting NaNs puts them at the max position. Insert a couple, and
rebalancing can put one above non-NaN values, oops.
More information about the Haskell-Cafe
mailing list