List of usage examples for com.google.common.math BigIntegerMath sqrt
@GwtIncompatible("TODO") @SuppressWarnings("fallthrough") public static BigInteger sqrt(BigInteger x, RoundingMode mode)
From source file:org.apache.drill.exec.util.DecimalUtility.java
/** * Calculates and returns square root for specified BigDecimal * with specified number of digits alter decimal point. * * @param in BigDecimal which square root should be calculated * @param scale number of digits alter decimal point in the result value. * @return square root for specified BigDecimal *///from w ww . ja va 2 s . c o m public static BigDecimal sqrt(BigDecimal in, int scale) { // unscaled BigInteger value from specified BigDecimal with doubled number of digits after decimal point // was used to calculate sqrt using Guava's BigIntegerMath. BigInteger valueWithDoubleMaxPrecision = in.multiply(BigDecimal.TEN.pow(scale * 2)) .setScale(0, RoundingMode.HALF_UP).unscaledValue(); return new BigDecimal(BigIntegerMath.sqrt(valueWithDoubleMaxPrecision, RoundingMode.HALF_UP), scale); }