If you take a number, take its square root, drop the decimal, and then raise it to the second power, the result should always be less than or equal to the original number.
This seems to hold true in python until you try it on 99999999999999975425
for some reason.
import math
def check(n):
assert math.pow(math.floor(math.sqrt(n)), 2) <= n
check(99999999999999975424) # No exception.
check(99999999999999975425) # Throws AssertionError.
It looks like math.pow(math.floor(math.sqrt(99999999999999975425)), 2)
returns 1e+20
.
I assume this has something to do with the way we store values in python... something related to floating point arithmetic, but I can't reason about specifically how that affects this case.
n = 4503599761588224
on most machines, despite the fact that both4503599761588224
and the floor of its square root (which is67108864
) are small enough to be exactly representable in IEEE 754 binary64 floating-point. So it's a bit more subtle than just using numbers larger than floating-point can represent. – Ascent