本文整理汇总了Java中java.math.BigInteger.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.compareTo方法的具体用法?Java BigInteger.compareTo怎么用?Java BigInteger.compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.compareTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCmp
import java.math.BigInteger; //导入方法依赖的package包/类
private static void testCmp(FDBigInteger t, FDBigInteger o) throws Exception {
BigInteger bt = t.toBigInteger();
BigInteger bo = o.toBigInteger();
int cmp = t.cmp(o);
int bcmp = bt.compareTo(bo);
if (bcmp != cmp) {
throw new Exception("cmp returns " + cmp + " expected " + bcmp);
}
check(bt, t, "cmp corrupts this");
check(bo, o, "cmp corrupts other");
if (o.cmp(t) != -cmp) {
throw new Exception("asymmetrical cmp");
}
check(bt, t, "cmp corrupts this");
check(bo, o, "cmp corrupts other");
}
示例2: validate
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public boolean validate(BlockHeader header, BlockHeader parent) {
errors.clear();
BigInteger headerGasLimit = new BigInteger(1, header.getGasLimit());
BigInteger parentGasLimit = new BigInteger(1, parent.getGasLimit());
if (headerGasLimit.compareTo(parentGasLimit.multiply(BigInteger.valueOf(GAS_LIMIT_BOUND_DIVISOR - 1)).divide(BigInteger.valueOf(GAS_LIMIT_BOUND_DIVISOR))) < 0 ||
headerGasLimit.compareTo(parentGasLimit.multiply(BigInteger.valueOf(GAS_LIMIT_BOUND_DIVISOR + 1)).divide(BigInteger.valueOf(GAS_LIMIT_BOUND_DIVISOR))) > 0) {
errors.add(String.format(
"#%d: gas limit exceeds parentBlock.getGasLimit() (+-) GAS_LIMIT_BOUND_DIVISOR",
header.getNumber()
));
return false;
}
return true;
}
示例3: decodeBitListFromBigInteger
import java.math.BigInteger; //导入方法依赖的package包/类
public static int[] decodeBitListFromBigInteger(BigInteger bits) {
List<Integer> resultList = new ArrayList<Integer>();
BigInteger mask = BigInteger.ONE;
int valueCandidate = 1;
while (mask.compareTo(bits) <= 0) {
if ((mask.and(bits)).equals(mask)) {
resultList.add(Integer.valueOf(valueCandidate));
}
valueCandidate++;
mask = mask.shiftLeft(1);
}
int[] result = new int[resultList.size()];
for (int i = 0; i < result.length; i++) {
result[i] = resultList.get(i).intValue();
}
return result;
}
示例4: decomposition
import java.math.BigInteger; //导入方法依赖的package包/类
public static Map<BigInteger, BigInteger> decomposition(BigInteger n) throws Exception{
if(n.compareTo(BigInteger.ONE)!=1) throw new Exception("Not a positive integer.");
BigInteger max = bigIntSqRootCeil(n);
Map<BigInteger, BigInteger> map = new HashMap<BigInteger,BigInteger>();
for (BigInteger i = BigInteger.valueOf(2L); i.compareTo(max)<1;i=i.add(BigInteger.ONE)) {
boolean ipremier = true;
if(!i.equals(BigInteger.valueOf(2L)))
for (BigInteger j = BigInteger.valueOf(2L); j.compareTo(bigIntSqRootCeil(i))<1 && ipremier; j=j.add(BigInteger.ONE)){
if(i.mod(j).intValue()==0)ipremier=false;
}
if(!ipremier) continue;
if(n.mod(i).intValue()==0){
map.put(i, map.getOrDefault(i, BigInteger.ZERO).add(BigInteger.ONE));
n=n.divide(i);
max = bigIntSqRootCeil(n);
i=BigInteger.ONE;
}
}
map.put(n, map.getOrDefault(n, BigInteger.ZERO).add(BigInteger.ONE));
return map;
}
示例5: getIPv6Address
import java.math.BigInteger; //导入方法依赖的package包/类
String getIPv6Address() {
if (BuildConfig.DEBUG) Assert.assertTrue(!isV4);
BigInteger r = netAddress;
String ipv6str = null;
boolean lastPart = true;
while (r.compareTo(BigInteger.ZERO) == 1) {
long part = r.mod(BigInteger.valueOf(0x10000)).longValue();
if (ipv6str != null || part != 0) {
if (ipv6str == null && !lastPart) ipv6str = ":";
if (lastPart) ipv6str = String.format(Locale.US, "%x", part, ipv6str);
else ipv6str = String.format(Locale.US, "%x:%s", part, ipv6str);
}
r = r.shiftRight(16);
lastPart = false;
}
if (ipv6str == null) return "::";
return ipv6str;
}
示例6: compareTo
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public int compareTo(Field other) {
if (other == null || !(other instanceof FieldNum)) {
return 1;
}
FieldNum bOther = (FieldNum) other;
BigInteger intValue1 = this.valInt();
BigInteger intValue2 = bOther.valInt();
if (intValue1 == null && intValue2 == null)
return 0;
else if (intValue2 == null)
return 1;
else if (intValue1 == null)
return -1;
else
return intValue1.compareTo(intValue2);
}
示例7: checkPrime
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Verifies whether the fraction of probable primes detected is at least 1 -
* 1/2^certainty.
*
* @return true if and only if the test succeeds
*/
private static boolean checkPrime(Set<BigInteger> primes,
int certainty,
boolean parallel) {
long probablePrimes = (parallel ? primes.parallelStream() : primes.stream())
.filter(bi -> bi.isProbablePrime(certainty))
.count();
// N = certainty / 2
// Success if p/t >= 1 - 1/4^N
// or (p/t)*4^N >= 4^N - 1
// or p*4^N >= t*(4^N - 1)
BigInteger p = BigInteger.valueOf(probablePrimes);
BigInteger t = BigInteger.valueOf(primes.size());
BigInteger fourToTheC = BigInteger.valueOf(4).pow(certainty / 2);
BigInteger fourToTheCMinusOne = fourToTheC.subtract(BigInteger.ONE);
BigInteger left = p.multiply(fourToTheC);
BigInteger right = t.multiply(fourToTheCMinusOne);
if (left.compareTo(right) < 0) {
System.err.println("Probable prime certainty test failed");
}
return left.compareTo(right) >= 0;
}
示例8: lessThan
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Is the first number less than the second number?
*
* @param number1 the first number to compare, not null
* @param number2 the second number to compare, not null
* @return true if the first number is less than the second number, not null
*/
@Nonnull
static Boolean lessThan(@Nonnull BigInteger number1, @Nonnull BigInteger number2) {
requireNonNull(number1);
requireNonNull(number2);
return number1.compareTo(number2) < 0;
}
示例9: getInteger
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the integer which takes up the specified number
* of bytes in this buffer.
* @throws IOException if the result is not within the valid
* range for integer, i.e. between Integer.MIN_VALUE and
* Integer.MAX_VALUE.
* @param len the number of bytes to use.
* @return the integer.
*/
public int getInteger(int len) throws IOException {
BigInteger result = getBigInteger(len, false);
if (result.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0) {
throw new IOException("Integer below minimum valid value");
}
if (result.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
throw new IOException("Integer exceeds maximum valid value");
}
return result.intValue();
}
示例10: checkBigIntegerInIntRange
import java.math.BigInteger; //导入方法依赖的package包/类
private static int checkBigIntegerInIntRange(ASN1Encodable a)
{
BigInteger b = ((ASN1Integer)a).getValue();
if ((b.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) ||
(b.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0))
{
throw new IllegalArgumentException("BigInteger not in Range: " + b.toString());
}
return b.intValue();
}
示例11: randomBigInteger
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* @param upperbound exclusive upperbound
* @return a random BigInteger in range [0, upperbound)
*/
public BigInteger randomBigInteger(BigInteger upperbound) {
for (int i = 0; i < MAX_ITERATIONS; i++) {
BigInteger x = new BigInteger(upperbound.bitLength(), secureRandom);
if (x.compareTo(upperbound) < 0) {
return x;
}
}
// If we fail to get a value within range for MAX_ITERATIONS, get a value with lower bitCount
return new BigInteger(upperbound.bitLength() - 1, secureRandom);
}
示例12: digits
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Evaluates the number of digits of a {@link BigInteger}.
*
* @param n The BigInteger to be tested.
* @throws NullPointerException if {@code n} is null.
* @throws IllegalArgumentException if {@code n} is less than or equal to zero.
* @return an {@link Integer} representing the number of digits.
*/
public static Integer digits(final BigInteger n) {
if (n == null)
throw new NullPointerException("n value can't be null");
if (n.compareTo(ZERO) <= 0)
throw new IllegalArgumentException("n value must be greater than zero");
return n.toString().length();
}
示例13: compareBigIntegerValue
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* The Function will compare bigInteger values
* @param value1
* @param value2
* @return
*/
private int compareBigIntegerValue(String value1, String value2){
BigInteger int1= BigInteger.valueOf(Long.parseLong(value1));
BigInteger int2 = BigInteger.valueOf(Long.parseLong(value2));
return int1.compareTo(int2);
}
示例14: setF
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* @param f
*/
public void setF(BigInteger f) {
if (e == null)
throw new IllegalStateException("DhDsaExchange not initialized!");
BigInteger zero = BigInteger.valueOf(0);
if (zero.compareTo(f) >= 0 || p.compareTo(f) <= 0)
throw new IllegalArgumentException("Invalid f specified!");
this.f = f;
this.k = f.modPow(x, p);
}
示例15: testAddAndCmp
import java.math.BigInteger; //导入方法依赖的package包/类
private static void testAddAndCmp(FDBigInteger t, FDBigInteger x, FDBigInteger y) throws Exception {
BigInteger bt = t.toBigInteger();
BigInteger bx = x.toBigInteger();
BigInteger by = y.toBigInteger();
int cmp = t.addAndCmp(x, y);
int bcmp = bt.compareTo(bx.add(by));
if (bcmp != cmp) {
throw new Exception("addAndCmp returns " + cmp + " expected " + bcmp);
}
check(bt, t, "addAndCmp corrupts this");
check(bx, x, "addAndCmp corrupts x");
check(by, y, "addAndCmp corrupts y");
}