List of utility methods to do sqr
float | sqrt_double(double d) sqrdouble return (float) Math.sqrt(d); |
float | sqrt_float(float value) sqrfloat return (float) Math.sqrt((double) value); |
long | sqrt_long(final long x) sqrlong if (x == 0) return 0; else if (x < 0) throw new ArithmeticException("sqrt(" + x + ")"); final int half_nBits = (Long.SIZE - Long.numberOfLeadingZeros(x)) >> 1; long upper; long lower; final long mid = x >> half_nBits; final long r = x - mid * mid; if (r >= 0 && r <= (mid << 1)) { return mid; } else if (r > 0) { upper = x >> (half_nBits - 1); lower = mid; } else { upper = mid; lower = x >> (half_nBits + 1); for (; upper - lower > 1;) { final long mid = (upper + lower) >> 1; final long r = x - mid * mid; if (r >= 0 && r <= (mid << 1)) { return mid; } else if (r > 0) { lower = mid; } else { upper = mid; return lower; |
int | sqrtInt(Integer num) sqrt Int Double rs = Math.sqrt(num.longValue());
return rs.intValue();
|