Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

math.log(k) / math.log(2) gives niche precision errors, or not?

Правка en1, от akzytr, 2024-05-07 20:17:51

Reffering to the 2 solutions: 259905045 and 259906344

The only difference between the codes is that one uses math.log(x) / math.log(2), and the other uses math.log2(x) for the purpose of calculating log with base 2.

The former one, using division to get the base, fails on test case. However, the output is somehow close?

Output: 4327966553 Jury: 4327967516

My first thought was that math.log(x) / math.log(2) would somehow give precision errors if the values are big enough, which seems to be the case here.

I ran a simulation though with random large numbers taken from the range 2^32 and 2^63, and calculated the log with base 2 with both. The code was supposed to break when these two differ, but this never happens.

Is it that the math.log(x) / math.log(2) gives precision errors, or not?

Теги binary numbers, logarithm

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский akzytr 2024-05-07 20:17:51 903 Initial revision (published)