Java Code Examples for java.math.BigInteger#max()

The following examples show how to use java.math.BigInteger#max() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cashuwallet   File: SochainAPI.java    License: MIT License 6 votes vote down vote up
@Override
public BigInteger getFeeEstimate() {
    try {
        String url1 = baseUrl.replace("*", "get_info");
        JSONObject data1 = new JSONObject(urlFetch(url1));
        data1 = data1.getJSONObject("data");
        long height = data1.getLong("blocks");
        String url2 = baseUrl.replace("*", "block") + "/" + height;
        JSONObject data2 = new JSONObject(urlFetch(url2));
        data2 = data2.getJSONObject("data");
        BigInteger fees = new BigDecimal(data2.getString("fee")).multiply(BigDecimal.TEN.pow(8)).toBigInteger();
        BigInteger size = BigInteger.valueOf(data2.getLong("size"));
        BigInteger fee = fees.multiply(BigInteger.valueOf(1024)).divide(size);
        return fee.max(BigInteger.valueOf(1024));
    } catch (Exception e) {
        return null;
    }
}
 
Example 2
Source Project: j2objc   File: BigIntegerCompareTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * max(BigInteger val).
 * the first is greater.
 */
public void testMaxGreater() {
    byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
    byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
    int aSign = 1;
    int bSign = 1;        
    byte rBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger bNumber = new BigInteger(bSign, bBytes);
    BigInteger result = aNumber.max(bNumber);
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }    
    assertTrue("incorrect sign", result.signum() == 1);
}
 
Example 3
Source Project: j2objc   File: BigIntegerCompareTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * max(BigInteger val).
 * the first is less.
 */
public void testMaxLess() {
    byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
    byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
    int aSign = 1;
    int bSign = 1;        
    byte rBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger bNumber = new BigInteger(bSign, bBytes);
    BigInteger result = aNumber.max(bNumber);
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }    
    assertTrue("incorrect sign", result.signum() == 1);
}
 
Example 4
Source Project: j2objc   File: BigIntegerCompareTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * max(BigInteger val).
 * numbers are equal.
 */
public void testMaxEqual() {
    byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
    byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
    int aSign = 1;
    int bSign = 1;        
    byte rBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger bNumber = new BigInteger(bSign, bBytes);
    BigInteger result = aNumber.max(bNumber);
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }    
    assertEquals("incorrect sign", 1, result.signum());
}
 
Example 5
/**
 * * Returns the smallest range that will be fully decomposed (i.e. decomposition stops when the
 * range is equal or smaller than this value). Values is based on the _maximumRangeDecompsed and
 * _minRangeDecompsed instance members.
 *
 * @param minRangeList minimum values for each dimension (ordered)
 * @param maxRangeList maximum values for each dimension (ordered)
 * @return largest range that will be fully decomposed
 */
private BigInteger getMinimumQuadSize(
    final List<BigInteger> minRangeList,
    final List<BigInteger> maxRangeList) {
  BigInteger maxRange = BigInteger.valueOf(1);
  final int dimensionality = Math.min(minRangeList.size(), maxRangeList.size());
  for (int d = 0; d < dimensionality; d++) {
    maxRange =
        maxRange.max(maxRangeList.get(d).subtract(minRangeList.get(d)).abs().add(BigInteger.ONE));
  }
  final BigInteger maxRangeDecomposed = maxRange.pow(dimensionality);
  if (maxRangeDecomposed.compareTo(UNIT_CELL_SIZE) <= 0) {
    return BigInteger.ONE;
  }

  return maxRangeDecomposed.divide(UNIT_CELL_SIZE);
}
 
Example 6
Source Project: presto   File: TypeCalculation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BigInteger visitBinaryFunction(BinaryFunctionContext ctx)
{
    BigInteger left = visit(ctx.left);
    BigInteger right = visit(ctx.right);
    switch (ctx.binaryFunctionName().name.getType()) {
        case MIN:
            return left.min(right);
        case MAX:
            return left.max(right);
        default:
            throw new IllegalArgumentException("Unsupported binary function " + ctx.binaryFunctionName().getText());
    }
}
 
Example 7
public static void main(String[] args) {
	//if (args==null)
	Scanner userInput = new Scanner(System.in).useDelimiter("[,\\s+]");
	System.out.println("Please enter an range of integer (comma or space separated): ");
	//Only BigDecimal understand scientific notation
	BigInteger stop = userInput.nextBigDecimal().toBigIntegerExact();
	BigInteger start = userInput.hasNextLine()?userInput.nextBigDecimal().toBigIntegerExact():THREE;

	userInput.close();

	if (stop.compareTo(start) < 0) {
		BigInteger tmp = start;
		start = stop;
		stop = tmp;
	}

	start = start.max(THREE);
	BigInteger end = stop.max(THREE);

	start_num = start.or(ONE); 			 // if start_num even add 1
	end_num = end.subtract(ONE).or(ONE); // if end_num even subtract 1

	PGparam.Lstart = start_num.longValue();
	PGparam.Lend = end_num.longValue();

	twinprimes_ssoz();
}
 
Example 8
Source Project: j2objc   File: BigIntegerCompareTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * max(BigInteger val).
 * max of negative and ZERO.
 */
public void testMaxNegZero() {
    byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
    int aSign = -1;
    byte rBytes[] = {0};
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    BigInteger bNumber = BigInteger.ZERO;
    BigInteger result = aNumber.max(bNumber);
    byte resBytes[] = new byte[rBytes.length];
    resBytes = result.toByteArray();
    for(int i = 0; i < resBytes.length; i++) {
        assertTrue(resBytes[i] == rBytes[i]);
    }    
    assertTrue("incorrect sign", result.signum() == 0);
}
 
Example 9
private static BigInteger doWork(BigInteger arg1, BigInteger arg2, KNOWN_OP op) {
    if (arg1 == null) {
        return arg2;
    } else if (arg2 == null) {
        return arg1;
    } else {
        BigInteger retVal = null;
        switch (op) {
        case SUM:
            retVal = arg1.add(arg2);
            break;
        case MAX:
            if (BigIntegerWrapper.class.isInstance(arg1) && (((BigIntegerWrapper)arg1).isNegativeInfinity())) {
                retVal = arg2;
            } else if(BigIntegerWrapper.class.isInstance(arg2) && (((BigIntegerWrapper)arg2).isNegativeInfinity())) {
                retVal = arg1;
            } else {
                retVal = arg1.max(arg2);
            }
            break;
        case MIN:
            if (BigIntegerWrapper.class.isInstance(arg1) && (((BigIntegerWrapper)arg1).isPositiveInfinity())) {
                retVal = arg2;
            } else if (BigIntegerWrapper.class.isInstance(arg2) && (((BigIntegerWrapper)arg2).isPositiveInfinity())) {
                retVal = arg1;
            } else{
                retVal = arg1.min(arg2);
            }
            break;
        default:
            retVal = null;
            break;
        }
        return retVal;
    }
}
 
Example 10
Source Project: ghidra   File: MarkerSetImpl.java    License: Apache License 2.0 4 votes vote down vote up
public ProgramLocation getProgramLocation(int y, int height, AddressIndexMap map, int x) {

		assertSwing();
		if (overview == null) {
			return null;
		}

		ProgramLocation loc = null;
		if (overviewContains(y)) {
			y -= MARKER_HEIGHT - 1;
			if (y < 0) {
				y = 0;
			}

			BigDecimal bigHeight = BigDecimal.valueOf(height);
			BigInteger bigStarty = BigInteger.valueOf(y);
			BigInteger bigEndy = BigInteger.valueOf(y + MARKER_HEIGHT);
			BigInteger numIndexes = map.getIndexCount();
			BigInteger numIndexesMinus1 = numIndexes.subtract(BigInteger.ONE);
			numIndexesMinus1.max(BigInteger.ZERO);

			BigInteger start = getIndex(bigStarty, bigHeight, numIndexes, numIndexesMinus1);
			BigInteger end = getIndex(bigEndy, bigHeight, numIndexes, numIndexesMinus1);

			FieldSelection fs = new FieldSelection();
			fs.addRange(start, end.add(BigInteger.ONE));
			AddressSet set = map.getAddressSet(fs);

			if (set.isEmpty()) {
				return null;
			}

			Address addr = markers.findFirstAddressInCommon(set);
			if (addr == null) {
				addr = set.getMinAddress();
			}
			if (listener != null) {
				loc = listener.getProgramLocation(new MarkerLocation(this, addr, x, y));
			}
			if (loc == null) {
				loc = new ProgramLocation(mgr.getProgram(), addr);
			}
		}
		return loc;

	}
 
Example 11
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 12
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 13
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 14
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 15
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 16
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 17
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 18
private BigInteger max(BigInteger a, BigInteger b) {
    if(a==null) return b;
    if(b==null) return a;
    return a.max(b);
}
 
Example 19
Source Project: pitest   File: BigIntegerMutatorTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
BigInteger apply(BigInteger left, BigInteger right) {
  return left.max(right);
}
 
Example 20
public BigInteger getCardinality(Join join){

        BigInteger card1 = getCardinality(join.getLeftArg());

        BigInteger card2 = getCardinality(join.getRightArg());

        BigDecimal sel = BigDecimal.valueOf(selectivityEstimator.getJoinSelectivity(join));

        BigInteger tt = new BigDecimal(card1.multiply(card2)).multiply(sel).setScale(0, RoundingMode.CEILING).toBigInteger();

        return tt.max(BigInteger.ZERO);
    }