本文整理了Java中java.math.BigInteger.intValue()
方法的一些代码示例,展示了BigInteger.intValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.intValue()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:intValue
[英]Returns this BigInteger as an int value. If this is too big to be represented as an int, then this % (1 << 32) is returned.
[中]将此BigInteger作为int值返回。如果该值太大,无法表示为int,则返回该值%(1<<32)。
代码示例来源:origin: org.apache.ant/ant
/**
* Create a "magic number" for use in hashCode calculations.
* @param seed byte[] to seed with.
* @return a magic number as int.
*/
protected static int getMagicNumber(byte[] seed) {
return new BigInteger(seed).intValue();
}
代码示例来源:origin: LeonardoZ/java-concurrency-patterns
public void depositCoins(BigInteger amount) {
if (amount.intValue() < -1)
throw new IllegalArgumentException("Amount can't be negative");
this.coins = this.coins.add(amount);
}
代码示例来源:origin: stackoverflow.com
public static BigInteger factorial(BigInteger n) {
BigInteger factorial = BigInteger.valueOf(1);
for (int i = 1; i <= n.intValue(); i++) {
factorial = factorial.multiply(BigInteger.valueOf(i));
}
return factorial;
}
代码示例来源:origin: google/guava
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
case CEILING:
case UP:
int sqrtFloorInt = sqrtFloor.intValue();
boolean sqrtFloorIsExact =
(sqrtFloorInt * sqrtFloorInt == x.intValue()) // fast check mod 2^32
&& 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: org.apache.commons/commons-lang3
final BigInteger uvp = BigInteger.valueOf(numerator).multiply(BigInteger.valueOf(fraction.denominator / d1));
final BigInteger upv = BigInteger.valueOf(fraction.numerator).multiply(BigInteger.valueOf(denominator / d1));
final BigInteger t = isAdd ? uvp.add(upv) : uvp.subtract(upv);
final int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue();
final int d2 = tmodd1 == 0 ? d1 : greatestCommonDivisor(tmodd1, d1);
throw new ArithmeticException("overflow: numerator too large after multiply");
return new Fraction(w.intValue(), mulPosAndCheck(denominator / d1, fraction.denominator / d2));
代码示例来源: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: DiUS/java-faker
private static String calculateIbanChecksum(String countryCode, String basicBankAccountNumber) {
String basis = basicBankAccountNumber + countryCode + "00";
StringBuilder sb = new StringBuilder();
char[] characters = basis.toLowerCase().toCharArray();
for (char c : characters) {
if (Character.isLetter(c)) {
sb.append(String.valueOf((c - 'a') + 10));
} else {
sb.append(c);
}
}
int mod97 = new BigInteger(sb.toString()).mod(BigInteger.valueOf(97L)).intValue();
return StringUtils.leftPad(String.valueOf(98 - mod97), 2, '0');
}
代码示例来源:origin: google/guava
private static int saturatedCast(BigInteger big) {
if (big.compareTo(MAX_INT) > 0) {
return Integer.MAX_VALUE;
}
if (big.compareTo(MIN_INT) < 0) {
return Integer.MIN_VALUE;
}
return big.intValue();
}
代码示例来源:origin: wildfly/wildfly
private int validateFirstOIDComponent(BigInteger value) throws ASN1Exception {
if ((value.compareTo(BigInteger.valueOf(0)) == -1)
|| (value.compareTo(BigInteger.valueOf(2)) == 1)) {
throw log.asnInvalidValueForFirstOidComponent();
}
return value.intValue();
}
代码示例来源:origin: apache/tika
/**
* Returns encrypted integer
*
* @param data_chunk
*
* @return
*/
private int getEncint(byte[] data_chunk) {
byte ob;
BigInteger bi = BigInteger.ZERO;
byte[] nb = new byte[1];
if (placeHolder < data_chunk.length) {
while ((ob = data_chunk[placeHolder]) < 0) {
nb[0] = (byte) ((ob & 0x7f));
bi = bi.shiftLeft(7).add(new BigInteger(nb));
setPlaceHolder(placeHolder + 1);
}
nb[0] = (byte) ((ob & 0x7f));
bi = bi.shiftLeft(7).add(new BigInteger(nb));
setPlaceHolder(placeHolder + 1);
}
return bi.intValue();
}
代码示例来源:origin: com.github.Andy-Shao/Gear
@SuppressWarnings("unchecked")
public static final <ARRAY> ARRAY bitOxr(final ARRAY b1 , final ARRAY b2 , BigInteger size , ByteWrapper<ARRAY> byteWrapper) {
final BigInteger answers[] = size.divideAndRemainder(ByteOperation.EIGHT);
ARRAY result = (ARRAY) Array.newInstance(b1.getClass().getComponentType() , answers[1].intValue() == 0 ? answers[0].intValue() : answers[0].intValue() + 1);
ByteOperation.fill(0 , BigInteger.ZERO , size , result , byteWrapper);
for (BigInteger i = BigInteger.ZERO ; i.compareTo(size) == -1 ; i = i.add(BigInteger.ONE))
if (ByteOperation.bitGet(i , b1 , byteWrapper) != ByteOperation.bitGet(i , b2 , byteWrapper)) ByteOperation.bitSet(i , 1 , result , byteWrapper);
else ByteOperation.bitSet(i , 0 , result , byteWrapper);
return result;
}
代码示例来源:origin: prestodb/presto
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
case CEILING:
case UP:
int sqrtFloorInt = sqrtFloor.intValue();
boolean sqrtFloorIsExact =
(sqrtFloorInt * sqrtFloorInt == x.intValue()) // fast check mod 2^32
&& 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: robovm/robovm
/**
* Converts decoded ASN.1 Integer to int value.
* If the object represents an integer value
* larger than 32 bits, the high bits will be lost.
*
* @param decoded a decoded object corresponding to this type
* @return decoded int value.
*/
public static int toIntValue(Object decoded) {
return new BigInteger((byte[]) decoded).intValue();
}
代码示例来源:origin: stackoverflow.com
private static int gcdThing(int a, int b) {
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.intValue();
}
代码示例来源:origin: commons-lang/commons-lang
BigInteger uvp = BigInteger.valueOf(numerator)
.multiply(BigInteger.valueOf(fraction.denominator/d1));
BigInteger upv = BigInteger.valueOf(fraction.numerator)
.multiply(BigInteger.valueOf(denominator/d1));
BigInteger t = isAdd ? uvp.add(upv) : uvp.subtract(upv);
int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue();
int d2 = (tmodd1==0)?d1:greatestCommonDivisor(tmodd1, d1);
(w.intValue(),
mulPosAndCheck(denominator/d1, fraction.denominator/d2));
代码示例来源:origin: groovy/groovy-core
} else {
BigInteger v = new BigInteger(text);
if (v.compareTo(MAX_INTEGER) <= 0 && v.compareTo(MIN_INTEGER) >= 0) {
return v.intValue();
} else if (v.compareTo(MAX_LONG) <= 0 && v.compareTo(MIN_LONG) >= 0) {
return v.longValue();
} else {
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Power of a BigInteger to a BigInteger certain exponent. Called by the '**' operator.
*
* @param self a BigInteger
* @param exponent a BigInteger exponent
* @return a BigInteger to the power of a the exponent
* @since 2.3.8
*/
public static BigInteger power(BigInteger self, BigInteger exponent) {
if ((exponent.signum() >= 0) && (exponent.compareTo(BI_INT_MAX) <= 0)) {
return self.pow(exponent.intValue());
} else {
return BigDecimal.valueOf(Math.pow(self.doubleValue(), exponent.doubleValue())).toBigInteger();
}
}
代码示例来源: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: stackoverflow.com
BigInteger total = new Biginteger("1000000000000000");
BigInteger[] series = new BigInteger[total.intValue()];
series[0]=BigInteger.ZERO;
series[1]=BigInteger.ONE;
series[i] = series[i-1].add(series[i-2])`
代码示例来源:origin: plutext/docx4j
/**
* increments the current count of list items of that level
*/
public void IncrementCounter()
{
setCurrentValue( currentValue.add(BigInteger.ONE));
log.debug("counter now: " + currentValue.intValue() );
}
内容来源于网络,如有侵权,请联系作者删除!