Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jan 2018 08:52:54 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Yuri Pankov <yuripv@icloud.com>
Cc:        freebsd-current <freebsd-current@freebsd.org>
Subject:   Re: inconsistent for() and while() behavior when using floating point
Message-ID:  <CANCZdfp%2BjAK3KgG7mq9nQCEJqDHiY=HvVbA8B6KmR6ezWRsR-g@mail.gmail.com>
In-Reply-To: <6c423dbf-cd85-3c93-41e4-3362c06dfbb7@icloud.com>
References:  <6c423dbf-cd85-3c93-41e4-3362c06dfbb7@icloud.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 15, 2018 at 7:38 AM, Yuri Pankov <yuripv@icloud.com> wrote:

> Is this a known problem with loops and floating point numbers?
>

Yes. Many exact fractions in base-10 aren't exact in base-2, so you get
accumulation of errors based on the tiny difference and see behavior like
this. This is totally expected. You have to work around the problem using a
computation method that doesn't accumulate errors.

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfp%2BjAK3KgG7mq9nQCEJqDHiY=HvVbA8B6KmR6ezWRsR-g>