本文整理了Java中java.math.BigInteger.valueOf()
方法的一些代码示例,展示了BigInteger.valueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.valueOf()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:valueOf
[英]Returns a BigInteger whose value is equal to value.
[中]返回一个BigInteger,其值等于value。
代码示例来源:origin: alibaba/druid
public static BigInteger castToBigInteger(Object val) {
if (val == null) {
return null;
}
if (val instanceof BigInteger) {
return (BigInteger) val;
}
if (val instanceof String) {
return new BigInteger((String) val);
}
return BigInteger.valueOf(((Number) val).longValue());
}
代码示例来源:origin: google/guava
@Override
BigInteger offset(BigInteger origin, long distance) {
checkNonnegative(distance, "distance");
return origin.add(BigInteger.valueOf(distance));
}
代码示例来源: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: apache/hbase
@Override
public byte[][] split(int n) {
Preconditions.checkArgument(lastRowInt.compareTo(firstRowInt) > 0,
"last row (%s) is configured less than first row (%s)", lastRow,
firstRow);
// +1 to range because the last row is inclusive
BigInteger range = lastRowInt.subtract(firstRowInt).add(BigInteger.ONE);
Preconditions.checkState(range.compareTo(BigInteger.valueOf(n)) >= 0,
"split granularity (%s) is greater than the range (%s)", n, range);
BigInteger[] splits = new BigInteger[n - 1];
BigInteger sizeOfEachSplit = range.divide(BigInteger.valueOf(n));
for (int i = 1; i < n; i++) {
// NOTE: this means the last region gets all the slop.
// This is not a big deal if we're assuming n << MAXHEX
splits[i - 1] = firstRowInt.add(sizeOfEachSplit.multiply(BigInteger
.valueOf(i)));
}
return convertToBytes(splits);
}
代码示例来源: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: prestodb/presto
private static long bigIntegerDecimalToGenericIntegerType(BigInteger bigInteger, int sourceScale, long minValue, long maxValue)
{
BigDecimal bigDecimal = new BigDecimal(bigInteger, sourceScale);
BigInteger unscaledValue = bigDecimal.setScale(0, FLOOR).unscaledValue();
if (unscaledValue.compareTo(BigInteger.valueOf(maxValue)) > 0) {
return maxValue;
}
if (unscaledValue.compareTo(BigInteger.valueOf(minValue)) < 0) {
return minValue;
}
return unscaledValue.longValueExact();
}
代码示例来源: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: ethereum/ethereumj
@Override
public ValidationResult validate(BlockHeader header) {
if (new BigInteger(1, header.getGasLimit()).compareTo(BigInteger.valueOf(MIN_GAS_LIMIT)) < 0) {
return fault("header.getGasLimit() < MIN_GAS_LIMIT");
}
return Success;
}
}
代码示例来源: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: apache/hbase
/**
* Divide 2 numbers in half (for split algorithm)
*
* @param a number #1
* @param b number #2
* @return the midpoint of the 2 numbers
*/
public BigInteger split2(BigInteger a, BigInteger b) {
return a.add(b).divide(BigInteger.valueOf(2)).abs();
}
代码示例来源: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: hibernate/hibernate-orm
public IntegralDataTypeHolder multiplyBy(long factor) {
checkInitialized();
value = value.multiply( BigInteger.valueOf( factor ) );
return this;
}
代码示例来源: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: deeplearning4j/nd4j
/**
* binomial (n choose m).
*
* @param n the numerator. Equals the size of the set to choose from.
* @param m the denominator. Equals the number of elements to select.
* @return the binomial coefficient.
*/
public static Rational binomial(Rational n, BigInteger m) {
if (m.compareTo(BigInteger.ZERO) == 0) {
return Rational.ONE;
}
Rational bin = n;
for (BigInteger i = BigInteger.valueOf(2); i.compareTo(m) != 1; i = i.add(BigInteger.ONE)) {
bin = bin.multiply(n.subtract(i.subtract(BigInteger.ONE))).divide(i);
}
return bin;
} /* Rational.binomial */
代码示例来源: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: hibernate/hibernate-orm
public IntegralDataTypeHolder subtract(long subtrahend) {
checkInitialized();
value = value.subtract( BigInteger.valueOf( subtrahend ) );
return this;
}
代码示例来源:origin: robovm/robovm
compRem = remainder.abs().shiftLeftOneBit().compareTo(scaledDivisor.abs());
compRem = roundingBehavior(quotient.testBit(0) ? 1 : 0,
sign * (5 + compRem), roundingMode);
return valueOf(quotient.longValue() + compRem,scale);
quotient = quotient.add(BigInteger.valueOf(compRem));
return new BigDecimal(quotient, scale);
代码示例来源: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: ethereum/ethereumj
public long mine(long fullSize, int[] dataset, byte[] blockHeaderTruncHash, long difficulty, long startNonce) {
long nonce = startNonce;
BigInteger target = valueOf(2).pow(256).divide(valueOf(difficulty));
while (!Thread.currentThread().isInterrupted()) {
nonce++;
Pair<byte[], byte[]> pair = hashimotoFull(fullSize, dataset, blockHeaderTruncHash, longToBytes(nonce));
BigInteger h = new BigInteger(1, pair.getRight() /* ?? */);
if (h.compareTo(target) < 0) break;
}
return nonce;
}
内容来源于网络,如有侵权,请联系作者删除!