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

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Tue Feb 24 13:13:51 EST 2015

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.


Posted on the users mailing list.