[Haskell-cafe] Why aren't Float and Double Bounded?

Henning Thielemann lemming at henning-thielemann.de
Tue Nov 27 15:28:58 EST 2007


On Tue, 27 Nov 2007, Josh Lee wrote:

> On Tue, 27 Nov 2007 14:41:59 -0500
> Isaac Dupree <isaacdupree at charter.net> wrote:
>
> > Henning Thielemann wrote:
> > > On Mon, 26 Nov 2007, Jason Dusek wrote:
> > >
> > >> Among numeric types, it seems that only integer types are Bounded.
> > >
> > > Maybe because IEEE format supports Infinity?
> >
> > therefore, maxBound is Infinity and minBound negative infinity?
>
> Using Infinity would go against the meaning of Enum. In the
> Double/Float types, succ and pred mean "add/subtract 1.0", as opposed
> to the unit of least precision. In fact, succ and pred lose meaning
> once the precision of the floats exceeds a certain value.
>
> > until (\x -> x == succ x) succ 1.0 :: Float
> 1.6777216e7
>
> It would be interesting to have an enumeration for Double/Float that
> goes from -Infinity to Infinity, reaching every single number on the
> way.

Actually, IEEE numbers are designed in such a way, that if you interpret
their bits as integer number, then 'succ' leads you to the next larger
representable number. Thus you only have to cast from Float or Double to
Int32 or Int64 respectively, call enumFromTo, then cast back to Float or
Double, respectively. :-]


More information about the Haskell-Cafe mailing list