Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78339

Re: String representations of numbers and approximate equality

References <CAPTjJmpOxK5xosvk-=0nBdpsXoEwoSj5qEyY5pf1yFS2PbEoww@mail.gmail.com> <lvv7fq$dem$1@ger.gmane.org> <CAPTjJmpd6unM-FR80XioDK892sKzH4+cD-g=F3G9W4-EvKFcOQ@mail.gmail.com> <m012b4$ase$1@ger.gmane.org>
Date 2014-09-25 22:46 +1000
Subject Re: String representations of numbers and approximate equality
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14357.1411649176.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Sep 25, 2014 at 10:40 PM, Dave Angel <davea@davea.name> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: String representations of numbers and approximate equality Chris Angelico <rosuav@gmail.com> - 2014-09-25 22:46 +1000

csiph-web