[Haskell-cafe] Set of reals...?
Jon Fairbairn
Jon.Fairbairn at cl.cam.ac.uk
Wed Oct 27 06:51:31 EDT 2004
On 2004-10-27 at 19:37+0900 Stijn De Saeger wrote:
> hello
>
> Thanks for the explanation, at first it seemed like enumFromThenTo
> would indeed give me the functionality I am looking for. But then all
> of GHCi started acting weird while playing around... this is a
> copy-paste transcript from the terminal.
>
> *S3> 0.5 `elem` [0.0,0.1..1.0]
> True
> *S3> 0.8 `elem` [0.6,0.7..1.0]
> False
> *S3> 0.8 `elem` [0.6,0.7..1.0]
> False
> *S3> [0.6,0.7..0.9]
> [0.6,0.7,0.7999999999999999,0.8999999999999999]
> *S3>
>
> ????????
> why would the floating point step size work the first time but not the
> second? confusing...
Doubles aren't real numbers, they're binary floating
point. 1/5 doesn't have a finite binary representation.
Also what gets printed out has been converted back to
decimal and rounded a bit. So don't expect too much from
them!
You probably want to use Double -> Bool, and possibly look
at infinite precision real arithmetic too.
Jón
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe
mailing list