本文整理了Java中java.math.BigInteger.divide()
方法的一些代码示例,展示了BigInteger.divide()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.divide()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:divide
[英]Returns a BigInteger whose value is this / divisor.
[中]返回一个BigInteger,其值为this/除数。
代码示例来源:origin: stackoverflow.com
static BigInteger binomial(final int N, final int K) {
BigInteger ret = BigInteger.ONE;
for (int k = 0; k < K; k++) {
ret = ret.multiply(BigInteger.valueOf(N-k))
.divide(BigInteger.valueOf(k+1));
}
return ret;
}
//...
System.out.println(binomial(133, 71));
// prints "555687036928510235891585199545206017600"
代码示例来源:origin: apache/hive
/**
* 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;
}
代码示例来源:origin: commons-io/commons-io
String displaySize;
if (size.divide(ONE_EB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_EB_BI)) + " EB";
} else if (size.divide(ONE_PB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_PB_BI)) + " PB";
} else if (size.divide(ONE_TB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_TB_BI)) + " TB";
} else if (size.divide(ONE_GB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_GB_BI)) + " GB";
} else if (size.divide(ONE_MB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_MB_BI)) + " MB";
} else if (size.divide(ONE_KB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_KB_BI)) + " KB";
} else {
displaySize = String.valueOf(size) + " bytes";
代码示例来源:origin: apache/hbase
/**
* Divide 2 numbers in half (for split algorithm)
*
* @param a number #1
* @param b number #2
* @return the midpoint of the 2 numbers
*/
public BigInteger split2(BigInteger a, BigInteger b) {
return a.add(b).divide(BigInteger.valueOf(2)).abs();
}
代码示例来源:origin: ethereum/ethereumj
public long mine(long fullSize, byte[][] dataset, byte[] blockHeaderTruncHash, long difficulty) {
BigInteger target = valueOf(2).pow(256).divide(valueOf(difficulty));
long nonce = new Random().nextLong();
while(!Thread.currentThread().isInterrupted()) {
nonce++;
Pair<byte[], byte[]> pair = hashimotoFull(fullSize, dataset, blockHeaderTruncHash, longToBytes(nonce));
BigInteger h = new BigInteger(1, pair.getRight() /* ?? */);
if (h.compareTo(target) < 0) break;
}
return nonce;
}
代码示例来源:origin: google/guava
BigInteger sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
if (sqrt0.equals(sqrt1)) {
return sqrt0;
sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
} while (sqrt1.compareTo(sqrt0) < 0);
return sqrt0;
代码示例来源:origin: google/guava
int approxCmp = approxPow.compareTo(x);
approxPow = approxPow.divide(BigInteger.TEN);
approxCmp = approxPow.compareTo(x);
} while (approxCmp > 0);
} else {
BigInteger nextPow = BigInteger.TEN.multiply(approxPow);
int nextCmp = nextPow.compareTo(x);
while (nextCmp <= 0) {
approxLog10++;
approxPow = nextPow;
approxCmp = nextCmp;
nextPow = BigInteger.TEN.multiply(approxPow);
nextCmp = nextPow.compareTo(x);
BigInteger halfPowerSquared = floorPow.pow(2).multiply(BigInteger.TEN);
return (x2.compareTo(halfPowerSquared) <= 0) ? floorLog : floorLog + 1;
default:
代码示例来源:origin: ethereum/ethereumj
@Override
public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) {
BigInteger pd = parent.getDifficultyBI();
BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR());
BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent);
BigInteger fromParent = pd.add(quotient.multiply(sign));
BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent);
int explosion = getExplosion(curBlock, parent);
if (explosion >= 0) {
difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion)));
}
return difficulty;
}
代码示例来源:origin: prestodb/presto
@Test
public void testUnderflowAfterOverflow()
{
addToState(state, TWO.pow(126));
addToState(state, TWO.pow(126));
addToState(state, TWO.pow(125));
assertEquals(state.getOverflow(), 1);
assertEquals(state.getLongDecimal(), unscaledDecimal(TWO.pow(125)));
addToState(state, TWO.pow(126).negate());
addToState(state, TWO.pow(126).negate());
addToState(state, TWO.pow(126).negate());
assertEquals(state.getOverflow(), 0);
assertEquals(state.getLongDecimal(), unscaledDecimal(TWO.pow(125).negate()));
assertEquals(average(state, TYPE), new BigDecimal(TWO.pow(125).negate().divide(BigInteger.valueOf(6))));
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* floor(): the nearest integer not greater than this.
*
* @return The integer rounded towards negative infinity.
*/
public BigInteger floor() {
/* is already integer: return the numerator
*/
if (b.compareTo(BigInteger.ONE) == 0) {
return a;
} else if (a.compareTo(BigInteger.ZERO) > 0) {
return a.divide(b);
} else {
return a.divide(b).subtract(BigInteger.ONE);
}
} /* Rational.floor */
代码示例来源:origin: apache/hive
bigInteger = bigInteger.multiply(BIG_INTEGER_TEN.pow(-scale));
scale = 0;
bigInteger = bigInteger.divide(bigIntegerThrowAwayBelowRoundDigitDivisor);
bigInteger = quotient.add(BigInteger.ONE);
代码示例来源:origin: kiegroup/optaplanner
@Override
public long getSize() {
return to.subtract(from).divide(incrementUnit).longValue();
}
代码示例来源:origin: prestodb/presto
private void assertAddReturnOverflow(BigInteger left, BigInteger right)
{
Slice result = unscaledDecimal();
long overflow = addWithOverflow(unscaledDecimal(left), unscaledDecimal(right), result);
BigInteger actual = unscaledDecimalToBigInteger(result);
BigInteger expected = left.add(right).remainder(TWO.pow(UnscaledDecimal128Arithmetic.UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 1));
BigInteger expectedOverflow = left.add(right).divide(TWO.pow(UnscaledDecimal128Arithmetic.UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 1));
assertEquals(actual, expected);
assertEquals(overflow, expectedOverflow.longValueExact());
}
代码示例来源:origin: robovm/robovm
/**
* Returns this {@code BigDecimal} as a big integer instance. A fractional
* part is discarded.
*
* @return this {@code BigDecimal} as a big integer instance.
*/
public BigInteger toBigInteger() {
if ((scale == 0) || (isZero())) {
return getUnscaledValue();
} else if (scale < 0) {
return getUnscaledValue().multiply(Multiplication.powerOf10(-(long)scale));
} else {// (scale > 0)
return getUnscaledValue().divide(Multiplication.powerOf10(scale));
}
}
代码示例来源:origin: apache/activemq
private static String toHumanReadableSizeString(final BigInteger size) {
String displaySize;
final BigInteger ONE_KB_BI = BigInteger.valueOf(1024);
final BigInteger ONE_MB_BI = ONE_KB_BI.multiply(ONE_KB_BI);
final BigInteger ONE_GB_BI = ONE_KB_BI.multiply(ONE_MB_BI);
if (size.divide(ONE_GB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_GB_BI)) + " GB";
} else if (size.divide(ONE_MB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_MB_BI)) + " MB";
} else if (size.divide(ONE_KB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = String.valueOf(size.divide(ONE_KB_BI)) + " KB";
} else {
displaySize = String.valueOf(size) + " bytes";
}
return displaySize;
}
}
代码示例来源:origin: google/guava
return BigInteger.valueOf(LongMath.binomial(n, k));
.multiply(BigInteger.valueOf(numeratorAccum))
.divide(BigInteger.valueOf(denominatorAccum));
numeratorAccum = p;
denominatorAccum = q;
.multiply(BigInteger.valueOf(numeratorAccum))
.divide(BigInteger.valueOf(denominatorAccum));
代码示例来源:origin: ethereum/ethereumj
public static boolean isIn20PercentRange(BigInteger first, BigInteger second) {
BigInteger five = BigInteger.valueOf(5);
BigInteger limit = first.add(first.divide(five));
return !isMoreThan(second, limit);
}
代码示例来源:origin: ethereum/ethereumj
public long mine(long fullSize, int[] dataset, byte[] blockHeaderTruncHash, long difficulty, long startNonce) {
long nonce = startNonce;
BigInteger target = valueOf(2).pow(256).divide(valueOf(difficulty));
while (!Thread.currentThread().isInterrupted()) {
nonce++;
Pair<byte[], byte[]> pair = hashimotoFull(fullSize, dataset, blockHeaderTruncHash, longToBytes(nonce));
BigInteger h = new BigInteger(1, pair.getRight() /* ?? */);
if (h.compareTo(target) < 0) break;
}
return nonce;
}
代码示例来源:origin: prestodb/presto
BigInteger sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
if (sqrt0.equals(sqrt1)) {
return sqrt0;
sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
} while (sqrt1.compareTo(sqrt0) < 0);
return sqrt0;
代码示例来源:origin: prestodb/presto
int approxCmp = approxPow.compareTo(x);
approxPow = approxPow.divide(BigInteger.TEN);
approxCmp = approxPow.compareTo(x);
} while (approxCmp > 0);
} else {
BigInteger nextPow = BigInteger.TEN.multiply(approxPow);
int nextCmp = nextPow.compareTo(x);
while (nextCmp <= 0) {
approxLog10++;
approxPow = nextPow;
approxCmp = nextCmp;
nextPow = BigInteger.TEN.multiply(approxPow);
nextCmp = nextPow.compareTo(x);
BigInteger halfPowerSquared = floorPow.pow(2).multiply(BigInteger.TEN);
return (x2.compareTo(halfPowerSquared) <= 0) ? floorLog : floorLog + 1;
default:
内容来源于网络,如有侵权,请联系作者删除!