Here you can find the source of sqrt(long x)
public static long sqrt(long x)
//package com.java2s; //License from project: LGPL public class Main { public static long sqrt(long x) { long y = 0; long b = (~Long.MAX_VALUE) >>> 1; while (b > 0) { if (x >= y + b) { x -= y + b;/*from w ww . j a va 2 s .c om*/ y >>= 1; y += b; } else { y >>= 1; } b >>= 2; } return y; } }