From owner-freebsd-current@freebsd.org Mon Jan 15 15:52:56 2018 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E4678EB6544 for ; Mon, 15 Jan 2018 15:52:56 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com [IPv6:2a00:1450:400c:c09::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7736D7DA60 for ; Mon, 15 Jan 2018 15:52:56 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-wm0-x22c.google.com with SMTP id r78so2940054wme.0 for ; Mon, 15 Jan 2018 07:52:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=KFmRWaurjkFJMFpyNwJxmgzzu812gsUTBXIad3uqG0k=; b=t50i70Bp3B8zsoY2ibUKOMnqntaRRTbpMRuHKv708O5d4OGGpromu7yLqSlkLds9yK zFOk9bvnrKaDyJwKxFakEbczOOGbhdAh5KsinAP/SDMnIv/6vS9GQM9mFpcjloK5vvmO 5n2WuaInvIq4cteiinDE12zOmnwmLxiW8YHZ5ZCdFkv/diWyhB3Te9q+mSjUAIb93wdM 1bh9k+IX2PaohiM4JVwHnhbS2KclHva+/g4b6C/4kkIUP6SAPE3Bi1wKpDnM/925zesQ /lOaq44LTAo0D55k/leLw5ZAoLYcdeLfQBIcHvy4x4nEPrAoiR7AMELJb0Ji81iYrMPB Ospw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=KFmRWaurjkFJMFpyNwJxmgzzu812gsUTBXIad3uqG0k=; b=aenpM2fHf0SQQlx0vUsBZlBP9XTKraRqf9+yXN9LaU9MKY+d0daeiLGTzre4fXt9Lt siB2rY6ZVPFxKl7IwEiLcZcbIkr/9ypxn0zUDpl/4U4u5x4kNy5ObiH9VHOtxSyQ+tRw lrhVYKPMQ/Ugw6Ugbf/VpJnDJ45OI9Xv1N9DjENIfcophQwmdahOx48DesrNhGThcK0C TE6tEN9lBeQPIbbJy0EUUHUoVZ09VIzs19BrYK3MaWrOSimh0RHnIm/bXhiZzJuP+/tu bYVqQ/nOBZ4HhtjgCkuBUZ+0cYzvh98hTGAccsjubt109zhlKXqsQVTWPazkQ6kup04D H3Iw== X-Gm-Message-State: AKwxytdStOc0lUcZ1f68AG9nw3+ErCM7jRhDJxJgVjyMCid89Cldo5EO bhZ3e2Is0ZnU7t9hIptpp37vdMSHEveIH0KdsCdM6g== X-Google-Smtp-Source: ACJfBosMdNJHT9B7xSVY+EmB//G8EwckyGlZWlcPCKUw5rkNqIT0AuMD5nZWYGLnmiP809EjY+NjcB8g8ft7veCuPWk= X-Received: by 10.80.130.2 with SMTP id 2mr17063436edf.7.1516031574748; Mon, 15 Jan 2018 07:52:54 -0800 (PST) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.80.195.88 with HTTP; Mon, 15 Jan 2018 07:52:54 -0800 (PST) X-Originating-IP: [50.253.99.174] In-Reply-To: <6c423dbf-cd85-3c93-41e4-3362c06dfbb7@icloud.com> References: <6c423dbf-cd85-3c93-41e4-3362c06dfbb7@icloud.com> From: Warner Losh Date: Mon, 15 Jan 2018 08:52:54 -0700 X-Google-Sender-Auth: M0v8U0rO1IxdQHWcpyEPoWx-gwY Message-ID: Subject: Re: inconsistent for() and while() behavior when using floating point To: Yuri Pankov Cc: freebsd-current Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jan 2018 15:52:57 -0000 On Mon, Jan 15, 2018 at 7:38 AM, Yuri Pankov 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