Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!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: UNSURE 0.201 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.68; '*S*': 0.08; 'diff': 0.05; 'truncated': 0.09; 'zero,': 0.16; 'wrote:': 0.17; 'sorry,': 0.22; 'subject:problem': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'correct': 0.28; 'cases.': 0.29; 'gets': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'members.': 0.33; 'built-in': 0.35; 'pm,': 0.35; 'subject:: ': 0.38; 'shows': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'notice': 0.39; 'received:192.168': 0.40; 'middle': 0.66; 'received:74.208': 0.71; 'casting': 0.84; 'do:': 0.91; 'skip:4 20': 0.91; 'angel': 0.93; 'hand,': 0.97 Date: Thu, 21 Feb 2013 15:49:43 -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> In-Reply-To: <512682B3.8070909@davea.name> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:z3rJilNj9wdZKDsi2pSgFxZlAbEqck+CgHFy7fAtUYF fzG7iuS1QnaPRzD6z39W3FG79xMgpFqFwj+80tg9WZhpLGOJk7 aelRAWRVg0aGj6WQZNyrZctY4Y4egcAEGlOxfHTKZUHQHuAQFw 5tZxy+kOE947PCPRzDzdN7uLde9cn5fQ83AIyTfCujoyyGC1LL lMotc2G7pxET39sPTpj/U5dvF/Hrah+udesShgrTrqRgxtMb2h lyHLZnnXZJ5LmUH701Du2rFdQiy1fdzNw5j59ode6eiaMgRkH2 5XLk1RAOa6oPz8Sob2WrZKm8ihOOI7/rGv9kGf6JP5hyr7+TA= = X-Mailman-Approved-At: Thu, 21 Feb 2013 22:07:58 +0100 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361480880 news.xs4all.nl 6859 [2001:888:2000:d::a6]:58113 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39458 On 02/21/2013 03:25 PM, Dave Angel wrote: > >> >> > a b math.pow(a,b) a**b > 3 34 1.66771816997e+16 16677181699666569 > 3 35 5.0031545099e+16 50031545098999707 > ... > 5 23 1.19209289551e+16 11920928955078125 > > The built-in pow, on the other hand, seems to get identical answers for > all these cases. So use pow() instead of math.pow() > > One other test: > > diff = set(map(int, result1)).symmetric_difference(set(result2)) > if diff: > print diff > print len(diff) > > shows me a diff set of 15656 members. One such member: > > 13552527156068805425093160010874271392822265625000000000000000000000000000000000000000000000000000000000000000000L > > > Notice how using floats truncated lots of the digits in the value? Sorry, I just rechecked, and that value is correct for 50**66 power. However, if I do: print 3**60, "\n", int(math.pow(3,60)), "\n", pow(3,60) I get: 42391158275216203514294433201 42391158275216203520420085760 42391158275216203514294433201 and the middle one is the one that's wrong. You can tell by casting out 9's. The middle one gets 1 instead of zero, showing that it's NOT divisible by 3. -- DaveA