本文整理了Java中java.math.BigInteger.multiply()
方法的一些代码示例,展示了BigInteger.multiply()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.multiply()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:multiply
[英]Package private methods used by BigDecimal code to multiply a BigInteger with a long. Assumes v is not equal to INFLATED.
[中]BigDecimal代码用于将BigInteger与长整数相乘的包私有方法。假设v不等于膨胀的。
代码示例来源:origin: deeplearning4j/nd4j
/**
* Compares the value of this with another constant.
*
* @param val the other constant to compare with
* @return -1, 0 or 1 if this number is numerically less than, equal to,
* or greater than val.
*/
public int compareTo(final Rational val) {
/* Since we have always kept the denominators positive,
* simple cross-multiplying works without changing the sign.
*/
final BigInteger left = a.multiply(val.b);
final BigInteger right = val.a.multiply(b);
return left.compareTo(right);
} /* Rational.compareTo */
代码示例来源: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: deeplearning4j/nd4j
/**
* Add another fraction.
*
* @param val The number to be added
* @return this+val.
*/
public Rational add(Rational val) {
BigInteger num = a.multiply(val.b).add(b.multiply(val.a));
BigInteger deno = b.multiply(val.b);
return (new Rational(num, deno));
} /* Rational.add */
代码示例来源:origin: javamelody/javamelody
boolean first = true;
while (true) {
if (FOUR.multiply(q).add(r).subtract(t).compareTo(n.multiply(t)) == -1) {
System.out.print(n);
if (first) {
first = false;
nr = BigInteger.TEN.multiply(r.subtract(n.multiply(t)));
n = BigInteger.TEN.multiply(THREE.multiply(q).add(r)).divide(t)
.subtract(BigInteger.TEN.multiply(n));
q = q.multiply(BigInteger.TEN);
r = nr;
System.out.flush();
} else {
nr = TWO.multiply(q).add(r).multiply(l);
nn = q.multiply(SEVEN.multiply(k)).add(TWO).add(r.multiply(l))
.divide(t.multiply(l));
q = q.multiply(k);
t = t.multiply(l);
l = l.add(TWO);
k = k.add(BigInteger.ONE);
代码示例来源:origin: apache/hive
public static BigInteger fastBigIntegerValueUnscaled(
int fastSignum, long fast0, long fast1, long fast2) {
if (fastSignum == 0) {
return BigInteger.ZERO;
}
BigInteger result;
if (fast2 == 0) {
if (fast1 == 0) {
result =
BigInteger.valueOf(fast0);
} else {
result =
BigInteger.valueOf(fast0).add(
BigInteger.valueOf(fast1).multiply(BIG_INTEGER_LONGWORD_MULTIPLIER));
}
} else {
result =
BigInteger.valueOf(fast0).add(
BigInteger.valueOf(fast1).multiply(BIG_INTEGER_LONGWORD_MULTIPLIER)).add(
BigInteger.valueOf(fast2).multiply(BIG_INTEGER_LONGWORD_MULTIPLIER_2X));
}
return (fastSignum == 1 ? result : result.negate());
}
代码示例来源:origin: web3j/web3j
BigInteger i = BigInteger.valueOf((long) recId / 2);
BigInteger x = sig.r.add(i.multiply(n));
if (x.compareTo(prime) >= 0) {
BigInteger eInv = BigInteger.ZERO.subtract(e).mod(n);
BigInteger rInv = sig.r.modInverse(n);
BigInteger srInv = rInv.multiply(sig.s).mod(n);
BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
ECPoint q = ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv);
代码示例来源:origin: i2p/i2p.i2p
private static ECPoint doublePoint(ECPoint r, EllipticCurve curve) {
if (r.equals(ECPoint.POINT_INFINITY))
return r;
BigInteger slope = (r.getAffineX().pow(2)).multiply(THREE);
slope = slope.add(curve.getA());
BigInteger prime = ((ECFieldFp) curve.getField()).getP();
// use NBI modInverse();
BigInteger tmp = r.getAffineY().multiply(TWO);
tmp = new NativeBigInteger(tmp);
slope = slope.multiply(tmp.modInverse(prime));
BigInteger xOut = slope.pow(2).subtract(r.getAffineX().multiply(TWO)).mod(prime);
BigInteger yOut = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(xOut))).mod(prime);
ECPoint out = new ECPoint(xOut, yOut);
return out;
}
代码示例来源:origin: hibernate/hibernate-orm
public IntegralDataTypeHolder multiplyBy(long factor) {
checkInitialized();
value = value.multiply( BigInteger.valueOf( factor ) );
return this;
}
代码示例来源:origin: robovm/robovm
if (r.signum() != 1 || r.compareTo(q) != -1 || s.signum() != 1
|| s.compareTo(q) != -1) {
return false;
u1 = (new BigInteger(1, digest)).multiply(w).mod(q);
u2 = r.multiply(w).mod(q);
v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q);
if (v.compareTo(r) != 0) {
return false;
代码示例来源:origin: apache/flink
@Override
protected long vertexCount() {
BigInteger vertexCount = BigInteger.ONE;
for (Dimension dimension : dimensions) {
vertexCount = vertexCount.multiply(BigInteger.valueOf(dimension.size));
}
if (vertexCount.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
throw new ProgramParametrizationException("Number of vertices in grid graph '" + vertexCount +
"' is greater than Long.MAX_VALUE.");
}
return vertexCount.longValue();
}
代码示例来源:origin: Sable/soot
/** Factorial */
public static BigInteger fact(BigInteger n_) {
BigInteger result = BigInteger.ONE;
for (BigInteger i = BigInteger.ONE; i.compareTo(n_) <= 0; i = i.add(BigInteger.ONE)) {
result = result.multiply(i);
}
return result;
}
代码示例来源:origin: org.apache.poi/poi
/**
* Converts a {@link Date} into a filetime.
*
* @param date The date to be converted
* @return The filetime
*
* @see #filetimeToDate(long)
*/
public static long dateToFileTime(final Date date) {
return BigInteger.valueOf(date.getTime()).subtract(EPOCH_DIFF).multiply(NANO_100).longValue();
}
代码示例来源:origin: i2p/i2p.i2p
public byte[] multiplyAndAdd(byte[] a, byte[] b, byte[] c) {
return enc.encode(enc.toBigInteger(a).multiply(enc.toBigInteger(b)).add(enc.toBigInteger(c)).mod(l));
}
代码示例来源: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: jfaster/mango
private static BigInteger fnv1_32(byte[] data) {
BigInteger hash = INIT32;
for (byte b : data) {
hash = hash.multiply(PRIME32).mod(MOD32);
hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
}
return hash;
}
代码示例来源:origin: prestodb/presto
@Test
public void testShiftRightArray8()
{
assertShiftRightArray8(TWO.pow(1), 0);
assertShiftRightArray8(TWO.pow(1), 1);
assertShiftRightArray8(TWO.pow(1), 10);
assertShiftRightArray8(TWO.pow(15).add(TWO.pow(3)), 2);
assertShiftRightArray8(TWO.pow(15).add(TWO.pow(3)), 10);
assertShiftRightArray8(TWO.pow(15).add(TWO.pow(3)), 20);
assertShiftRightArray8(TWO.pow(70), 30);
assertShiftRightArray8(TWO.pow(70).subtract(TWO.pow(1)), 30, true);
assertShiftRightArray8(TWO.pow(70), 32);
assertShiftRightArray8(TWO.pow(70).subtract(TWO.pow(1)), 32, true);
assertShiftRightArray8(TWO.pow(120), 70);
assertShiftRightArray8(TWO.pow(120).subtract(TWO.pow(1)), 70, true);
assertShiftRightArray8(TWO.pow(120), 96);
assertShiftRightArray8(TWO.pow(120).subtract(TWO.pow(1)), 96, true);
assertShiftRightArray8(MAX_DECIMAL_UNSCALED_VALUE, 20, true);
assertShiftRightArray8(MAX_DECIMAL_UNSCALED_VALUE.multiply(MAX_DECIMAL_UNSCALED_VALUE), 130);
assertShiftRightArray8(TWO.pow(256).subtract(BigInteger.ONE), 130, true);
assertShiftRightArray8Overflow(TWO.pow(156), 1);
assertShiftRightArray8Overflow(MAX_DECIMAL_UNSCALED_VALUE.multiply(MAX_DECIMAL_UNSCALED_VALUE), 20);
assertShiftRightArray8Overflow(TWO.pow(256).subtract(BigInteger.ONE), 129);
}
代码示例来源:origin: ethereum/ethereumj
@Override public Fp squared() { return new Fp(v.multiply(v).mod(P)); }
@Override public Fp dbl() { return new Fp(v.add(v).mod(P)); }
代码示例来源:origin: prestodb/presto
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];
boolean overflowIsExpected = expectedQuotient.abs().compareTo(bigIntegerTenToNth(38)) >= 0 || expectedRemainder.abs().compareTo(bigIntegerTenToNth(38)) >= 0;
代码示例来源:origin: stackoverflow.com
public static BigInteger factorial(BigInteger n) {
BigInteger result = BigInteger.ONE;
while (!n.equals(BigInteger.ZERO)) {
result = result.multiply(n);
n = n.subtract(BigInteger.ONE);
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!