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

From: Laurent (laurent.orseau at gmail.com)
Date: Tue Feb 24 13:29:38 EST 2015

Thanks for you detailed explanation Konrad.

I'm surprised I didn't encounter this problem before–or most probably the
last time was just so long ago that I don't remember it. A wakeup call for
floating-point issues I suppose. Fortunately Racket offers rational numbers!

On Tue, Feb 24, 2015 at 6:13 PM, Konrad Hinsen <konrad.hinsen at fastmail.net>
wrote:

> On 24/02/2015 17:04, Laurent wrote:
>
>  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.
>>
>
> It's not just your machine. 0.1 = 1/10 does not have an exact
> representation as a binary floating-point number. It gets rounded to the
> nearest binary float value, which is smaller than 0.1. This is the correct
> behavior according to IEEE 754.
>
> Konrad.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150224/f710ac95/attachment-0001.html>

Posted on the users mailing list.