Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int isqrt(unsigned x) {
- unsigned x1;
- int s, g0, g1;
- if (x <= 1) return x;
- s = 1;
- x1 = x - 1;
- if (x1 > 65535) {s = s + 8; x1 = x1 >> 16;}
- if (x1 > 255) {s = s + 4; x1 = x1 >> 8;}
- if (x1 > 15) {s = s + 2; x1 = x1 >> 4;}
- if (x1 > 3) {s = s + 1;}
- g0 = 1 << s;
- g1 = (g0 + (x >> s)) >> 1;
- while (g1 < g0) {
- g0 = g1;
- g1 = (g0 + (x/g0)) >> 1;
- }
- return g0;
- }
Add Comment
Please, Sign In to add comment