本文整理了Java中java.math.BigInteger.subtract()
方法的一些代码示例,展示了BigInteger.subtract()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.subtract()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:subtract
[英]Returns a BigInteger whose value is this - value.
[中]返回一个BigInteger,其值为-value。
代码示例来源: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: 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;
}
代码示例来源:origin: stackoverflow.com
for (BigInteger bi = BigInteger.valueOf(5);
bi.compareTo(BigInteger.ZERO) > 0;
bi = bi.subtract(BigInteger.ONE)) {
System.out.println(bi);
}
// prints "5", "4", "3", "2", "1"
代码示例来源: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: 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: pholser/junit-quickcheck
@Override protected void primeSourceOfRandomness() {
when(randomForParameterGenerator.nextBigInteger(min.add(TEN).subtract(min).bitLength()))
.thenReturn(new BigInteger("6"));
when(randomForParameterGenerator.nextBigInteger(min.add(TEN.pow(2)).subtract(min).bitLength()))
.thenReturn(new BigInteger("35"));
when(distro.sampleWithMean(1, randomForParameterGenerator)).thenReturn(0);
when(distro.sampleWithMean(2, randomForParameterGenerator)).thenReturn(1);
}
代码示例来源:origin: prestodb/presto
@Test
public void testGetTokenCountInRange()
{
assertEquals(tokenRing.getTokenCountInRange("0", "1"), ONE);
assertEquals(tokenRing.getTokenCountInRange("-1", "1"), new BigInteger("2"));
assertEquals(tokenRing.getTokenCountInRange("-100", "100"), 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"), ZERO);
assertEquals(tokenRing.getTokenCountInRange(Long.toString(Long.MIN_VALUE), Long.toString(Long.MIN_VALUE)), BigInteger.valueOf(2).pow(64).subtract(ONE));
assertEquals(tokenRing.getTokenCountInRange("1", "0"), BigInteger.valueOf(2).pow(64).subtract(BigInteger.valueOf(2)));
}
代码示例来源: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: oracle/helidon
@Override
public BigInteger apply(Config config) throws ConfigMappingException, MissingValueException {
return (new BigInteger(config.asString().get())).subtract(BigInteger.ONE);
}
代码示例来源:origin: square/wire
@Override public Long fromJson(JsonReader reader) throws IOException {
BigInteger bigInteger = new BigInteger(reader.nextString());
return bigInteger.compareTo(maxLong) > 0
? bigInteger.subtract(power64).longValue()
: bigInteger.longValue();
}
代码示例来源: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
protected byte[] engineSign() throws SignatureException {
BigInteger elgp = key.getParams().getP();
BigInteger pm1 = elgp.subtract(BigInteger.ONE);
BigInteger elgg = key.getParams().getG();
BigInteger x = ((ElGamalPrivateKey) key).getX();
boolean ok;
do {
k = new BigInteger(2048, RandomSource.getInstance());
ok = k.compareTo(pm1) == -1;
ok = ok && k.compareTo(BigInteger.ONE) == 1;
ok = ok && k.gcd(pm1).equals(BigInteger.ONE);
} while (!ok);
BigInteger kinv = k.modInverse(pm1);
BigInteger h = new NativeBigInteger(1, data);
BigInteger s = (kinv.multiply(h.subtract(x.multiply(r)))).mod(pm1);
代码示例来源:origin: hibernate/hibernate-orm
public IntegralDataTypeHolder subtract(long subtrahend) {
checkInitialized();
value = value.subtract( BigInteger.valueOf( subtrahend ) );
return this;
}
代码示例来源:origin: plantuml/plantuml
public BigDecimal eval(List<? extends Number> parameters) {
assertNotNull(parameters.get(0));
/*
* From The Java Programmers Guide To numerical Computing (Ronald Mak, 2003)
*/
BigDecimal x = (BigDecimal) parameters.get(0);
if (x.compareTo(BigDecimal.ZERO) == 0) {
return new BigDecimal(0);
}
if (x.signum() < 0) {
throw new ExpressionException("Argument to SQRT() function must not be negative");
}
BigInteger n = x.movePointRight(mc.getPrecision() << 1).toBigInteger();
int bits = (n.bitLength() + 1) >> 1;
BigInteger ix = n.shiftRight(bits);
BigInteger ixPrev;
BigInteger test;
do {
ixPrev = ix;
ix = ix.add(n.divide(ix)).shiftRight(1);
// Give other threads a chance to work;
Thread.yield();
test = ix.subtract(ixPrev).abs();
} while (test.compareTo(BigInteger.ZERO) != 0 && test.compareTo(BigInteger.ONE) != 0);
return new BigDecimal(ix, mc.getPrecision());
}
});
代码示例来源:origin: apache/zeppelin
BigInteger base = new BigInteger("" + DICTIONARY.length);
int exponent = 1;
BigInteger remaining = new BigInteger(value.toString());
while (true) {
BigInteger b = remaining.mod(a); // 119 % 16 = 7 | 112 % 256 = 112
BigInteger c = base.pow(exponent - 1);
BigInteger d = b.divide(c);
remaining = remaining.subtract(b); // 119 - 7 = 112 | 112 - 112 = 0
代码示例来源:origin: prestodb/presto
private static BigInteger bigDecimalToBigintFloorSaturatedCast(BigDecimal bigDecimal, int resultPrecision, int resultScale)
{
BigDecimal rescaledValue = bigDecimal.setScale(resultScale, FLOOR);
BigInteger unscaledValue = rescaledValue.unscaledValue();
BigInteger maxUnscaledValue = bigIntegerTenToNth(resultPrecision).subtract(ONE);
if (unscaledValue.compareTo(maxUnscaledValue) > 0) {
return maxUnscaledValue;
}
BigInteger minUnscaledValue = maxUnscaledValue.negate();
if (unscaledValue.compareTo(minUnscaledValue) < 0) {
return minUnscaledValue;
}
return unscaledValue;
}
代码示例来源: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: i2p/i2p.i2p
/**
* @param sigBytes ASN.1 R,S
*/
@Override
protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
BigInteger elgp = key.getParams().getP();
BigInteger pm1 = elgp.subtract(BigInteger.ONE);
BigInteger elgg = key.getParams().getG();
BigInteger y = ((ElGamalPublicKey) key).getY();
if (!(y instanceof NativeBigInteger))
y = new NativeBigInteger(y);
byte[] data = digest.digest();
try {
BigInteger[] rs = SigUtil.aSN1ToBigInteger(sigBytes, 256);
BigInteger r = rs[0];
BigInteger s = rs[1];
if (r.signum() != 1 || s.signum() != 1 ||
r.compareTo(elgp) != -1 || s.compareTo(pm1) != -1)
return false;
NativeBigInteger h = new NativeBigInteger(1, data);
BigInteger modvalr = r.modPow(s, elgp);
BigInteger modvaly = y.modPow(r, elgp);
BigInteger modmulval = modvalr.multiply(modvaly).mod(elgp);
BigInteger v = elgg.modPow(h, elgp);
boolean ok = v.compareTo(modmulval) == 0;
return ok;
} catch (RuntimeException e) {
throw new SignatureException("verify", e);
}
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!