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
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).
Is q or q1 equal to zero or one of them negative?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With