Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'argument': 0.05; 'clean.': 0.09; 'curve': 0.09; 'cc:addr:python-list': 0.11; 'wrote': 0.14; 'did.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'low.': 0.16; 'opposite': 0.16; 'subject:String': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'this:': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; 'factor': 0.31; 'sep': 0.31; 'subject:numbers': 0.31; 'another': 0.32; 'something': 0.35; 'received:google.com': 0.35; 'so,': 0.37; 'too': 0.37; 'sometimes': 0.38; 'needed': 0.38; 'pm,': 0.38; 'changed': 0.39; 'enough': 0.39; 'dave': 0.60; 'high': 0.63; 'close': 0.67; 'slope': 0.84; 'trig': 0.84; 'angel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=gHp9F3Wslp8ww+MNQ3K5HaWHHfA468gvtnbW6kXrIWw=; b=d3HrdH/e0DuXC/pxrRCj62knHg4e0ZVmvNqPTIKlbnczqI5Ydp4XsJRUazxEGGPV4F gx19iLJRCrdGsOXeT5058q86WRS2qkqO1ObeMet070WSa4iK7bjK4OlvUoY0+sEKIOd8 lqMK9mNgVbUxOX9yvo5zdSWZMTNL/Vvccu70msTzoc+hWBnLvRZ0szN4ZFKkosGK85WH dKT2pOy+MVFuIpf9HG8hPVegd+w3ATPr1JFQztkPVz4W/+zBccwF+j7/jEEI3dRd6Vvy ViMw8FhvyIP9TFAdfU0hg/saw4ZFsrVDFkf0yPJwcLklzd79n+rDHBrLvAp1nAo1wV2O u20g== MIME-Version: 1.0 X-Received: by 10.42.92.129 with SMTP id t1mr18011328icm.59.1411649167178; Thu, 25 Sep 2014 05:46:07 -0700 (PDT) In-Reply-To: References: Date: Thu, 25 Sep 2014 22:46:07 +1000 Subject: Re: String representations of numbers and approximate equality From: Chris Angelico To: Dave Angel Content-Type: text/plain; charset=UTF-8 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411649176 news.xs4all.nl 2856 [2001:888:2000:d::a6]:45683 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78339 On Thu, Sep 25, 2014 at 10:40 PM, Dave Angel wrote: > Another approach is to see if twiddling the last digit gets you > from too high to too low. I used this approach to check a trig > package I wrote in '75. An answer was close enough if twiddling > the last digit changed the result value from too high to too low, > or if twiddling the last digit of the argument did. I needed to > go both ways because the curve sometimes had a slope greater than > one. Ooh, that sounds clean. So, something like this: if x * FACTOR > y: reduce_last_digit_of_x if x * FACTOR > y: error otherwise do the opposite check ? That's pretty doable. ChrisA