Java Utililty Methods sqr

List of utility methods to do sqr

Description

The list of methods to do sqr are organized into topic(s).

Method

floatsqrt_double(double d)
sqrdouble
return (float) Math.sqrt(d);
floatsqrt_float(float value)
sqrfloat
return (float) Math.sqrt((double) value);
longsqrt_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;
intsqrtInt(Integer num)
sqrt Int
Double rs = Math.sqrt(num.longValue());
return rs.intValue();