private static long longSqrt ( long value ) { final int scale = 8 ; int bits = 64 ; long sqrt = 0 ; long rest = 0 ; for ( int i = 0 ; i < scale ; i ++ ) { bits -= 8 ; rest = ( rest << 8 ) | ( ( value >> bits ) & 0xFF ) ; long i2 = ( sqrt << 5 ) + 1 ; int k0 = 0 ; while ( true ) { long i3 = rest - i2 ; if ( i3 < 0 ) break ; rest = i3 ; i2 += 2 ; k0 ++ ; } sqrt = ( sqrt << 4 ) + k0 ; } return sqrt ; }
This will calculate the integer sqrt from a long value