[Haskell-cafe] Bug with [Double]

Roman Leshchinskiy rl at cse.unsw.edu.au
Wed May 19 06:27:11 EDT 2010


On 19/05/2010, at 19:24, Dmitry Olshansky wrote:

> 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!

Unfortunately, it isn't. Section 6.3.4 of the Haskell report says:

For Float and Double, the semantics of the enumFrom family is given by the rules for Int above, except that the list terminates when the elements become greater than e3+i/2 for positive increment i, or when they become less than e3+i/2 for negative i.

In this case, i = 2/3 so the last value in the list is 10+1/3. The same applies to the other examples.

Personally, I consider the Enum class itself to be broken.

Roman




More information about the Haskell-Cafe mailing list