Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'essentially': 0.04; 'binary': 0.07; 'float': 0.07; 'interpreted': 0.09; 'performs': 0.09; 'subject:module': 0.09; 'cc:addr:python-list': 0.11; 'wrote': 0.14; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'introduces': 0.16; 'skip:d 60': 0.16; 'str()': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'value.': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'primary': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'assumes': 0.31; 'decimal': 0.31; 'probably': 0.32; 'entirely': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'module.': 0.36; 'doing': 0.36; 'should': 0.36; 'sure': 0.39; "you'll": 0.62; 'making': 0.63; 'kind': 0.63; 'talking': 0.65; 'to:addr:gmail.com': 0.65; 'experiment': 0.84; 'oscar': 0.84; 'reasoning': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Nb49nWrPBybfQEAEq5FDYYjtpOduh8aPnTysngmfB4E=; b=El73Pbj9OebHDhjuyYCTKtvDGW16hJZrfIc/F6agQej7H8OiKsNaUphI+dmu0d9Zd5 D8Fu1riOn8qfYm0Iq6ZdLo4Bma2l5AIuWGKopP6KUXukDGpukwCDIcwDScjDBRpKvK3w TEEyXQCGs5uBtznsDmzFEyNruE497/y7oW2/O3ruTwhzG605AztXeEpgcB+5htVDlYhE SYhYMLvzYXdeAtoW0UdxxI2syTIjGUf0j5dokRXWgWaABQAzsw0ingIDdiD6HNvnguuu U6ckuqc5brZdHE/5z938WlBRD0x+FStLXt67am9B29hRQEI/b2pZmMrnWHEHpJuVk3LJ 0uDw== X-Received: by 10.58.178.238 with SMTP id db14mr12895101vec.25.1393545075379; Thu, 27 Feb 2014 15:51:15 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <9f7b535f-9e5d-45df-96f6-6cd8f6b4a524@googlegroups.com> References: <02cdd9c7-aef7-4cc7-a813-cd1c9627ceb4@googlegroups.com> <94b1962a-0004-4c5b-b484-972a166b88b5@googlegroups.com> <55525f2c-fd3a-4927-b642-2dbf5eae7e9b@googlegroups.com> <360e87d2-4daf-4222-8ebe-51f3e4d1fade@googlegroups.com> <9f7b535f-9e5d-45df-96f6-6cd8f6b4a524@googlegroups.com> From: Oscar Benjamin Date: Thu, 27 Feb 2014 23:50:55 +0000 Subject: Re: extend methods of decimal module To: "Mark H. Harris" Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393545085 news.xs4all.nl 2845 [2001:888:2000:d::a6]:50520 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67179 On 27 February 2014 23:00, Mark H. Harris wrote: > On Thursday, February 27, 2014 10:24:23 AM UTC-6, Oscar Benjamin wrote: > >>>>> from decimal import Decimal as D >> >>> D(0.1) >> Decimal('0.1000000000000000055511151231257827021181583404541015625') > > hi Oscar, well, that's not what I'm doing with my D()... I'm not just making D() mimic Decimal... look inside it... there's a str() call.... consider the following experiment and you'll see what I'm talking about... I understood what your code is doing but I'm not sure if you do. Calling str on a float performs an inexact binary to decimal conversion. Calling Decimal on a float performs an exact binary to decimal conversion. Your reasoning essentially assumes that every float should be interpreted as an approximate representation for a nearby decimal value. This is probably true if the user wrote "a = 0.1" but is generally not true in the kind of numeric code that is likely to be using the transcendental functions defined in your dmath module. Calling Decimal(str(float)) introduces entirely avoidable inaccuracy in your code when the primary purpose of your code as accuracy! Oscar