See the Integer square root Wikipedia page for more information.
Some notes on this script:
- I have no idea why this method works, all I know is that it’s fast.
- Because it’s POSIX shell, you can’t use floating point numbers, meaning both the input and output of this script are integers.
I’m disappointed that I wasn’t able to find an “arithmetic-only non-iterative integer square root” formula which only needs to be executed once. I feel like it’s possible, but, this is good enough given its speed.