tags:

views:

437

answers:

3

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

+1  A: 

Is q or q1 equal to zero or one of them negative?

Mitch Wheat
thanks very silly of me !!
mekasperasky
A: 

math.log10(0) is minus infinity. See: http://en.wikipedia.org/wiki/Logarithm

jacob
+5  A: 

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).

Laurence Gonsalves