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: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; '21,': 0.07; 'function,': 0.07; 'lines.': 0.07; 'wrapper': 0.07; 'python': 0.09; 'separately': 0.09; '2.7.3': 0.16; 'doubles.': 0.16; 'subtlety': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'thu,': 0.17; 'windows': 0.19; 'feb': 0.19; 'sort': 0.21; '(on': 0.22; 'subject:problem': 0.22; 'header:In-Reply-To:1': 0.25; 'implemented': 0.27; 'library.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'run': 0.28; 'probably': 0.29; "i'm": 0.29; 'code': 0.31; 'mac': 0.32; 'received:209.85.160.46': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'built-in': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'between': 0.63; 'different': 0.63; 'box,': 0.69; 'hand': 0.82; '2013': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=FF9LPznKWjOvi8/4VfgYT12fjAC1xyLYouHD1Ik3DY0=; b=PHSWfVFrPZoPe7Kp/Q7hR9MwN7bAotvzGf0G0Nc4kAenDbKfyjY2E30icCnxQn82rU UJ3gOb+JpTBhiGWjPTuc53vNlVRjDnWGAqtoluZZICdnNCFOXP2ZLlW2HnCUB/B6B8Wf dt9jJxsFiPxgGoby+GTg/jz9M70s8wavww4Xi58TCk+Oqg0q8Qp1OMxIJzrAntGKdPDS CEEomfsf5HOHP1I4BnFs4Dhs+Q4MbSfgdvDmi20wYBXBcTXcmxjv8HqbWQtRc1BckIZT ctTG5kMi1MhPnDmWcuakCQ08Em0Nv+N3OIrRjSxjOGsayS5PawJh0Jx3TOelEnKZU162 wFBg== X-Received: by 10.68.232.38 with SMTP id tl6mr56730633pbc.153.1361479409376; Thu, 21 Feb 2013 12:43:29 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 21 Feb 2013 13:42:49 -0700 Subject: Re: Confusing math problem To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361479419 news.xs4all.nl 6968 [2001:888:2000:d::a6]:45074 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39454 On Thu, Feb 21, 2013 at 12:33 PM, Schizoid Man wrote: > Hi there, > > I run the following code in Python 3.3.0 (on a Windows 7 machine) and Python > 2.7.3 on a Mac and I get two different results: > > result1 = [] > result2 = [] > for a in range(2,101): > for b in range(2,101): > result1.append(math.pow(a,b)) > result2.append(a**b) > result1 = list(set(result1)) > result2 = list(set(result2)) > print (len(result1)) > print (len(result2)) > > On the Windows box, I get 9183 for on both lines. However, on the Mac I get > 9220 and 9183. Why this difference? Is there some sort of precision subtlety > I'm missing between ** and math.pow()? math.pow is basically a wrapper for the C standard pow function, which operates on doubles. The difference you're seeing is probably a difference in implementation in the platform's C library. The ** operator on the other hand is implemented separately as a Python built-in and operates on any numeric data type.