/** * Scale down a BigInteger by a power of 10 and round off if necessary using ROUND_HALF_UP. * @return The scaled and rounded BigInteger. */ private static BigInteger doBigIntegerScaleDown(BigInteger unscaledValue, int scaleDown) { BigInteger[] quotientAndRemainder = unscaledValue.divideAndRemainder(BigInteger.TEN.pow(scaleDown)); BigInteger quotient = quotientAndRemainder[0]; BigInteger round = quotientAndRemainder[1].divide(BigInteger.TEN.pow(scaleDown - 1)); if (round.compareTo(BIG_INTEGER_FIVE) >= 0) { quotient = quotient.add(BigInteger.ONE); } return quotient; }
private static LocalDateTime nanosToLocalDateTimeUTC(long epocNanos) { // the pg plugin stores date/time info as microseconds since epoch BigInteger epochMicrosBigInt = BigInteger.valueOf(epocNanos); BigInteger[] secondsAndNanos = epochMicrosBigInt.divideAndRemainder(BigInteger.valueOf(TimeUnit.SECONDS.toNanos(1))); return LocalDateTime.ofInstant(Instant.ofEpochSecond(secondsAndNanos[0].longValue(), secondsAndNanos[1].longValue()), ZoneOffset.UTC); }
BigInteger[] dandr = bi.divideAndRemainder(divideBy); bi = dandr[0]; int digit = dandr[1].intValue();
/** * Return the spacing between lines of a paragraph. The units of the return value depends on the * {@link LineSpacingRule}. If AUTO, the return value is in lines, otherwise the return * value is in points * * @return a double specifying points or lines. */ public double getSpacingBetween() { CTSpacing spacing = getCTSpacing(false); if (spacing == null || !spacing.isSetLine()) { return -1; } else if (spacing.getLineRule() == null || spacing.getLineRule() == STLineSpacingRule.AUTO) { BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(240L)); return val[0].doubleValue() + (val[1].doubleValue() / 240L); } BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(20L)); return val[0].doubleValue() + (val[1].doubleValue() / 20L); }
private static BigDecimal divideBigIntegers(BigInteger scaledDividend, BigInteger scaledDivisor, int scale, RoundingMode roundingMode) { BigInteger[] quotAndRem = scaledDividend.divideAndRemainder(scaledDivisor); // quotient and remainder
bigInteger.divideAndRemainder(BIG_INTEGER_LONGWORD_MULTIPLIER); fastResult.fast0 = quotientAndRemainder[1].longValue(); BigInteger quotient = quotientAndRemainder[0]; quotient.divideAndRemainder(BIG_INTEGER_LONGWORD_MULTIPLIER); fastResult.fast1 = quotientAndRemainder[1].longValue(); quotient = quotientAndRemainder[0];
BigInteger n1 = toBigInteger(first); BigInteger n2 = toBigInteger(second); BigInteger[] divmod = n1.divideAndRemainder(n2); if (divmod[1].equals(BigInteger.ZERO)) { return divmod[0];
for (int i = 0; i < KEY_LENGTH_WORDS; i++) res = rr.divideAndRemainder(r32); rr = res[0]; rem = res[1]; myRr[i] = rem.intValue(); res = n.divideAndRemainder(r32); n = res[0]; rem = res[1];
BigInteger[] quotientAndRemainder = bigInteger.divideAndRemainder(BIG_INTEGER_TEN);
quotAndRem = mantissa.divideAndRemainder(powerOfTen);
quotAndRem = q.divideAndRemainder(FIVE_POW[i]); if (quotAndRem[1].signum() == 0) { l += i;
quotAndRem = strippedBI.divideAndRemainder(TEN_POW[i]);
BigInteger mantissaDigitMask = pow10(BigInteger.ONE, mantissaLength - 1); for (int i = mantissaLength - 1; i >= exponentPos; --i) { BigInteger[] parts = mantissa.divideAndRemainder(mantissaDigitMask); buffer.append(forDigit(Math.abs(parts[0].intValue()))); mantissa = parts[1]; int count = 0; for (int i = visibleExponent - 1; i >= limit; --i) { BigInteger[] parts = mantissa.divideAndRemainder(mantissaDigitMask); buffer.append(forDigit(Math.abs(parts[0].intValue()))); mantissa = parts[1];
BigInteger mantissaDigitMask = pow10(BigInteger.ONE, mantissaLength - 1); for (int i = 0; i < significantIntDigits; ++i) { BigInteger[] parts = mantissa.divideAndRemainder(mantissaDigitMask); buffer.append(forDigit(Math.abs(parts[0].intValue()))); mantissa = parts[1]; BigInteger[] parts = mantissa.divideAndRemainder(mantissaDigitMask); buffer.append(forDigit(Math.abs(parts[0].intValue()))); mantissa = parts[1];
BigInteger[] integerAndFraction = getUnscaledValue().divideAndRemainder(sizeOfFraction); long newScale = (long)scale - discardedPrecision; int compRem;
divideAndRemainder(divisor.getUnscaledValue()); quotAndRem = strippedBI.divideAndRemainder(TEN_POW[i]); if ((quotAndRem[1].signum() == 0) && ((resultPrecision - i >= mcPrecision)
/** * Returns this {@code BigDecimal} as a big integer instance if it has no * fractional part. If this {@code BigDecimal} has a fractional part, i.e. * if rounding would be necessary, an {@code ArithmeticException} is thrown. * * @return this {@code BigDecimal} as a big integer value. * @throws ArithmeticException * if rounding is necessary. */ public BigInteger toBigIntegerExact() { if ((scale == 0) || (isZero())) { return getUnscaledValue(); } else if (scale < 0) { return getUnscaledValue().multiply(Multiplication.powerOf10(-(long)scale)); } else {// (scale > 0) BigInteger[] integerAndFraction; // An optimization before do a heavy division if ((scale > approxPrecision()) || (scale > getUnscaledValue().getLowestSetBit())) { throw new ArithmeticException("Rounding necessary"); } integerAndFraction = getUnscaledValue().divideAndRemainder(Multiplication.powerOf10(scale)); if (integerAndFraction[1].signum() != 0) { // It exists a non-zero fractional part throw new ArithmeticException("Rounding necessary"); } return integerAndFraction[0]; } }
newScale += trailingZeros; quotAndRem = quotAndRem[0].divideAndRemainder( divisor.getUnscaledValue() ); integerQuot = quotAndRem[0]; quotAndRem = integerQuot.divideAndRemainder(TEN_POW[i]); if ((quotAndRem[1].signum() == 0) && (newScale - i >= diffScale)) {
BigInteger rescaledDividend = dividendBigInteger.multiply(bigIntegerTenToNth(dividendRescaleFactor)); BigInteger rescaledDivisor = divisorBigInteger.multiply(bigIntegerTenToNth(divisorRescaleFactor)); BigInteger[] expectedQuotientAndRemainder = rescaledDividend.divideAndRemainder(rescaledDivisor); BigInteger expectedQuotient = expectedQuotientAndRemainder[0]; BigInteger expectedRemainder = expectedQuotientAndRemainder[1];
quotAndRem = integralValue.divideAndRemainder(TEN_POW[i]); if ((quotAndRem[1].signum() == 0) && (tempScale - i >= newScale)) {