Enum on Float/Double

George Russell ger@tzi.de
Thu, 24 Oct 2002 18:31:01 +0200


The situation with Enum on Ratio is pretty bad but at least
it's not hopeless, since rational numbers are at least exact.  But
for Float/Double it seems to be a total disaster area.  Since it seems
to be impossible to abolish Enum Float/Double altogether, would it
at least be possible to make it rather more useful, by making
   succ x 
return the next representable float after x (or x if x is non-finite)
and pred x the previous representable float.  This would (a) be useful;
(b) make mathematical sense; (c) is tricky to implement with the existing
primitives.

Before someone else points it out, this is of course unimplementable should
someone in the future implement infinite-precision reals in Haskell, but
as (barring a solution to the halting problem) Eq would be as well, that
does not bother me.

My preference would be for succ (+-0) to return the smallest positive
real, since then you could define succ x to be the unique y with
x < y and forall z . z < y => not (x < z), where such a y exists, and
I'm not sure if the Haskell standard knows about signed zeros.

Feri wrote 
> Everybody working with floats should know their quirks
While in an ideal world, everyone who represented a mouse position or
anything else as a float should have a PhD in numerical analysis, in
practice they do not.  Indeed I think the Haskell Library Report contains
quite a few examples of floating point code which a numerical analyst would
have written rather better.  So I don't think it's good enough to treat
every Float/Double operation as if it had an implicit "UNSAFE" flag 
indicating that the compiler was entitled to wierd behaviour only
comprehensible to experts, as seems to be the case with floating 
enumerations now.