[Haskell-cafe] Which one is right?

Jake McArthur jake.mcarthur at gmail.com
Wed Jun 24 16:19:11 EDT 2009


Linker wrote:
> Hugs> [0,0.1..1]
> [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
 >
> Prelude> [0,0.1..1]
> [0.0,0.1,0.2,0.30000000000000004,0.4,0.5,0.6,0.7,0.7999999999999999,0.8999999999999999,0.9999999999999999]

Just floating point errors. In this case, you may be able to get away 
with something like this:

     Prelude> map ((/10) . fromIntegral) [0..10]
     [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]

- Jake


More information about the Haskell-Cafe mailing list