MCPcopy Create free account
hub / github.com/antlr/codebuff / roundToBigInteger

Method roundToBigInteger

output/java_guava/1.4.16/DoubleMath.java:176–186  ·  view source on GitHub ↗
(double x, RoundingMode mode)

Source from the content-addressed store, hash-verified

174 // #roundIntermediate, java.lang.Math.getExponent, com.google.common.math.DoubleUtils
175
176 @GwtIncompatible
177 public static BigInteger roundToBigInteger(double x, RoundingMode mode) {
178 x = roundIntermediate(x, mode);
179 if (MIN_LONG_AS_DOUBLE - x < 1.0 & x < MAX_LONG_AS_DOUBLE_PLUS_ONE) {
180 return BigInteger.valueOf((long) x);
181 }
182 int exponent = getExponent(x);
183 long significand = getSignificand(x);
184 BigInteger result = BigInteger.valueOf(significand).shiftLeft(exponent - SIGNIFICAND_BITS);
185 return (x < 0) ? result.negate() : result;
186 }
187
188 /**
189 * Returns {@code true} if {@code x} is exactly equal to {@code 2^k} for some finite integer

Callers 1

sqrtApproxWithDoublesMethod · 0.95

Calls 4

roundIntermediateMethod · 0.95
valueOfMethod · 0.45
getSignificandMethod · 0.45
negateMethod · 0.45

Tested by

no test coverage detected