[Haskell-cafe] instance Enum Double considerednotentirelygreat?

Donn Cave donn at avvanta.com
Tue Sep 27 18:23:20 CEST 2011


Quoth Chris Smith <cdsmith at gmail.com>,
...
> I certainly don't agree that wanting the exact value from a floating
> point type is a reasonable expectation.  The *only* way to recover those
> results is to do the math with the decimal or rational values instead of
> floating point numbers.  You'll get the rounding error from floating
> point regardless of how you do the computation, because the interval
> just isn't really 0.1.  The difference between those numbers is larger
> than 0.1, and when you step by that interval, you won't hit 0.5.

You may have misunderstand - you're right, it isn't reasonable to expect
`exact values' out of 0.1, 0.2, 0.3, etc., in the sense of the values
classically denoted by those terms on paper.  But I believe they do have
specific values of type Double, and it isn't unreasonable to expect the
range to produce those values and not some approximation that may have
been convenient to compute.

I think it's more than reasonable to expect

  [0.1,0.2..0.5] == [0.1,0.2,0.3,0.4,0.5]

and that would make everyone happy, wouldn't it?

If it's expensive to compute, hopefully people won't write code that
makes intensive use of Double range generation.

	Donn



More information about the Haskell-Cafe mailing list