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

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

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

BigInteger.intValueExact介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

final DERDecoder decoder = new DERDecoder(encoded);
final CertificateFactory certificateFactory = CertificateFactory.getInstance(X_509);
final int count = decoder.decodeInteger().intValueExact();
final X509Certificate[] array = new X509Certificate[count];
decoder.startSequence();

代码示例来源:origin: pholser/junit-quickcheck

private Period fromBigInteger(BigInteger period) {
    BigInteger[] monthsAndDays = period.divideAndRemainder(THIRTY_ONE);
    BigInteger[] yearsAndMonths = monthsAndDays[0].divideAndRemainder(TWELVE);

    return Period.of(
      yearsAndMonths[0].intValueExact(),
      yearsAndMonths[1].intValueExact(),
      monthsAndDays[1].intValueExact());
  }
}

代码示例来源:origin: DataSketches/sketches-core

/**
 * Returns the next prime number that is greater than the given target. There will be
 * no prime numbers less than the returned prime number that are greater than the given target.
 * @param target the starting value to begin the search for the next prime
 * @return the next prime number that is greater than the given target.
 */
static int nextPrime(final int target) {
 return BigInteger.valueOf(target).nextProbablePrime().intValueExact();
}

代码示例来源:origin: org.ow2.authzforce/authzforce-ce-core-pdp-api

@Override
public int intValueExact() throws ArithmeticException
{
  return value.intValueExact();
}

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

private static int digitSum(final BigInteger someInteger)
{
  int ret = 0;
  BigInteger b = someInteger;
  BigInteger[] modResult;

  while (b.compareTo(BigInteger.ZERO) > 0) {
    modResult = b.divideAndRemainter(BigInteger.TEN);
    ret += modResult[1].intValueExact();
    b = modResult[0];
  }

  return ret;
}

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

public static int getIntFromInput(String inputString) {

  //sanity checks
  if (inputString == null || inputString.trim().length() == 0) {
    throw new IllegalArgumentException("empty or null string passed");
  }

  try {
    return new BigInteger(inputString, 10).intValueExact();
  } catch (Exception ignored) {
    throw new IllegalArgumentException(String.format("input string is not a valid integer number: '%s'", inputString));
  }
}

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

public static int myRandom(int min, int max, Random r){
  if (max <= min)
    throw new RuntimeException("max value must be greater than min value: max="+max +", min="+min);

  BigInteger maxB = BigInteger.valueOf(max);
  BigInteger minB = BigInteger.valueOf(min);

  BigInteger range = maxB.subtract(minB);
  do{
    BigInteger result = new BigInteger(range.bitLength(), r);
    if (result.compareTo(range)<=0)
      return result.add(minB).intValueExact();
  }while(true);
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-queryalgebra-evaluation

@Override
protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue)
  throws ArithmeticException
{
  if (integerValue.compareTo(BigInteger.ZERO) >= 0) {
    return Optional.of(vf.createLiteral(String.valueOf(integerValue.intValueExact()), XMLSchema.UNSIGNED_INT));
  }
  return Optional.empty();
}

代码示例来源:origin: de.tudarmstadt.ukp.inception.rdf4j/rdf4j-queryalgebra-evaluation

@Override
protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue)
  throws ArithmeticException
{
  return Optional.of(vf.createLiteral(integerValue.intValueExact()));
}

代码示例来源:origin: de.tudarmstadt.ukp.inception.rdf4j/rdf4j-queryalgebra-evaluation

@Override
protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue)
  throws ArithmeticException
{
  if (integerValue.compareTo(BigInteger.ZERO) >= 0) {
    return Optional.of(vf.createLiteral(String.valueOf(integerValue.intValueExact()), XMLSchema.UNSIGNED_INT));
  }
  return Optional.empty();
}

代码示例来源:origin: com.pholser/junit-quickcheck-generators

private Period fromBigInteger(BigInteger period) {
    BigInteger[] monthsAndDays = period.divideAndRemainder(THIRTY_ONE);
    BigInteger[] yearsAndMonths = monthsAndDays[0].divideAndRemainder(TWELVE);

    return Period.of(
      yearsAndMonths[0].intValueExact(),
      yearsAndMonths[1].intValueExact(),
      monthsAndDays[1].intValueExact());
  }
}

代码示例来源:origin: com.yahoo.datasketches/sketches-core

/**
 * Returns the next prime number that is greater than the given target. There will be
 * no prime numbers less than the returned prime number that are greater than the given target.
 * @param target the starting value to begin the search for the next prime
 * @return the next prime number that is greater than the given target.
 */
static int nextPrime(final int target) {
 return BigInteger.valueOf(target).nextProbablePrime().intValueExact();
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-queryalgebra-evaluation

@Override
protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue)
  throws ArithmeticException
{
  return Optional.of(vf.createLiteral(integerValue.intValueExact()));
}

代码示例来源:origin: org.beryx/streamplify

@Override
  public int[] unrank() {
    int[] product = new int[dimensions.length];
    BigInteger dividend = currentIndex;
    for(int k = dimensions.length - 1; k >= 0; k--) {
      BigInteger[] quotientAndRemainder = dividend.divideAndRemainder(BigInteger.valueOf(dimensions[k]));
      product[k] = quotientAndRemainder[1].intValueExact();
      dividend = quotientAndRemainder[0];
    }
    return product;
  }
}

代码示例来源:origin: FISCO-BCOS/web3sdk

public void setV(Object v) {
  if (v instanceof String) {
    this.v = Numeric.toBigInt((String) v).intValueExact();
  } else {
    this.v = ((Integer) v);
  }
}

代码示例来源:origin: de.pfabulist.bigchin/bigchin-list

@Override
public Optional<T> get( BigInteger idx ) {
  if( idx.signum() < 0 || idx.compareTo( size ) >= 0 ) {
    return Optional.empty();
  }
  InternalValues.Intern first = new InternalValues.Intern();
  calcInternal( first, idx );
  return Optional.of(
      firstMap.get( first.fist ).
          get( first.second.intValueExact() ));
  
}

代码示例来源:origin: leangen/graphql-spqr

@Override
public Object parseValue(Object input) {
  if (input instanceof Number || input instanceof String) {
    try {
      return new IntNode(new BigInteger(input.toString()).intValueExact());
    } catch (ArithmeticException e) {
      throw new CoercingParseValueException(input + " does not fit into an int without a loss of precision");
    }
  }
  if (input instanceof IntNode) {
    return input;
  }
  throw valueParsingException(input, Number.class, String.class, IntNode.class);
}

代码示例来源:origin: kframework/k

public static IntToken shr(IntToken term1, IntToken term2, TermContext context) {
  try {
    return IntToken.of(term1.bigIntegerValue().shiftRight(term2.bigIntegerValue().intValueExact()));
  } catch (ArithmeticException e) {
    if (term1.bigIntegerValue().compareTo(BigInteger.ZERO) >= 0) {
      return IntToken.of(0);
    } else {
      return IntToken.of(-1);
    }
  }
}

代码示例来源:origin: leangen/graphql-spqr

@Override
  public Object parseLiteral(Object input) {
    if (input instanceof IntValue) {
      try {
        return new IntNode(((IntValue) input).getValue().intValueExact());
      } catch (ArithmeticException e) {
        throw new CoercingParseLiteralException(input + " does not fit into an int without a loss of precision");
      }
    } else {
      throw new CoercingParseLiteralException(errorMessage(input, IntValue.class));
    }
  }
});

代码示例来源:origin: jlink/jqwik

@Example
void withFilter() {
  Shrinkable<BigInteger> shrinkable = createShrinkableBigInteger(100000, Range.of(0L, 1000000L));
  Falsifier<BigInteger> falsifier = aBigInteger -> aBigInteger.intValueExact() < 99;
  Falsifier<BigInteger> filteredFalsifier = falsifier.withFilter(aBigInteger -> aBigInteger.intValueExact() % 2 == 0);
  ShrinkingSequence<BigInteger> sequence = shrinkable.shrink(filteredFalsifier);
  while (sequence.next(count, reporter));
  assertThat(sequence.current().value()).isEqualTo(100);
  assertThat(counter.get()).isEqualTo(8);
}

相关文章