Help needed codeforces round 647 div2C , Log unusual behaviour

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

log() operation uses floating point numbers. Here you have precision upto 1 decimal point, so even if the answer is something like 58.9898999999, you would get the output as 59.0. It is better to not work with floating points if you want such precision

1 Like

Never came across situation like this before.
You are correct.
I got log2 of number to be 58.9999999999999999975 by using high precision calculator.
Thank a lot for your help.

Refer This

Never thought log2l() such thing exist

Thank you for sharing.