Example usage for java.math BigInteger doubleValue

List of usage examples for java.math BigInteger doubleValue

Introduction

In this page you can find the example usage for java.math BigInteger doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Converts this BigInteger to a double .

Usage

From source file:com.github.jessemull.microflexbiginteger.stat.NTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//* ww  w  .  j  a  v  a2s .c  o m*/
@Test
public void testAggregatedSetArray() {

    WellSet[] setArray = new WellSet[array.length];

    for (int i = 0; i < setArray.length; i++) {
        setArray[i] = array[i].dataSet();
    }

    Map<WellSet, Integer> aggregatedReturnedMap = n.setsAggregated(setArray);
    Map<WellSet, Integer> aggregatedResultMap = new TreeMap<WellSet, Integer>();

    for (WellSet set : setArray) {

        List<Double> resultList = new ArrayList<Double>();

        for (Well well : set) {

            for (BigInteger bi : well) {
                resultList.add(bi.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(set, (int) resultAggregated);
    }

    for (WellSet set : setArray) {

        int result = aggregatedResultMap.get(set);
        int returned = aggregatedReturnedMap.get(set);

        assertEquals(result, returned);
    }

}

From source file:geogebra.kernel.AlgoBinomial.java

private double BinomBig(double n, double r) {
    if (r > n / 2)
        r = n - r;//  w ww . j a  va 2 s . c o m
    BigInteger ncr = BigInteger.ONE, dd = BigInteger.ONE, nn, rr;
    //       nn=BigInteger.valueOf((long)n);
    //       rr=BigInteger.valueOf((long)r);

    // need a long-winded conversion in case n>10^18
    Double nnn = new Double(n);
    Double rrr = new Double(r);
    nn = (new BigDecimal(nnn.toString())).toBigInteger();
    rr = (new BigDecimal(rrr.toString())).toBigInteger();

    while (dd.compareTo(rr) <= 0) {
        ncr = ncr.multiply(nn);
        ncr = ncr.divide(dd); // dd is guaranteed to divide exactly into ncr here
        nn = nn.subtract(BigInteger.ONE);
        dd = dd.add(BigInteger.ONE);
    }
    return ncr.doubleValue();
}

From source file:com.github.jessemull.microflexbiginteger.stat.GeometricMeanTest.java

/**
 * Tests well calculation./*  w ww .  ja v  a 2  s  . c o m*/
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getGeometricMean();

            BigDecimal returned = mean.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MaxTest.java

/**
 * Tests well calculation./* www . jav  a  2 s  .  c  o  m*/
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMax();

            BigDecimal returned = max.well(well);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests well calculation.//from ww w  . j a  va2  s  . c om
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMin();

            BigDecimal returned = min.well(well);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.SumTest.java

/**
 * Tests well calculation.//from   w  w  w.j  a  va  2  s .c  o m
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getSum();

            BigDecimal returned = sum.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.GeometricMeanTest.java

/**
 * Tests well calculation using indices.
 *//*w  ww .j  a v  a 2  s.  co m*/
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 7);
            int end = begin + 3;

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getGeometricMean();

            BigDecimal returned = mean.well(well, begin, end - begin, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MaxTest.java

/**
 * Tests well calculation using indices.
 *//* www.jav  a 2  s .c  om*/
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 5);
            int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMax();

            BigDecimal returned = max.well(well, begin, end - begin);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests well calculation using indices.
 *//* w w w.j a v a2s .  c o m*/
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 5);
            int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal returned = min.well(well, begin, end - begin);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.StandardDeviationTest.java

/**
 * Tests well calculation./*from   www  .  ja  v  a2 s. co  m*/
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getStandardDeviation();

            BigDecimal returned = deviation.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}