Interesting result in c++

  • 0

    When printing out the value of some calculation:

    log(243)/log(3) gives 5

    floor(log(243)/log(3)) gives 4

    floor(5) gives 5


  • 1

    I tried in python 2.7.10. I think the result is the same in c++.

    In [2]: import math

    In [3]: math.log(243)
    Out[3]: 5.493061443340548

    In [4]: math.log(3)
    Out[4]: 1.0986122886681098

    In [5]: math.log(243)/math.log(3)
    Out[5]: 4.999999999999999

  • 0

    Maybe you can try "round" instead of "floor".

  • 1

    It possibly turns out to be 4.9999999999 due to round off errors in floating point arithmetic, floor() of which is 4.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.