java.math.BigInteger.equals()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中java.math.BigInteger.equals()方法的一些代码示例,展示了BigInteger.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.equals()方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:equals

BigInteger.equals介绍

[英]Compares this BigInteger with the specified Object for equality.
[中]将此BigInteger与指定的对象进行相等比较。

代码示例

代码示例来源:origin: alibaba/jstorm

private BigInteger previousTransactionId(BigInteger id) {
  if (id.equals(INIT_TXID)) {
    return null;
  } else {
    return id.subtract(BigInteger.ONE);
  }
}

代码示例来源: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: 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: google/guava

checkNonNegative("x", x);
if (fitsInLong(x)) {
 return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
  checkRoundingUnnecessary(sqrtFloor.pow(2).equals(x)); // fall through
 case FLOOR:
 case DOWN:
  boolean sqrtFloorIsExact =
      && sqrtFloor.pow(2).equals(x); // slow exact check
  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: google/guava

int approxCmp = approxPow.compareTo(x);
  approxLog10--;
  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);
  return floorPow.equals(x) ? floorLog : floorLog + 1;
  BigInteger halfPowerSquared = floorPow.pow(2).multiply(BigInteger.TEN);
  return (x2.compareTo(halfPowerSquared) <= 0) ? floorLog : floorLog + 1;
 default:

代码示例来源:origin: alibaba/fastjson

BigInteger bigIntA = BigInteger.valueOf(a.longValue());
  return bigIntA.equals(bigIntB);
if (a instanceof BigInteger) {
  BigInteger bigIntA = (BigInteger) a;
  BigInteger bigIntB = BigInteger.valueOf(TypeUtils.longExtractValue(b));
  return bigIntA.equals(bigIntB);

代码示例来源: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: plutext/docx4j

if (listSpec==null
    || (numId!=null
        && !numId.equals(listSpec.numId))) {
    listSpec = new ListSpec(numId, BigInteger.valueOf(i));
    listSpec.sdtList = new SdtBlock();
    setTag(listSpec.sdtList, numId, ilvl);            
  if (ilvl.equals(listSpec.ilvl)) {
  } else if (ilvl.compareTo(listSpec.ilvl)>0) {
      listSpec = new ListSpec(numId, BigInteger.valueOf(i));
      listSpec.sdtList = new SdtBlock();
      setTag(listSpec.sdtList, numId, ilvl);

代码示例来源:origin: org.codehaus.groovy/groovy

final BigInteger sizeNum = toNum.subtract(fromNum).add(new BigInteger("1"));
tempsize = sizeNum.intValue();
if (!BigInteger.valueOf(tempsize).equals(sizeNum)) {
  tempsize = Integer.MAX_VALUE;
final BigInteger sizeNum = toNum.subtract(fromNum).add(new BigDecimal(1.0)).toBigInteger();
tempsize = sizeNum.intValue();
if (!BigInteger.valueOf(tempsize).equals(sizeNum)) {
  tempsize = Integer.MAX_VALUE;

代码示例来源:origin: mcxiaoke/packer-ng-plugin

public int compareTo(Item item) {
  if (item == null) {
    return BIG_INTEGER_ZERO.equals(value) ? 0 : 1; // 1.0 == 1, 1.1 > 1
  }
  switch (item.getType()) {
    case INTEGER_ITEM:
      return value.compareTo(((IntegerItem) item).value);
    case STRING_ITEM:
      return 1; // 1.1 > 1-sp
    case LIST_ITEM:
      return 1; // 1.1 > 1-1
    default:
      throw new RuntimeException("invalid item: " + item.getClass());
  }
}

代码示例来源: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();
  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: checkstyle/checkstyle

/** Leaves while, do, for, if, ternary (?::), return or switch. */
private void leaveConditional() {
  final Values valuePair = popValue();
  final BigInteger expressionValue = valuePair.getExpressionValue();
  BigInteger basicRangeValue = valuePair.getRangeValue();
  if (currentRangeValue.equals(BigInteger.ZERO)) {
    currentRangeValue = BigInteger.ONE;
  }
  if (basicRangeValue.equals(BigInteger.ZERO)) {
    basicRangeValue = BigInteger.ONE;
  }
  currentRangeValue = currentRangeValue.add(expressionValue).multiply(basicRangeValue);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

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");
messageDigest.update(salt.toByteArray());
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: kiegroup/optaplanner

/**
 * @param from never null, inclusive minimum
 * @param to never null, exclusive maximum, {@code >= from}
 * @param incrementUnit never null, {@code > 0}
 */
public BigIntegerValueRange(BigInteger from, BigInteger to, BigInteger incrementUnit) {
  this.from = from;
  this.to = to;
  this.incrementUnit = incrementUnit;
  if (to.compareTo(from) < 0) {
    throw new IllegalArgumentException("The " + getClass().getSimpleName()
        + " cannot have a from (" + from + ") which is strictly higher than its to (" + to + ").");
  }
  if (incrementUnit.compareTo(BigInteger.ZERO) <= 0) {
    throw new IllegalArgumentException("The " + getClass().getSimpleName()
        + " must have strictly positive incrementUnit (" + incrementUnit + ").");
  }
  if (!to.subtract(from).remainder(incrementUnit).equals(BigInteger.ZERO)) {
    throw new IllegalArgumentException("The " + getClass().getSimpleName()
        + "'s incrementUnit (" + incrementUnit
        + ") must fit an integer number of times between from (" + from + ") and to (" + to + ").");
  }
}

代码示例来源: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);
}

代码示例来源:origin: ethereum/ethereumj

if (!expectedBalance.equals(actualBalance)) {
BigInteger actualGas = new BigInteger(1, gas).subtract(BigInteger.valueOf(program.getResult().getGasUsed()));
if (!expectedGas.equals(actualGas)) {

代码示例来源:origin: google/guava

@GwtIncompatible // TODO
@AndroidIncompatible // slow
public void testDivNonZeroExact() {
 boolean isAndroid = System.getProperties().getProperty("java.runtime.name").contains("Android");
 for (BigInteger p : NONZERO_BIGINTEGER_CANDIDATES) {
  for (BigInteger q : NONZERO_BIGINTEGER_CANDIDATES) {
   if (isAndroid && p.equals(BAD_FOR_ANDROID_P) && q.equals(BAD_FOR_ANDROID_Q)) {
    // https://code.google.com/p/android/issues/detail?id=196555
    continue;
   }
   if (isAndroid && p.equals(BAD_FOR_GINGERBREAD_P) && q.equals(BAD_FOR_GINGERBREAD_Q)) {
    // Works fine under Marshmallow, so I haven't filed a bug.
    continue;
   }
   boolean dividesEvenly = p.remainder(q).equals(ZERO);
   try {
    BigInteger quotient = BigIntegerMath.divide(p, q, UNNECESSARY);
    BigInteger undone = quotient.multiply(q);
    if (!p.equals(undone)) {
     failFormat("expected %s.multiply(%s) = %s; got %s", quotient, q, p, undone);
    }
    assertTrue(dividesEvenly);
   } catch (ArithmeticException e) {
    assertFalse(dividesEvenly);
   }
  }
 }
}

代码示例来源:origin: ethereum/ethereumj

expectedNonce = repo.getNonce(txSender);
curNonce.put(key, expectedNonce.add(ONE));
BigInteger txNonce = new BigInteger(1, tx.getNonce());
if (!expectedNonce.equals(txNonce)) {
  logger.warn("Invalid transaction: Tx nonce {} != expected nonce {} (parent nonce: {}): {}",
      txNonce, expectedNonce, repo.getNonce(txSender), tx);

代码示例来源:origin: stackoverflow.com

public static void main(String... args) {
  BigInteger fact = fact(100);
  System.out.println("fact(100) = " + fact);
  System.out.println("fact(100).longValue() = " + fact.longValue());
  System.out.println("fact(100).intValue() = " + fact.intValue());
  int powerOfTwoCount = 0;
  BigInteger two = BigInteger.valueOf(2);
  while (fact.compareTo(BigInteger.ZERO) > 0 && fact.mod(two).equals(BigInteger.ZERO)) {
    powerOfTwoCount++;
    fact = fact.divide(two);
  }
  System.out.println("fact(100) powers of two = " + powerOfTwoCount);
}

private static BigInteger fact(long n) {
  BigInteger result = BigInteger.ONE;
  for (long i = 2; i <= n; i++)
    result = result.multiply(BigInteger.valueOf(i));
  return result;
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Raise a BigInteger to a BigInteger power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, BigInteger e) throws NotPositiveException {
  if (e.compareTo(BigInteger.ZERO) < 0) {
    throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
  }
  BigInteger result = BigInteger.ONE;
  BigInteger k2p    = k;
  while (!BigInteger.ZERO.equals(e)) {
    if (e.testBit(0)) {
      result = result.multiply(k2p);
    }
    k2p = k2p.multiply(k2p);
    e = e.shiftRight(1);
  }
  return result;
}

相关文章