Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'suddenly': 0.07; 'expense': 0.09; 'integers': 0.09; 'cc:addr :python-list': 0.11; 'arbitrarily': 0.16; 'both)': 0.16; 'complexity,': 0.16; 'digits.': 0.16; 'efficiently,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integers.': 0.16; 'non-integers': 0.16; 'precision,': 0.16; 'subtract': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cheap': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'fraction': 0.24; 'integer': 0.24; 'cc:2**0': 0.24; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(maybe': 0.31; 'division': 0.31; 'subject:size': 0.31; 'types.': 0.31; "can't": 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'data,': 0.36; 'pm,': 0.38; '12,': 0.39; 'sure': 0.39; 'either': 0.39; 'numbers': 0.61; 'simple': 0.61; 'more': 0.64; 'natural': 0.68; 'optimized': 0.68; 'limit': 0.70; '100%': 0.77; 'cpu.': 0.84; 'divide': 0.84; 'to:none': 0.92 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=8rlOgC2P8l/t19FZlWUxyObEnrL1N5256XA4Bpc9HFY=; b=fQVLdsx/Yc4QsnueZY0JWuwaqiA4jUY4YAF2s7j/lqpkPT0cE+YchxyNcXeLljqYWa mGxyO6UBdbpChhUTKtDqAhDZO+f8bG4PCMunuYl3ZgpQTVM0p/kg4pa1ISO3gmCpZTo2 EH15eTi+uM+YBR7505UZj8K2D0JLZ31a0Wg9XQ2/tHMScpZFzrUURnhpc8tNSHV67x5V QSOYtR9eIvfYvXSEzX2MwAXR3+lRw+tAQNCn5QKHuX3QmMFISRDL7eCCAuyz/wBVUa2K 3WvhOA81wInI/Hb/x84/qLPz15bHuyKhYqp7TaO0f1dYNG6YmyiL8fIucKvADFYF7C1P w5/w== MIME-Version: 1.0 X-Received: by 10.66.118.71 with SMTP id kk7mr38011673pab.14.1392197049948; Wed, 12 Feb 2014 01:24:09 -0800 (PST) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <7e7d3200-a4ae-4842-ad8d-68b4435b9006@googlegroups.com> <52f219c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <888bd2fc-54b0-4c46-9d7b-d81d01a78b52@googlegroups.com> <52f59aeb$0$29972$c3e8da3$5496439d@news.astraweb.com> <7cc8f49d-a4c7-48c2-a0af-ac58c847d794@googlegroups.com> <71e578f8-0d23-4b8e-b9f2-b987bdc9c01d@googlegroups.com> Date: Wed, 12 Feb 2014 20:24:09 +1100 Subject: Re: Finding size of Variable 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392197059 news.xs4all.nl 2958 [2001:888:2000:d::a6]:45471 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66019 On Wed, Feb 12, 2014 at 7:57 PM, Jussi Piitulainen wrote: >> In Python, integers have arbitrary precision, but floats, Fractions, >> and Decimals, don't. Nearly any operation on arbitrarily large >> numbers will be either more accurate or more efficient (maybe both) >> with integers than with any of the other types. > > Is that true about Fractions? I'm not 100% sure if fraction.Fraction and decimal.Decimal ever limit the size or precision of their data, but certainly if they don't, it'll be at horrendous expense of performance. (Decimal can add and subtract in reasonable time complexity, but multiplication and division will get slow when you have huge numbers of digits. Fraction can multiply and divide efficiently, but will get crazily slow on addition and subtraction.) Integers are an optimized case in many ways. I can do accurate arbitrary-precision integer arithmetic without worrying about simple operations suddenly saturating the CPU. I can't do that with non-integers in any way. It's not optimized for natural numbers (nonnegative integers), as negatives are just as cheap as positives, but it's certainly an optimization for integers. ChrisA