Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39458

Re: Confusing math problem

Date 2013-02-21 15:49 -0500
From Dave Angel <davea@davea.name>
Subject Re: Confusing math problem
References <kg5sog$lfb$1@dont-email.me> <512682B3.8070909@davea.name>
Newsgroups comp.lang.python
Message-ID <mailman.2196.1361480880.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 02/21/2013 03:25 PM, Dave Angel wrote:
>
>>    <snip>
>>
>   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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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