I get TLE error in codeforces round 647 div 2C because of using log2 instead using bit manipulation for finding 1s in binary representation.

While debugging I find the following problem.

log2 of the number 576460752303423487 is 59.0

while 2^59 is 576460752303423488 (one more)

Hence my while loop wasn’t breaking.( while(n) and n-2^59 =-1)

I can’t understand this unusual behaviour of log. Any help would be approciated.

Here is my solution link if needed

https://codeforces.com/contest/1362/submission/82524801