I found myself needing to compute the “integer cube root”, meaning the cube root of an integer, rounded down to the nearest integer. In Python, we could use the NumPy floating-point cbrt() function: Though this works most of the time, it fails at certain input x, with the result being one less than expected. For example, icbrt(15**3) == 14, which
Tag: floating-accuracy
Unexpected integer division vs. floating-point division result in Python
Running the following code in Python produces a somewhat unexpected result. Now, I might have understood the discrepancy if both results were the same, because of how floating point numbers are stored in binary. The question is why is the second result different from the first one? Is there a difference in how / and // work besides the latter