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

The following examples show how to use java.math.BigInteger#doubleValue() . 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: OSPREY3   File: LUTE.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void reportConfSpaceSize(PruningMatrix pmat) {

		BigInteger sizeLower = pmat.calcUnprunedConfsLowerBound();
		BigInteger sizeUpper = pmat.calcUnprunedConfsUpperBound();

		// the bounds are loose, but remember we sampled some confs
		// so improve the lower bound with the samples if possible
		try {
			sizeLower = BigInteger.valueOf(Math.max(sizeLower.longValueExact(), energies.size()));

		} catch (ArithmeticException ex) {
			// lower bound is bigger than we could have possibly sampled
			// so don't change anything
		}

		double percentLower = 100.0*energies.size()/sizeUpper.doubleValue();
		double percentUpper = 100.0*energies.size()/sizeLower.doubleValue();

		log("conf space (after singles and pairs pruning) has somewhere between %s and %s conformations", formatBig(sizeLower), formatBig(sizeUpper));
		log("LUTE sampled somewhere between %.1f%% and %.1f%% of those conformations", percentLower, percentUpper);
	}
 
Example 2
@Override
public Object calculatePercentage(JRCalculable value, JRCalculable total)
{
	BigInteger totalVal = (BigInteger) total.getValue();
	BigInteger val = (BigInteger) value.getValue();
	BigInteger percentage;
	if (totalVal != null && totalVal.doubleValue() != 0)
	{
		percentage = val.multiply(BigInteger.valueOf(100L)).divide(totalVal);
	}
	else
	{
		percentage = BigInteger.valueOf(0);
	}

	return percentage;
}
 
Example 3
Source Project: swim   File: NumInt.java    License: Apache License 2.0 5 votes vote down vote up
public static NumInt from(BigInteger value) {
  final double doubleValue = value.doubleValue();
  if (doubleValue == 0.0) {
    return zero();
  } else if (doubleValue == 1.0) {
    return positiveOne();
  } else if (doubleValue == -1.0) {
    return negativeOne();
  } else {
    return cache().put(new NumInt(value));
  }
}
 
Example 4
Source Project: simblock   File: SampleProofOfStake.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SampleStakingTask minting() {
  Node selfNode = this.getSelfNode();
  SamplePoSBlock parent = (SamplePoSBlock) selfNode.getBlock();
  BigInteger difficulty = parent.getNextDifficulty();
  double p = parent.getCoinage(selfNode).getCoinage().doubleValue() / difficulty.doubleValue();
  double u = random.nextDouble();
  return p <= Math.pow(2, -53) ? null : new SampleStakingTask(selfNode,
                                                              (long) (Math.log(u) / Math.log(
                                                                  1.0 - p) * 1000), difficulty
  );
}
 
Example 5
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 6
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 7
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 8
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 9
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 10
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 11
private BigInteger getNumBits(BigInteger value)
{
    if (value.doubleValue() < 2.0)
        return BigInteger.ONE;

    final BigInteger calcValue = value.subtract(BigInteger.ONE);
    return BigInteger.valueOf(calcValue.bitLength());
}
 
Example 12
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 13
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 14
public static int testDoubleValue() {
    int failures = 0;
    for (BigInteger big : ALL_BIGINTEGER_CANDIDATES) {
        double expected = Double.parseDouble(big.toString());
        double actual = big.doubleValue();

        // should be bitwise identical
        if (Double.doubleToRawLongBits(expected) != Double
                .doubleToRawLongBits(actual)) {
            System.out.println(big);
            failures++;
        }
    }
    return failures;
}
 
Example 15
@Override
public void initializeForN(
		int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays,
		AParamGenerator aParamGenerator, Sieve sieveEngine, TDiv_QS tDivEngine) {
	
	this.k = k;
	this.kN = kN;
	this.d = d;
	
	this.baseArrays = baseArrays;
	this.mergedBaseSize = baseArrays.primes.length;
	
	// initialize sub-engines
	this.aParamGenerator = aParamGenerator;
	sieveEngine.initializeForN(sieveParams, mergedBaseSize);
	this.sieveEngine = sieveEngine;
	final double N_dbl = N.doubleValue();
	tDivEngine.initializeForN(N_dbl, kN, sieveParams.maxQRest);
	this.tDivEngine = tDivEngine;

	// B2: the array needs one more element because used indices start at 1.
	// the B2 entries are non-negative, so we can use UnsignedBigInt.mod(int), which is much faster than BigInteger.mod(BigInteger).
	qCount = aParamGenerator.getQCount();
	B2Array = new BigInteger[qCount];
	B2Array_UBI = new UnsignedBigInt[qCount];
	// set bIndex=maxBIndex=0 to indicate that the first polynomial is wanted
	bIndex = maxBIndex = 0;
	
	// Allocate filtered base and solution arrays: The true size may be smaller if powers are filtered out, too.
	solutionArrays = new SolutionArrays(mergedBaseSize - qCount, qCount);
	
	// statistics
	if (ANALYZE) {
		aParamCount = bParamCount = 0;
		aDuration = firstBDuration = filterPBDuration = firstXArrayDuration = nextBDuration = nextXArrayDuration = 0;
	}
}
 
Example 16
@Override
public Float createFromBigInteger(BigInteger i) {
    return (float) i.doubleValue();
}
 
Example 17
@Override
public Double evaluate(final ILabeledPath<ITransparentTreeNode, Integer> path) throws PathEvaluationException, InterruptedException {
	BigInteger numLeafsBefore = path.getHead().getNumberOfLeafsPriorToNodeViaDFS();
	return this.asc ? numLeafsBefore.doubleValue() : path.getRoot().getNumberOfLeafsUnderNode().subtract(numLeafsBefore).doubleValue();
}
 
Example 18
Source Project: gravel   File: IntegerExtensions.java    License: Apache License 2.0 4 votes vote down vote up
public static float floatDivFromLargeInteger_(int receiver,
		BigInteger argument) {
	return (float) (argument.doubleValue() / receiver);
}
 
Example 19
@Override
public Double createFromBigInteger(BigInteger i) {
    return i.doubleValue();
}
 
Example 20
Source Project: sarl   File: BigIntegerCastExtensions.java    License: Apache License 2.0 4 votes vote down vote up
/** Convert the given value to {@code AtomicDouble}. This function is not null-safe.
 *
 * @param number a number of {@code BigInteger} type.
 * @return the equivalent value to {@code number} of {@code AtomicDouble} type.
 */
@Pure
@Inline(value = "new $2($1.doubleValue())", imported = AtomicDouble.class)
public static AtomicDouble toAtomicDouble(BigInteger number) {
	return new AtomicDouble(number.doubleValue());
}