Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

In this page you can find the example usage for java.lang Double isInfinite.

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:org.eclipse.dataset.IntegerDataset.java

@Override
public IntegerDataset ipower(final Object b) {
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    final double v = Math.pow(data[it.index], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }/*ww  w. jav a  2s .  c om*/
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    Complex zd = new Complex(data[it.index], 0);
                    final double v = zd.pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(data[it.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.index] = 0; // INT_USE
                } else { // INT_USE
                    data[it.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                final double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    }
    setDirty();
    return this;
}

From source file:org.eclipse.dataset.AbstractCompoundDataset.java

@Override
protected void calculateSummaryStats(final boolean ignoreNaNs, final boolean ignoreInfs, final int axis) {
    int rank = getRank();

    int[] oshape = getShape();
    int alen = oshape[axis];
    oshape[axis] = 1;//w  w w.  j av  a  2 s .co m

    int[] nshape = squeezeShape(oshape, false);

    IntegerDataset count = new IntegerDataset(nshape);
    CompoundDoubleDataset sum = new CompoundDoubleDataset(isize, nshape);
    CompoundDoubleDataset mean = new CompoundDoubleDataset(isize, nshape);
    CompoundDoubleDataset var = new CompoundDoubleDataset(isize, nshape);

    IndexIterator qiter = count.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos = oshape;
    double[] darray = new double[isize];

    while (qiter.hasNext()) {
        int i = 0;
        for (; i < axis; i++) {
            spos[i] = qpos[i];
        }
        spos[i++] = 0;
        for (; i < rank; i++) {
            spos[i] = qpos[i - 1];
        }

        final SummaryStatistics[] stats = new SummaryStatistics[isize];
        for (int k = 0; k < isize; k++) {
            stats[k] = new SummaryStatistics();
        }
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            getDoubleArray(darray, spos);
            boolean skip = false;
            for (int k = 0; k < isize; k++) {
                double v = darray[k];
                if (ignoreNaNs && Double.isNaN(v)) {
                    skip = true;
                    break;
                }
                if (ignoreInfs && Double.isInfinite(v)) {
                    skip = true;
                    break;
                }
            }
            if (!skip)
                for (int k = 0; k < isize; k++) {
                    stats[k].addValue(darray[k]);
                }
        }

        count.setAbs(qiter.index, (int) stats[0].getN());

        for (int k = 0; k < isize; k++) {
            darray[k] = stats[k].getSum();
        }
        sum.set(darray, qpos);
        for (int k = 0; k < isize; k++) {
            darray[k] = stats[k].getMean();
        }
        mean.set(darray, qpos);
        for (int k = 0; k < isize; k++) {
            darray[k] = stats[k].getVariance();
        }
        var.set(darray, qpos);
    }
    setStoredValue(storeName(ignoreNaNs, ignoreInfs, STORE_COUNT + "-" + axis), count);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_SUM + "-" + axis), sum);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MEAN + "-" + axis), mean);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_VAR + "-" + axis), var);
}

From source file:org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcUnitTest.java

@Test(enabled = true, dataProvider = "Models")
public void testNoPrior(final AFCalc model) {
    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        final double[] flatPriors = new double[] { 0.0, 0.0, 0.0 };
        final double[] noPriors = new double[3];
        // test that function computeAlleleFrequency correctly operates when the flat prior option is set
        // computeAlleleFrequencyPriors takes linear priors
        final ArrayList<Double> inputPrior = new ArrayList<Double>();
        inputPrior.add(1.0 / 3);//from w ww . j a  v a2s  .  co  m
        inputPrior.add(1.0 / 3);
        UnifiedGenotypingEngine.computeAlleleFrequencyPriors(2, noPriors, 0.0, inputPrior);

        GetGLsTest cfgFlatPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "flatPrior");
        GetGLsTest cfgNoPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "noPrior");
        final AFCalcResult resultTrackerFlat = cfgFlatPrior.execute();
        final AFCalcResult resultTrackerNoPrior = cfgNoPrior.execute();

        final double pRefWithNoPrior = AB.getLikelihoods().getAsVector()[0];
        final double pHetWithNoPrior = AB.getLikelihoods().getAsVector()[1] - Math.log10(0.5);
        final double nonRefPost = Math.pow(10, pHetWithNoPrior)
                / (Math.pow(10, pRefWithNoPrior) + Math.pow(10, pHetWithNoPrior));
        final double log10NonRefPost = Math.log10(nonRefPost);

        if (!Double.isInfinite(log10NonRefPost)) {
            // check that the no-prior and flat-prior constructions yield same result
            Assert.assertEquals(resultTrackerFlat.getLog10PosteriorOfAFGT0(),
                    resultTrackerNoPrior.getLog10PosteriorOfAFGT0());
        }

    }
}

From source file:org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalcUnitTest.java

@Test(enabled = true, dataProvider = "Models")
public void testNoPrior(final AFCalc model) {
    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        final double[] flatPriors = new double[] { 0.0, 0.0, 0.0 };
        final double[] noPriors = new double[3];
        // test that function computeAlleleFrequency correctly operates when the flat prior option is set
        // computeAlleleFrequencyPriors takes linear priors
        final ArrayList<Double> inputPrior = new ArrayList<Double>();
        inputPrior.add(1.0 / 3);/*from   w w  w. jav a 2  s.c  o m*/
        inputPrior.add(1.0 / 3);
        UnifiedGenotyperEngine.computeAlleleFrequencyPriors(2, noPriors, 0.0, inputPrior);

        GetGLsTest cfgFlatPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "flatPrior");
        GetGLsTest cfgNoPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "noPrior");
        final AFCalcResult resultTrackerFlat = cfgFlatPrior.execute();
        final AFCalcResult resultTrackerNoPrior = cfgNoPrior.execute();

        final double pRefWithNoPrior = AB.getLikelihoods().getAsVector()[0];
        final double pHetWithNoPrior = AB.getLikelihoods().getAsVector()[1] - Math.log10(0.5);
        final double nonRefPost = Math.pow(10, pHetWithNoPrior)
                / (Math.pow(10, pRefWithNoPrior) + Math.pow(10, pHetWithNoPrior));
        final double log10NonRefPost = Math.log10(nonRefPost);

        if (!Double.isInfinite(log10NonRefPost)) {
            // check that the no-prior and flat-prior constructions yield same result
            Assert.assertEquals(resultTrackerFlat.getLog10PosteriorOfAFGT0(),
                    resultTrackerNoPrior.getLog10PosteriorOfAFGT0());
        }

    }
}

From source file:org.eclipse.january.dataset.LongDataset.java

@Override
public LongDataset ipower(final Object b) {
    setDirty();//from   www . j av a  2 s  .c o m
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    final double v = Math.pow(data[it.index], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    Complex zd = new Complex(data[it.index], 0);
                    final double v = zd.pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(data[it.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.index] = 0; // INT_USE
                } else { // INT_USE
                    data[it.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                final double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    }
    return this;
}

From source file:org.eclipse.january.dataset.ByteDataset.java

@Override
public ByteDataset ipower(final Object b) {
    setDirty();//from   w  w  w . j  av  a2 s  .c  om
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    final double v = Math.pow(data[it.index], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    Complex zd = new Complex(data[it.index], 0);
                    final double v = zd.pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(data[it.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.index] = 0; // INT_USE
                } else { // INT_USE
                    data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                final double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    }
    return this;
}

From source file:net.pms.util.Rational.java

/**
 * Returns a {@link Rational} whose value is {@code (this / value)}.
 *
 * @param value the value by which this {@link Rational} is to be divided.
 * @return The division result.//from   w ww.j  a v  a 2s.c  o m
 */
@Nonnull
public Rational divide(double value) {
    if (isNaN() || Double.isNaN(value) || isInfinite() && Double.isInfinite(value)) {
        return NaN;
    }

    if (value == 0d) {
        if (signum() == 0) {
            return NaN;
        }
        return signum() > 0 ? POSITIVE_INFINITY : NEGATIVE_INFINITY;
    }

    if (Double.isInfinite(value)) {
        return ZERO;
    }
    if (signum() == 0 || isInfinite() || 1d == Math.abs(value)) {
        return value < 0d ? negate() : this;
    }

    return divide(valueOf(value));
}

From source file:org.eclipse.january.dataset.ShortDataset.java

@Override
public ShortDataset ipower(final Object b) {
    setDirty();/*w w  w .j av  a 2  s .  c o  m*/
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    final double v = Math.pow(data[it.index], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    Complex zd = new Complex(data[it.index], 0);
                    final double v = zd.pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(data[it.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.index] = 0; // INT_USE
                } else { // INT_USE
                    data[it.index] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                final double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    }
    return this;
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

public void sameTest(double[] data) {
    // test//ww w .  j a  v  a2 s  .c  om
    if (cmpDB == null || cmpDB.length != data.length) {
        Log.i(TAG, "sameTest(): new");
        cmpDB = new double[data.length];
    } else {
        boolean same = true;
        for (int i = 0; i < data.length; i++) {
            if (!Double.isNaN(cmpDB[i]) && !Double.isInfinite(cmpDB[i]) && cmpDB[i] != data[i]) {
                same = false;
                break;
            }
        }
        if (same) {
            Log.i(TAG, "sameTest(): same data row!!");
        }
        for (int i = 0; i < data.length; i++) {
            cmpDB[i] = data[i];
        }
    }
}

From source file:org.eclipse.january.dataset.IntegerDataset.java

@Override
public IntegerDataset ipower(final Object b) {
    setDirty();//from   w w w .j  a va2 s  .  c  om
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    final double v = Math.pow(data[it.index], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    Complex zd = new Complex(data[it.index], 0);
                    final double v = zd.pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(data[it.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.index] = 0; // INT_USE
                } else { // INT_USE
                    data[it.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                final double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        } else {// NAN_OMIT
            while (it.hasNext()) {
                final double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
            }
        }
    }
    return this;
}