[Haskell-cafe] instance Enum Double considered not entirely great?

Lennart Augustsson lennart at augustsson.net
Mon Sep 26 18:53:59 CEST 2011


If you do [0.1, 0.2 .. 0.3] it should leave out 0.3.  This is floating point
numbers and if you don't understand them, then don't use them.  The current
behaviour of .. for floating point is totally broken, IMO.

  -- Lennart

On Fri, Sep 23, 2011 at 6:06 AM, Chris Smith <cdsmith at gmail.com> wrote:

> On Fri, 2011-09-23 at 11:02 +1200, Richard O'Keefe wrote:
> > I do think that '..' syntax for Float and Double could be useful,
> > but the actual definition is such that, well, words fail me.
> > [1.0..3.5] => [1.0,2.0,3.0,4.0] ????  Why did anyone ever think
> > _that_ was a good idea?
>
> In case you meant that as a question, the reason is this:
>
>    Prelude> [0.1, 0.2 .. 0.3]
>    [0.1,0.2,0.30000000000000004]
>
> Because of rounding error, an implementation that meets your proposed
> law would have left out 0.3 from that sequence, when of course it was
> intended to be there.  This is messy for the properties you want to
> state, but it's almost surely the right thing to do in practice.  If the
> list is longer, then the most likely way to get it right is to follow
> the behavior as currently specified.  Of course it's messy, but the
> world is a messy place, especially when it comes to floating point
> arithmetic.
>
> If you can clear this up with a better explanation of the properties,
> great!  But if you can't, then we ought to reject the kind of thinking
> that would remove useful behavior when it doesn't fit some theoretical
> properties that looked nice until you consider the edge cases.
>
> --
> Chris
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110926/7d80eb6f/attachment.htm>


More information about the Haskell-Cafe mailing list