[racket] Inconsistency of `in-range` and numerical issues

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Feb 24 13:31:36 EST 2015

I am not offended. I am saddened. 


On Feb 24, 2015, at 1:25 PM, Andrew Kent <andmkent at indiana.edu> wrote:

> I just grabbed two separate witnesses showing the result of the relevant floating point math - I apologize for any offense.
> 
> On Tue Feb 24 2015 at 1:15:01 PM Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> 
> That's the saddest argument in support of anything Racket I have ever seen (even with the smiley).
> 
> 
> On Feb 24, 2015, at 1:05 PM, Andrew Kent <andmkent at indiana.edu> wrote:
> 
> > Racket:
> > (+ .1 .1 .1 .1 .1 .1 .1 .1)
> > 0.7999999999999999
> >
> > Python:
> > >>> .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1
> >
> > 0.7999999999999999
> >
> > Looks consistent to me =)
> >
> >
> > On Tue Feb 24 2015 at 10:43:19 AM Laurent <laurent.orseau at gmail.com> wrote:
> > I've discovered a rather troubling behaviour when using `in-range` with floating point numbers, which I think is worth knowing in case you hadn't consider the issue before:
> >
> > On my machine, I get the following:
> >
> > (length (for/list ([i (in-range .1 .7 .1)]) i)) ; 6
> > (length (for/list ([i (in-range .1 .8 .1)]) i)) ; 8 (!)
> >
> > But:
> > (length (for/list ([i (in-range 1/10 7/10 1/10)]) i)) ; 6
> > (length (for/list ([i (in-range 1/10 8/10 1/10)]) i)) ; 7
> >
> >
> > Would it be a good idea to safe-guard these kinds of cases directly in `in-range`?
> >
> >
> >
> >
> >
> >
> >
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
> 



Posted on the users mailing list.