i want to find out a log10 of an integer in python and i get an error like math domain error
my code is this w=math.log10(q*q1)/math.log10(2)
where q1,q2 are integers
yeah q1 is 0 sometimes
i want to find out a log10 of an integer in python and i get an error like math domain error
my code is this w=math.log10(q*q1)/math.log10(2)
where q1,q2 are integers
yeah q1 is 0 sometimes
math.log10(0) is minus infinity. See: http://en.wikipedia.org/wiki/Logarithm
You can only compute the logarithm of a positive number. Trying to compute the logarithm for a negative number or zero will result in a "math domain error" in Python.
By the way: it looks like you're actually trying to compute a logarithm base 2. You can do this with math.log
:
w=math.log(q*q1, 2)
The second, optional, parameter is the base. It defaults to e (ie: natural log).