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


Groups > comp.lang.python > #85659

Re: Floating point "g" format not stripping trailing zeros

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'subject:not': 0.03; 'algorithm': 0.04; 'binary': 0.07; 'context': 0.07; 'float': 0.07; 'needed,': 0.07; 'bits': 0.09; 'formatting': 0.09; 'indicates': 0.09; 'logic': 0.09; 'mess': 0.09; 'trailing': 0.09; 'wrote': 0.14; 'thread': 0.14; 'developing,': 0.16; 'does,': 0.16; 'exponent': 0.16; 'jumping': 0.16; 'precision,': 0.16; 'precision.': 0.16; 'relevant.': 0.16; 'rounding': 0.16; 'sign.': 0.16; 'subject:format': 0.16; 'zero.': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'written': 0.21; 'separate': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'algorithms.': 0.24; 'possess': 0.24; 'decide': 0.24; 'math': 0.24; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'correct': 0.29; 'fixed': 0.29; 'compared': 0.30; 'important.': 0.30; '(on': 0.31; 'decimal': 0.31; 'another': 0.32; 'up.': 0.33; 'ago': 0.33; 'maybe': 0.34; 'could': 0.34; 'but': 0.35; 'accuracy': 0.36; 'done': 0.36; "didn't": 0.36; 'example,': 0.37; 'too': 0.37; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'realize': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'ian': 0.60; 'most': 0.60; 'tell': 0.60; 'length': 0.61; 'simple': 0.61; 'times': 0.62; 'within': 0.65; 'due': 0.66; 'bothered': 0.68; 'received:74.208': 0.68; 'results': 0.69; 'therefore': 0.72; 'analysis': 0.75; '100': 0.79; 'calculations': 0.84; 'end.': 0.84; 'fast,': 0.84; 'fourth': 0.84; 'edwards': 0.91; 'deal,': 0.93; 'hand,': 0.93
Date Fri, 13 Feb 2015 16:15:08 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Floating point "g" format not stripping trailing zeros
References <CAK291fpAycSecNuV6hDnVXK+rhB0CWJTAuC3BKNUz8B4aDg2kQ@mail.gmail.com> <CAK291fpKxW_V=yCvNHj9RRoEhC=i_DYJCa9-cbjxDwRwH4-KfQ@mail.gmail.com> <mailman.18715.1423784816.18130.python-list@python.org> <mbl04r$kb6$1@reader1.panix.com> <mailman.18731.1423846637.18130.python-list@python.org> <mbln2c$9k5$1@reader1.panix.com>
In-Reply-To <mbln2c$9k5$1@reader1.panix.com>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:VoC4cKQdp2Xx14mfF1X5l1r4AdStV+jM4gWB2u368Ly h4YPvYwjuA1XIorb3xDJYf2vDNNJq1xj2LM1Sm8VVofL+SxJ7J mLPC9vcIImyqITkIzBtA6tkVaNij4EL4gZxFkYShSkWZkSDZ6i XIata3s8uHTFUeXBf13ewJu+1ZJOerRHiyziwLi1vf/kQSzcj7 bZHLqMkh2vB2x8nsMZmoqB2BtdpbzRUlktywkpSYCIQioF8/Dk nCvoidrQMD9q96UvtJ0suLmpzwovzH95r4PGQlu1+2HiANRP93 aMY5J1ll8ngeUQfOomK7NezDrIrpW25ubcF8ho/J1bZKJm9HSB D/HtOE0k8ZuQhCs4z56w=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18734.1423862121.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1423862121 news.xs4all.nl 2847 [2001:888:2000:d::a6]:50446
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 6171
X-Received-Body-CRC 4191039235
Xref csiph.com comp.lang.python:85659

Show key headers only | View raw


On 02/13/2015 03:33 PM, Grant Edwards wrote:
> On 2015-02-13, Ian Kelly <ian.g.kelly@gmail.com> wrote:

>> Significant digits are within the precision of the calculation.
>> Writing 1.230 indicates that the fourth digit is known to be zero.
>> Writing 1.23 outside a context of exact calculation indicates that the
>> fourth digit is unknown due to insufficient precision.
>
> I knew that, but I was asking in the context of float/decimal's
> formatting function.  I didn't realize that float and/or decimal had a
> "significant digit" property, and therefore possess significant vs.
> insignificant trailing zeros when represented in base-10.
>

Just jumping in here, and somebody please correct me if I mess it up.

Built-in binary floating point (float) has a fixed number of bits for 
mantissa, and separate bits for exponent and sign.  Because of those 
fixed number of bits, no assumption can be made as to how many of them 
are relevant.

On the other hand, the Decimal package has a way that the programmer can 
tell how many digits to use at each stage of the calculation.  So if the 
programmer bothered to set it to the correct precision, the print logic 
(could) use that to decide about trailing zeroes.  I have no idea 
whether it does, but this thread would seem to say it does.

I also have no definite opinion as to whether that's reasonable, or 
whether most calculations are done by setting digits to about twice 
what's needed, and rounding at the end.  I know I did exactly that when 
I wrote a variable length math package to double-check the accuracy of a 
fixed precision package I was developing, 40 years ago  (long before the 
IEEE-754 standard began meetings).  The fixed precision package was 
fast, and used lots of clever(?) shortcuts for speed.  The variable one 
was written very brute force, ran maybe 100 times slower (on another 
machine), but the results could be compared with automatic algorithms. 
For simple arithmetic, not too big a deal, but for transcendentals, the 
error analysis was very important.  For example, the fast algorithm was 
a custom chebyshev, while the reference implementation was Taylor series.

-- 
DaveA

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


Thread

Re: Floating point "g" format not stripping trailing zeros Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-12 16:46 -0700
  Re: Floating point "g" format not stripping trailing zeros Grant Edwards <invalid@invalid.invalid> - 2015-02-13 14:02 +0000
    Re: Floating point "g" format not stripping trailing zeros Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-13 09:56 -0700
      Re: Floating point "g" format not stripping trailing zeros Grant Edwards <invalid@invalid.invalid> - 2015-02-13 20:33 +0000
        Re: Floating point "g" format not stripping trailing zeros Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-13 14:01 -0700
        Re: Floating point "g" format not stripping trailing zeros Dave Angel <davea@davea.name> - 2015-02-13 16:15 -0500
          Re: Floating point "g" format not stripping trailing zeros Grant Edwards <invalid@invalid.invalid> - 2015-02-13 21:22 +0000
            Re: Floating point "g" format not stripping trailing zeros Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-13 14:40 -0700
            Re: Floating point "g" format not stripping trailing zeros Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-13 14:49 -0700

csiph-web