Confusing math problem
Dave Angel
davea at davea.name
Thu Feb 21 15:49:43 EST 2013
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
More information about the Python-list
mailing list