Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39454
| References | <kg5sog$lfb$1@dont-email.me> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2013-02-21 13:42 -0700 |
| Subject | Re: Confusing math problem |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2192.1361479419.2939.python-list@python.org> (permalink) |
On Thu, Feb 21, 2013 at 12:33 PM, Schizoid Man <schiz_man@21stcentury.com> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 19:33 +0000
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 15:25 -0500
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 22:39 +0000
Re: Confusing math problem Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-21 22:53 +0000
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 23:41 +0000
Re: Confusing math problem Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-22 00:04 +0000
Re: Confusing math problem Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 17:19 -0700
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 23:39 +0000
Re: Confusing math problem Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 13:42 -0700
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 07:46 +1100
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 22:44 +0000
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 11:29 +1100
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 21:19 -0500
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 15:49 -0500
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 08:23 +1100
Re: Confusing math problem Peter Pearson <ppearson@nowhere.invalid> - 2013-02-21 21:59 +0000
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 09:11 +1100
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 17:33 -0500
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 10:15 +1100
Re: Confusing math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 09:16 +0000
Re: Confusing math problem Serhiy Storchaka <storchaka@gmail.com> - 2013-02-22 13:48 +0200
Re: Confusing math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 09:27 +0000
csiph-web