BlueBlade's blog

By BlueBlade, history, 7 years ago, In English

What is the ans of floor of log2(288230376151711743) ??? Run a code with builtin log2() function, ans is 58 !!! Even google gives the ans 58 !!! Now write a code yourself to find the log2(x), and put x = 288230376151711743 . The actual answer is 57 !!!

couldn't get it !!!

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +6 Vote: I do not like it

It uses double precision and it is 57.99999999999999999499464608778919110696411496790292147213... Check: [WolframAlpha](https://www.wolframalpha.com/input/?i=log2(288230376151711743))

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thank you

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      but why my code is giving me ans 58?

      • »
        »
        »
        »
        7 years ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        double can only handle about 15-17 digits of precision. So C++ rounds the number to 58.00000000000000.

»
7 years ago, # |
  Vote: I like it +1 Vote: I do not like it

try to output log2(x) + 1e-9