> I´m pretty new in haskell and I'm wondering about the following list
> HUGS98 gave me:
>
> I typed :
> Prelude> [1, 1.1 .. 10]
> and expected an ascending list from 1 to 10 in exact steps of 0.1
...which is what you got...
> This is what Hugs gave me:
> [1.0 , 1.1, (...) 7.7, 7.79999, 7.89999, 7.99999, 8.09999, 8.2, 8.3,
> (...) ,10.0]
>
> So why occur e.g. 7.79999 instead of 7.8 ?
...except there were rounding problems. Floating-point numbers are simply
difficult. Representing them is bad, displaying them is worse, and there
are questions I don't know the answer to about how the list is
calculated: if by repeated addition, rounding errors will build up (it
looks like that, since 8.0 can certainly be represented in the machine
accurately, but wasn't in your list), and if by multiplication, they
should be one-off errors.
My own experiment (running Hugs September 1999 on a Psion Revo) suggest
that in fact the list is formed by repeated addition, as I get:
[1.0, 1.1,...,6.3,6.4,6.499999999999,6.599999999,...,9.2999999998,...,
9.99999999998]
(adjust no. of 9's to taste)
which looks like a rounding error is gradually building up. This is a
silly way to calculate such lists in FP, but perhaps there's a good
reason? (I suppose speed of calculation might be one!)
--
http://sc3d.org/rrt/ | certain, a. insufficiently analysed