本文整理了Java中java.math.BigInteger.longValue()
方法的一些代码示例,展示了BigInteger.longValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.longValue()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:longValue
[英]Returns this BigInteger as a long value. If this is too big to be represented as a long, then this % pow(2, 64) is returned.
[中]将此BigInteger作为长值返回。如果该值太大,无法表示为long,则返回该%pow(2,64)。
代码示例来源:origin: spring-projects/spring-framework
public AlternativeJdkIdGenerator() {
SecureRandom secureRandom = new SecureRandom();
byte[] seed = new byte[8];
secureRandom.nextBytes(seed);
this.random = new Random(new BigInteger(seed).longValue());
}
代码示例来源:origin: ethereum/ethereumj
private byte getRealV(BigInteger bv) {
if (bv.bitLength() > 31) return 0; // chainId is limited to 31 bits, longer are not valid for now
long v = bv.longValue();
if (v == LOWER_REAL_V || v == (LOWER_REAL_V + 1)) return (byte) v;
byte realV = LOWER_REAL_V;
int inc = 0;
if ((int) v % 2 == 0) inc = 1;
return (byte) (realV + inc);
}
代码示例来源: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: redisson/redisson
BigInteger n = new BigInteger(_cleanedTextValue);
if (len == 19 && n.bitLength() <= 63) {
_numberLong = n.longValue();
_numTypesValid = NR_LONG;
return;
代码示例来源: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
BigInteger txGasLimit = new BigInteger(1, tx.getGasLimit());
BigInteger curBlockGasLimit = new BigInteger(1, currentBlock.getGasLimit());
boolean cumulativeGasReached = txGasLimit.add(BigInteger.valueOf(gasUsedInTheBlock)).compareTo(curBlockGasLimit) > 0;
if (cumulativeGasReached) {
execError(String.format("Too much gas used in this block: Require: %s Got: %s", new BigInteger(1, currentBlock.getGasLimit()).longValue() - toBI(tx.getGasLimit()).longValue(), toBI(tx.getGasLimit()).longValue()));
if (txGasLimit.compareTo(BigInteger.valueOf(basicTxCost)) < 0) {
代码示例来源:origin: org.apache.ant/ant
private static long parseBinaryBigInteger(final byte[] buffer,
final int offset,
final int length,
final boolean negative) {
final byte[] remainder = new byte[length - 1];
System.arraycopy(buffer, offset + 1, remainder, 0, length - 1);
BigInteger val = new BigInteger(remainder);
if (negative) {
// 2's complement
val = val.add(BigInteger.valueOf(-1)).not();
}
if (val.bitLength() > 63) {
throw new IllegalArgumentException(String.format(
"At offset %d, %d byte binary number exceeds maximum signed long value",
offset, length));
}
return negative ? -val.longValue() : val.longValue();
}
代码示例来源: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: ethereum/ethereumj
BigInteger max = BigInteger.valueOf(2).pow(255);
byte[] target = BigIntegers.asUnsignedByteArray(32,
max.divide(new BigInteger(1, difficulty)));
(new BigInteger(1, newBlock.getGasLimit()).longValue() * (1024 - 1) + (newBlock.getGasUsed() * 6 / 5)) / 1024);
newBlock.getHeader().setGasLimit(BigInteger.valueOf(newGasLimit).toByteArray());
System.out.println("mining: " + new BigInteger(1, testNonce));
代码示例来源:origin: google/guava
private static long saturatedCast(BigInteger big) {
if (big.compareTo(MAX_LONG) > 0) {
return Long.MAX_VALUE;
}
if (big.compareTo(MIN_LONG) < 0) {
return Long.MIN_VALUE;
}
return big.longValue();
}
代码示例来源:origin: robovm/robovm
if(scaledDivisor.bitLength() < 63) { // 63 in order to avoid out of long after *2
long rem = remainder.longValue();
long divisor = scaledDivisor.longValue();
compRem = longCompareTo(Math.abs(rem) * 2,Math.abs(divisor));
compRem = remainder.abs().shiftLeftOneBit().compareTo(scaledDivisor.abs());
compRem = roundingBehavior(quotient.testBit(0) ? 1 : 0,
sign * (5 + compRem), roundingMode);
if(quotient.bitLength() < 63) {
return valueOf(quotient.longValue() + compRem,scale);
quotient = quotient.add(BigInteger.valueOf(compRem));
return new BigDecimal(quotient, scale);
代码示例来源:origin: ethereum/ethereumj
public long getCumulativeGasLong() {
return new BigInteger(1, cumulativeGas).longValue();
}
代码示例来源:origin: google/guava
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
return (halfSquare.compareTo(x) >= 0) ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
default:
throw new AssertionError();
代码示例来源:origin: osmandapp/Osmand
BigInteger bigValue = new BigInteger(numberText, radix);
if (negative) {
bigValue = bigValue.negate();
if (bigValue.bitLength() > 31) {
throw new NumberFormatException(
"Number out of range for 32-bit signed integer: " + text);
if (bigValue.bitLength() > 32) {
throw new NumberFormatException(
"Number out of range for 32-bit unsigned integer: " + text);
if (bigValue.bitLength() > 63) {
throw new NumberFormatException(
"Number out of range for 64-bit signed integer: " + text);
result = bigValue.longValue();
代码示例来源:origin: debezium/debezium
private static LocalDateTime nanosToLocalDateTimeUTC(long epocNanos) {
// the pg plugin stores date/time info as microseconds since epoch
BigInteger epochMicrosBigInt = BigInteger.valueOf(epocNanos);
BigInteger[] secondsAndNanos = epochMicrosBigInt.divideAndRemainder(BigInteger.valueOf(TimeUnit.SECONDS.toNanos(1)));
return LocalDateTime.ofInstant(Instant.ofEpochSecond(secondsAndNanos[0].longValue(), secondsAndNanos[1].longValue()),
ZoneOffset.UTC);
}
代码示例来源:origin: org.apache.commons/commons-compress
private static long parseBinaryBigInteger(final byte[] buffer,
final int offset,
final int length,
final boolean negative) {
final byte[] remainder = new byte[length - 1];
System.arraycopy(buffer, offset + 1, remainder, 0, length - 1);
BigInteger val = new BigInteger(remainder);
if (negative) {
// 2's complement
val = val.add(BigInteger.valueOf(-1)).not();
}
if (val.bitLength() > 63) {
throw new IllegalArgumentException("At offset " + offset + ", "
+ length + " byte binary number"
+ " exceeds maximum signed long"
+ " value");
}
return negative ? -val.longValue() : val.longValue();
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Get exactly number value and type.
*
* @param value string to be converted
* @param radix radix
* @return exactly number value and type
*/
public static Number getExactlyNumber(final String value, final int radix) {
BigInteger result = new BigInteger(value, radix);
if (result.compareTo(new BigInteger(String.valueOf(Integer.MIN_VALUE))) >= 0 && result.compareTo(new BigInteger(String.valueOf(Integer.MAX_VALUE))) <= 0) {
return result.intValue();
}
if (result.compareTo(new BigInteger(String.valueOf(Long.MIN_VALUE))) >= 0 && result.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) <= 0) {
return result.longValue();
}
return result;
}
}
代码示例来源:origin: hierynomus/sshj
public T putUInt64(BigInteger uint64) {
if (uint64.compareTo(MAX_UINT64_VALUE) > 0 ||
uint64.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException("Invalid value: " + uint64);
}
return putUInt64Unchecked(uint64.longValue());
}
代码示例来源:origin: robovm/robovm
private void setUnscaledValue(BigInteger unscaledValue) {
this.intVal = unscaledValue;
this.bitLength = unscaledValue.bitLength();
if(this.bitLength < 64) {
this.smallValue = unscaledValue.longValue();
}
}
代码示例来源:origin: robovm/robovm
compRem = quotAndRem[1].shiftLeftOneBit().compareTo(powerOfTen);
BigInteger.valueOf((compRem * (compRem + 3)) / 2 + 1));
exponent -= 2;
discardedSize = mantissa.bitLength() - 54;
if (discardedSize > 0) {// (n > 54)
bits = mantissa.shiftRight(discardedSize).longValue();
tempBits = bits;
bits = mantissa.longValue() << -discardedSize;
tempBits = bits;
内容来源于网络,如有侵权,请联系作者删除!