本文整理了Java中java.math.BigInteger.add()
方法的一些代码示例,展示了BigInteger.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.add()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:add
[英]Returns a BigInteger whose value is this + value.
[中]返回一个BigInteger,其值为this+值。
代码示例来源:origin: google/guava
@Override
BigInteger offset(BigInteger origin, long distance) {
checkNonnegative(distance, "distance");
return origin.add(BigInteger.valueOf(distance));
}
代码示例来源:origin: stackoverflow.com
BigInteger reallyBig = new BigInteger("1234567890123456890");
BigInteger notSoBig = new BigInteger("2743561234");
reallyBig = reallyBig.add(notSoBig);
代码示例来源: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: prestodb/presto
@Override
public BigInteger getTokenCountInRange(String startToken, String endToken)
{
BigInteger start = new BigInteger(startToken);
checkTokenBounds(start);
BigInteger end = new BigInteger(endToken);
checkTokenBounds(end);
if (start.equals(end)) {
if (start.equals(MIN_TOKEN)) {
return TOTAL_TOKEN_COUNT;
}
else {
return ZERO;
}
}
BigInteger result = end.subtract(start);
if (end.compareTo(start) <= 0) {
result = result.add(TOTAL_TOKEN_COUNT);
}
return result;
}
代码示例来源:origin: web3j/web3j
BigInteger i = BigInteger.valueOf((long) recId / 2);
BigInteger x = sig.r.add(i.multiply(n));
if (x.compareTo(prime) >= 0) {
BigInteger e = new BigInteger(1, message);
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);
return new BigInteger(1, Arrays.copyOfRange(qBytes, 1, qBytes.length));
代码示例来源:origin: google/guava
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
return sqrtFloorIsExact ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
BigInteger halfSquare = sqrtFloor.pow(2).add(sqrtFloor);
return (halfSquare.compareTo(x) >= 0) ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
default:
throw new AssertionError();
代码示例来源: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: prestodb/presto
@Override
public BigInteger getTokenCountInRange(String startToken, String endToken)
{
long start = Long.parseLong(startToken);
long end = Long.parseLong(endToken);
if (start == end) {
if (start == MIN_TOKEN) {
return TOTAL_TOKEN_COUNT;
}
else {
return ZERO;
}
}
BigInteger result = BigInteger.valueOf(end).subtract(BigInteger.valueOf(start));
if (end <= start) {
result = result.add(TOTAL_TOKEN_COUNT);
}
return result;
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
messageDigest.reset();
messageDigest.update(A.toByteArray());
final BigInteger u = new BigInteger(1, messageDigest.digest(B.toByteArray()));
if (u.equals(BigInteger.ZERO)) {
throw new CognitoInternalErrorException("Hash of A and B cannot be zero");
final BigInteger x = new BigInteger(1, messageDigest.digest(userIdHash));
final BigInteger s = (B.subtract(KK.multiply(GG.modPow(x, N)))
.modPow(a.add(u.multiply(x)), N)).mod(N);
代码示例来源:origin: robovm/robovm
digestBI = new BigInteger(1, msgDigest.digest());
k = new BigInteger(1, randomBytes);
if (k.compareTo(q) != -1) {
continue;
r = g.modPow(k, p).mod(q);
if (r.signum() == 0) {
continue;
s = k.modInverse(q).multiply(digestBI.add(x.multiply(r)).mod(q))
.mod(q);
代码示例来源:origin: stackoverflow.com
int nlen = n.bitLength();
BigInteger nm1 = n.subtract(BigInteger.ONE);
BigInteger r, s;
do {
s = new BigInteger(nlen + 100, rnd);
r = s.mod(n);
} while (s.subtract(r).add(nm1).bitLength() >= nlen + 100);
// result is in 'r'
代码示例来源:origin: prestodb/presto
@Test
public void testGetRingFraction()
{
assertEquals(tokenRing.getTokenCountInRange("0", "1"), ONE);
assertEquals(tokenRing.getTokenCountInRange("0", "200"), new BigInteger("200"));
assertEquals(tokenRing.getTokenCountInRange("0", "10"), new BigInteger("10"));
assertEquals(tokenRing.getTokenCountInRange("1", "11"), new BigInteger("10"));
assertEquals(tokenRing.getTokenCountInRange("0", "0"), ZERO);
assertEquals(tokenRing.getTokenCountInRange("-1", "-1"), BigInteger.valueOf(2).pow(127).add(ONE));
assertEquals(tokenRing.getTokenCountInRange("1", "0"), BigInteger.valueOf(2).pow(127));
}
代码示例来源:origin: google/guava
@GwtIncompatible // TODO
public void testSqrtHalfUp() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
BigInteger result = BigIntegerMath.sqrt(x, HALF_UP);
BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
BigInteger x4 = x.shiftLeft(2);
// sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4
// (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
assertTrue(x4.compareTo(plusHalfSquared) < 0);
BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
// sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
// (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) >= 0);
}
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public BigInteger next() {
if (upcoming.compareTo(to) >= 0) {
throw new NoSuchElementException();
}
BigInteger next = upcoming;
upcoming = upcoming.add(incrementUnit);
return next;
}
代码示例来源:origin: SeanDragon/protools
/**
* 判断生成的公钥是否合法
*
* @param publicKey
* @return
*/
private boolean checkPublicKey(ECPoint publicKey) {
if (!publicKey.isInfinity()) {
BigInteger x = publicKey.getXCoord().toBigInteger();
BigInteger y = publicKey.getYCoord().toBigInteger();
if (between(x, new BigInteger("0"), p) && between(y, new BigInteger("0"), p)) {
BigInteger xResult = x.pow(3).add(a.multiply(x)).add(b).mod(p);
BigInteger yResult = y.pow(2).mod(p);
return yResult.equals(xResult) && publicKey.multiply(n).isInfinity();
}
}
return false;
}
代码示例来源: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: ethereum/ethereumj
void testAddMod(String v1, String v2, String v3) {
DataWord dv1 = DataWord.of(Hex.decode(v1));
DataWord dv2 = DataWord.of(Hex.decode(v2));
DataWord dv3 = DataWord.of(Hex.decode(v3));
BigInteger bv1 = new BigInteger(v1, 16);
BigInteger bv2 = new BigInteger(v2, 16);
BigInteger bv3 = new BigInteger(v3, 16);
DataWord actual = dv1.addmod(dv2, dv3);
BigInteger br = bv1.add(bv2).mod(bv3);
assertEquals(actual.value(), br);
}
代码示例来源:origin: checkstyle/checkstyle
/** Leaves try. */
private void leaveMultiplyingConditional() {
currentRangeValue = currentRangeValue.add(BigInteger.ONE)
.multiply(popValue().getRangeValue().add(BigInteger.ONE));
}
代码示例来源:origin: prestodb/presto
@Override
public BigInteger visitArithmeticBinary(ArithmeticBinaryContext ctx)
{
BigInteger left = visit(ctx.left);
BigInteger right = visit(ctx.right);
switch (ctx.operator.getType()) {
case PLUS:
return left.add(right);
case MINUS:
return left.subtract(right);
case ASTERISK:
return left.multiply(right);
case SLASH:
return left.divide(right);
default:
throw new IllegalStateException("Unsupported binary operator " + ctx.operator.getText());
}
}
代码示例来源:origin: checkstyle/checkstyle
/** Leaves else, default or case group tokens. */
private void leaveBranch() {
final Values valuePair = popValue();
final BigInteger basicRangeValue = valuePair.getRangeValue();
final BigInteger expressionValue = valuePair.getExpressionValue();
if (branchVisited && currentRangeValue.equals(BigInteger.ZERO)) {
currentRangeValue = BigInteger.ONE;
}
currentRangeValue = currentRangeValue.subtract(BigInteger.ONE)
.add(basicRangeValue)
.add(expressionValue);
}
内容来源于网络,如有侵权,请联系作者删除!