(double x, RoundingMode mode)
| 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 |
no test coverage detected