← Back to context

Comment by remram

4 years ago

Yeah that seems like a serious flaw to me too. On my Python:

  >>> math.log(1000)/math.log(10)
  2.9999999999999996
  >>> int(math.log(1000)/math.log(10))
  2

But I don't know about the guarantees provided in the JavaScript standard (or more importantly those offered by actual browsers).

Floating point math is IEEE 754 in pretty much all cases, so you should see this result in most languages. `math.log(1000, 10)` gives the same result because it's implemented using natural logs internally as it is in most languages.

In this case, there's only about six boundary cases to consider so you can just manually verify it works as expected.