I was working with numbers up to 2100000. I am stuck at this point. Some of the numbers are not giving correct result as in the title:
>>> math.log(2**5910, 2)
5909.99999999999
>>> math.log(2**5910-1,2)
5909.99999999999
>>> math.log(2**5910+1,2)
5909.99999999999
How can i differentiate between log2(2^5910-1), log2(2^5910), log2(2^5910+1)? What I want is the characteristic of log2(n) to be exactly correct and I don't care about preciseness of mantissa. But it should give an integer in case of perfect power or atleast tell its a perfect power or not. Currently I am using this function:
def log(n):
c=int.bit_length(n)-1
m=0.5
if(2**c==n):m=0
return c,m