[racket] Inconsistency of `in-range` and numerical issues
While I don't doubt the facts presented below, it just seems wrong, notwithstanding what the standard states.
MUMPS (http://en.wikipedia.org/wiki/MUMPS), my workday language for 30-some years, would never think of acting in such a manner:
s sum=0 f i=1:1:8 s sum=sum+.1
w sum
.8
I gather, though, that such behavior in other languages is typical, correct?
Steve
From: Konrad Hinsen <konrad.hinsen at fastmail.net>
To: Laurent <laurent.orseau at gmail.com>; users <users at racket-lang.org>
Sent: Tuesday, February 24, 2015 10:13 AM
Subject: Re: [racket] Inconsistency of `in-range` and numerical issues
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.
____________________
Racket Users list:
http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150224/e5f2b813/attachment.html>