[racket] Inconsistency of `in-range` and numerical issues
One such safe guard could be:
(length (for/list ([i (in-range (inexact->exact .1) (inexact->exact .8)
(inexact->exact .1))]) i)) ; 7
But of course that slows things down.
Btw, the reason it outputs 8 in the bad case is because on my machine:
(for/sum ([i 8]) .1) ; 0.7999999999999999
which is then below the .8 threshold.
On Tue, Feb 24, 2015 at 3:41 PM, 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`?
>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150224/3fd96e76/attachment.html>