Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'importing': 0.05; 'say,': 0.05; 'binary': 0.07; 'cache': 0.07; '0.1': 0.09; 'arguments': 0.09; 'literal': 0.09; 'subject:module': 0.09; 'type,': 0.09; 'windows,': 0.09; 'yeah,': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; "'d',": 0.16; '(when': 0.16; '0.1b': 0.16; '<>?': 0.16; 'cards.': 0.16; 'decimal.': 0.16; 'decimal;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literals': 0.16; 'non-built- in': 0.16; 'notation,': 0.16; 'notation.': 0.16; 'numpy': 0.16; 'sorts': 0.16; 'tag,': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'discussion': 0.18; 'all,': 0.19; 'module': 0.19; 'feb': 0.22; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'load': 0.23; 'certainly': 0.24; 'string,': 0.24; 'typical': 0.24; 'file.': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'array': 0.29; 'topic': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'steven': 0.31; 'types.': 0.31; 'probably': 0.32; 'linux': 0.33; 'becomes': 0.33; 'fri,': 0.33; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'disk': 0.36; 'half': 0.37; 'seconds': 0.37; 'skip:4 10': 0.37; 'too': 0.37; 'pm,': 0.38; 'does': 0.39; 'bad': 0.39; 'extremely': 0.39; 'enough': 0.39; 'either': 0.39; 'users': 0.40; 'how': 0.40; 'affect': 0.61; 'here:': 0.62; 'box,': 0.64; 'believe': 0.68; 'default': 0.69; 'special': 0.74; 'float,': 0.84; 'heh.': 0.84; 'maybe,': 0.84; 'quicker': 0.84; 'sides.': 0.84; 'bless': 0.91; 'notion': 0.91; 'to:none': 0.92; 'average': 0.93 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:cc :content-type; bh=nL207G3fhUjxPDez1D9Gvxb3w7gq5q/HVHiAZ/Bb04Q=; b=gVDKBK6KCJ5AhlR8qION7vDzscOUQI64xXP1FUfX+56QKc3KACGaPlY4tMI3VJu4SD l8gRbK0agf7koHTz1Sq/donbccB5m6uOfUKFVVG1u7nZiWkFraQH3a3jipamuQjialG0 ednC1GCnQ4RcZzML765hqmbD97Mdz0hMdbBDBn+NvnR3Dun2y7tV2dE5Z3v7wNaaiB1/ QzOHue/BZCZzYW0IOSGVE08feDfeqiWZ2r9Lp7eDr2QCjoZRF/asTp1rvuX2CzE35m0K yn2smO1wEDwOYmuUe0tS5Nar6XUTALYghyPDWc5+macoY0scrVV6sWaQaTPCPetc9gVj EjKA== MIME-Version: 1.0 X-Received: by 10.66.102.39 with SMTP id fl7mr2090242pab.43.1393577565705; Fri, 28 Feb 2014 00:52:45 -0800 (PST) In-Reply-To: <53103c03$0$11113$c3e8da3@news.astraweb.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> <530fff58$0$11113$c3e8da3@news.astraweb.com> <53103c03$0$11113$c3e8da3@news.astraweb.com> Date: Fri, 28 Feb 2014 19:52:45 +1100 Subject: Re: extend methods of decimal module From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393577568 news.xs4all.nl 2960 [2001:888:2000:d::a6]:33111 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67208 On Fri, Feb 28, 2014 at 6:34 PM, Steven D'Aprano wrote: > On Fri, 28 Feb 2014 16:00:10 +1100, Chris Angelico wrote: > >> If we had some other tag, like 'd', we could actually construct a >> Decimal straight from the source code. Since source code is a string, >> it'll be constructed from that string, and it'll never go via float. > > Now that Python has a fast C implementation of Decimal, I would be happy > for Python 4000 to default to decimal floats, and require special syntax > for binary floats. Say, 0.1b if you want a binary float, and 0.1 for a > decimal. Maybe, but I believe the cdecimal module is still slower than typical floating point. There'd also be considerations regarding NumPy and how you'd go about working with an array of non-integer values, and so on. Certainly this will be an extremely reasonable topic of discussion once there's any notion of a Py4K on the cards. There'll be arguments on both sides. > But for now, backwards-compatibility requires that the default floating > point type remains binary float. But we could maybe agitate for a 1.234d > Decimal literal type. Care to write a PEP? > > :-) Heh. Strong consideration here: it would mean importing the decimal module on startup. >>> t=time.time(); import decimal; time.time()-t 4.5000159740448 >>> t=time.time(); import decimal; time.time()-t 0.0 A dummy import (when it's already loaded) is so fast that it's immeasurable, but four and a half seconds to load up decimal? This is 3.4.0b2 on Windows, btw. It was a lot quicker on my Linux box, probably because the OS or disk cache had the file. So maybe it wouldn't be too bad in practice; but it's still a cost to consider. >> The question is how far Python wants to bless the Decimal type with >> syntax - after all, if Decimal can get a literal notation, why can't >> Fraction, and why can't all sorts of other types? And that's a huge can >> of worms. > > I like Fractions, but I don't think they're important enough for the > average users to require literal notation. Yeah, but where do you draw the line? Either decimal.Decimal becomes a built-in type, or there needs to be a system for constructing literals of non-built-in types. And if Decimal becomes built-in, then why that and not <>? Also, if Decimal becomes a built-in type, does that affect the numeric tower? ChrisA