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

The following examples show how to use java.math.BigInteger#doubleValue() . 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 File: JRPercentageCalculatorFactory.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 2
Source File: LUTE.java    From OSPREY3 with 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 3
Source File: SampleProofOfStake.java    From simblock with 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 4
Source File: SIQSPolyGenerator.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: PrimitiveConversionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PrimitiveConversionTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PrimitiveConversionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ExpressionIntegerValue.java    From zserio with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 9
Source File: PrimitiveConversionTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PrimitiveConversionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PrimitiveConversionTests.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
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 12
Source File: PrimitiveConversionTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PrimitiveConversionTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PrimitiveConversionTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: NumInt.java    From swim with 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 16
Source File: LinearTreasureModel.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 17
Source File: IntegerExtensions.java    From gravel with Apache License 2.0 4 votes vote down vote up
public static float floatDivFromLargeInteger_(int receiver,
		BigInteger argument) {
	return (float) (argument.doubleValue() / receiver);
}
 
Example 18
Source File: DoubleValueFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Double createFromBigInteger(BigInteger i) {
    return i.doubleValue();
}
 
Example 19
Source File: BigIntegerCastExtensions.java    From sarl with 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());
}
 
Example 20
Source File: FloatValueFactory.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Float createFromBigInteger(BigInteger i) {
    return (float) i.doubleValue();
}