MCPcopy Create free account
hub / github.com/NetHack/NetHack / isqrt

Function isqrt

src/hacklib.c:681–700  ·  view source on GitHub ↗

integer square root function without using floating point */

Source from the content-addressed store, hash-verified

679
680/* integer square root function without using floating point */
681int
682isqrt(int val)
683{
684 int rt = 0;
685 int odd = 1;
686 /*
687 * This could be replaced by a faster algorithm, but has not been because:
688 * + the simple algorithm is easy to read;
689 * + this algorithm does not require 64-bit support;
690 * + in current usage, the values passed to isqrt() are not really that
691 * large, so the performance difference is negligible;
692 * + isqrt() is used in only few places, which are not bottle-necks.
693 */
694 while (val >= odd) {
695 val = val - odd;
696 odd = odd + 2;
697 rt = rt + 1;
698 }
699 return rt;
700}
701
702/* are two points lined up (on a straight line)? */
703boolean

Callers 3

throwitFunction · 0.85
percent_successFunction · 0.85
find_poleable_monFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected