Hacker News new | past | comments | ask | show | jobs | submit login

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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: