Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'algorithm': 0.03; 'versions,': 0.05; 'python': 0.09; 'calculates': 0.09; 'calculating': 0.09; "they've": 0.09; 'used)': 0.09; 'whichever': 0.09; 'times,': 0.13; 'library': 0.15; '(note,': 0.16; '53-bit': 0.16; 'how,': 0.16; 'one-element': 0.16; 'wrote:': 0.17; 'documented': 0.17; 'integer': 0.17; 'processor': 0.17; 'math': 0.20; 'combination': 0.22; 'subject:problem': 0.22; "python's": 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(as': 0.27; 'set.': 0.27; 'chris': 0.28; 'case,': 0.29; 'that.': 0.30; 'figure': 0.30; 'point': 0.31; 'to:addr:python-list': 0.33; 'likely': 0.33; 'operations': 0.33; 'times.': 0.33; "can't": 0.34; 'done': 0.34; 'pm,': 0.35; 'but': 0.36; 'does': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'between': 0.63; 'different': 0.63; 'more': 0.63; 'therefore': 0.65; 'total': 0.65; 'answer.': 0.71; 'received:74.208': 0.71; 'power': 0.74; 'square': 0.75; '128,': 0.84; 'multiply': 0.84; 'multiplying': 0.84; 'route': 0.84 Date: Thu, 21 Feb 2013 17:33:59 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Confusing math problem References: <512682B3.8070909@davea.name> <51268867.1000800@davea.name> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:DWfLkOPkyOrNjA3OLf5TssjEST2H6FMDQN2icJu3c8x s9y8FV/tsChp6QhJhNFfRnw/lvZy2ZADjQpeKm+ZeDgV8Wby2d //TGENxj5kz82P2Z9P3dLU4l6dgrrLrHgv9VVEB+o8mc9sfQNE 49hGgfERys+Dpbjk6K+6Wy5V4ULiXYMH2+/7NxzCdEaCXYulJ3 4xmof+CCCICiUvRxgp8p8zqy+PLnBrZSEmPNnAOc+U/Yqwpknx 3IVxRq4C8qEJnkre4aEZEd7uFS4biY5UzpzIeRAQOx89kS7G7A kW7yhOh5AR6yX7KNkd9wLFcxHLy9D/+7wwY/ux6hri1MTaC8A= = 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361486050 news.xs4all.nl 6987 [2001:888:2000:d::a6]:34637 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39477 On 02/21/2013 05:11 PM, Chris Angelico wrote: > >> > > Note how, in each case, calculating three powers that have the same > real-number result gives a one-element set. Three to the sixtieth > power can't be perfectly rendered with a 53-bit mantissa, but it's > rendered the same way whichever route is used to calculate it. > But you don't know how the floating point math library (note, it's the machine's C-library, not Python's that used) actually calculates that. For example, if they were to calculate 2**64 by squaring the number 6 times, that's likely to give a different answer than multiplying by 2 63 times. And you don't know how the library does it. For any integer power up to 128, you can do a combination of square and multiply so that the total operations are never more than 13, more or less. But if you then figure a = a*a and b = b/2, and do the same optimization, you might not do them exactly in the same order, and therefore might not get exactly the same answer. Even if it's being done in the coprocessor inside the Pentium, we don't have a documented algorithm for it. Professor Kahn helped with the 8087, but I know they've tweaked their algorithms over the years (as well as repairing bugs). So it might not be a difference between Python versions, nor between OS's, but between processor chips. -- DaveA