[Haskell-cafe] Bug with [Double]

Dmitry Olshansky olshanskydr at gmail.com
Wed May 19 05:24:30 EDT 2010


Hello all,

It seems that I saw something like this in Cafe recevtly. But I am not sure...
In GHC 6.12.1 (Platform 2010 on Windows Vista) I have

Prelude> [1,1+2/3..10]
[1.0,1.6666666666666665,2.333333333333333,2.9999999999999996,3.666666666666666,4.333333333333332,4.999999999999998,5.666666666666664,6.33333333333333,6.9999999999999964,7.6666666666666625,8.333333333333329,8.999999999999995,9.66666666666666,10.333333333333327]

-- It is a bug!

Prelude> [1,5/3..10]
[1.0,1.6666666666666667,2.3333333333333335,3.0,3.6666666666666665,4.333333333333333,5.0,5.666666666666667,6.333333333333334,7.000000000000001,7.666666666666668,8.333333333333336,9.000000000000004,9.666666666666671]

-- correct, but...

Prelude> [1,5/3..4]
[1.0,1.6666666666666667,2.3333333333333335,3.0,3.6666666666666665,4.333333333333333]

-- ... wrong again

Prelude> [1,1+2/3..10] :: [Float]
[1.0,1.6666667,2.3333335,3.0000002,3.666667,4.333334,5.000001,5.666668,6.333335,7.000002,7.666669,8.333336,9.000003,9.66667]

-- correct

Prelude> [1,1+2/3..10] :: [Double]
[1.0,1.6666666666666665,2.333333333333333,2.9999999999999996,3.666666666666666,4.333333333333332,4.999999999999998,5.666666666666664,6.33333333333333,6.9999999999999964,7.6666666666666625,8.333333333333329,8.999999999999995,9.66666666666666,10.333333333333327]

-- wrong

Any comments?


More information about the Haskell-Cafe mailing list