Possible Duplicate:
Inaccurate Logarithm in Python
Why are the math.log10(x) and math.log(x,10) results different?
In [1]: from math import *
In [2]: log10(1000)
Out[2]: 3.0
In [3]: log(1000,10)
Out[3]: 2.9999999999999996
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
math.log10andmath.log(x, 10)are using different algorithm, and the former is usually more accurate. Actually, it’s a known issue(Issue6765): math.log, log10 inconsistency.One may think in this way:
log10(x)has a fixed base, hence it can be computed directly by some mathematical approximation formula(e.g. Taylor series), whilelog(x, 10)comes from a more general formula with two variables, which may be indirectly calculated bylog(x) / log(10)(at least the precision of log(10) will affect the precision of quotient). So it’s natural that the former way is both faster and more accurate, and that is reasonable considering that it takes advantage of a pre-known logarithmic base(i.e. 10).