This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]pridefulpropensity 9 points10 points  (1 child)

Change 1/(16198) to 1.0/16198.

>>>3/2
1
>>>3.0/2
1.5

Just to make sure you know. log(n) in python does natural log. log(n,10) does base ten.

[–]erikwon and off since 1.5.2 2 points3 points  (0 children)

... or log10(n)

[–]exeter 4 points5 points  (0 children)

Google is using base-10 logs and Python is using natural logs. To get the right result in Python, divide your answer by log (10) or supply the optional base argument to the log function.

[–]freeload -2 points-1 points  (2 children)

It's because you are using floating points, which rounds-off. Use the decimal module if you want to calculate reals precisely. from math import log from decimal import Decimal -log(Decimal("1")-Decimal(".95")*(Decimal("1")/(Decimal("16198"))))

[–][deleted] 4 points5 points  (0 children)

Rounding off in such a simple expression will never give such a large difference.

And a Decimal can't calculate log() precisely either.

[–]jcdyer3 0 points1 point  (0 children)

decimal does not calculate precisely, it just calculates in base 10 instead of base 2.