Peculiar behaviour of log2() function in C++.

Правка en1, от Fearless_cod, 2021-12-16 06:39:46

Hi reader. Coming straight to the point. The value of (1ll<<59) or 2^59 is 576460752303423488(say x).So if you do log2(x),the answer should come out to be 59.That's indeed the case. But here is the catch... .If you do log2(x-1) in C++ 14(not sure for other versions),it also gives 59 as output..(but actual answer is 58), which is wrong and that caused me a fst in recent Div 3 problem F.

So, can anyone explain why is this happening and how to avoid these types of things. Thanks for spending your time in reading this blog.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Fearless_cod 2021-12-16 06:39:46 580 Initial revision (published)