[Haskell-cafe] smallest double eps

Bryan Burgers bryan.burgers at gmail.com
Sat Sep 30 13:42:00 EDT 2006


> >>> Hang on, hang on, now I'm getting confused.
> >>> First you asked for the smallest (positive) x such that
> >>>    1+x /= x
> >>> which is around x=4.5e15.
> >>
> >> 1 + 0 /= 0
> >>
> >> 0 is smaller than 4.5e15
> >>
> >> So I don't understand this at all...
> >
> > But then 0 isn't positive.
>
> Why not?
> In any case every positive number nust satisfy the above inequation so what
> about 0.1, which is certainly smaller than 4500000000000000?

In math, every positive number must satisfy the above inequation, that
is true. But as Chad said, the smallest number in Haskell (at least
according to my GHC, it could be different with different processors,
right?) that satisfies the equation is 2.2e-16.

> 1 + 2.2e-16 /= 1
True
> 1 + 2.2e-17 /= 1
False

This is because the Double type only holds so much precision. After
getting small enough, the type just can't hold any more precision, and
the value is essentially 0.

> last $ takeWhile (\x -> 1 + x /= 1) (iterate (/2) 1)
2.220446049250313e-16


More information about the Haskell-Cafe mailing list