Example usage for java.lang Double isNaN

List of usage examples for java.lang Double isNaN

Introduction

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

Prototype

public boolean isNaN() 

Source Link

Document

Returns true if this Double value is a Not-a-Number (NaN), false otherwise.

Usage

From source file:Main.java

public static void main(String[] args) {
    Double double1 = new Double(0.0 / 0.0);

    System.out.println(double1.isNaN());

}

From source file:Main.java

public static void main(String args[]) {
    Double d1 = new Double(1 / 0.);
    Double d2 = new Double(0 / 0.);

    System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
    System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
}

From source file:MainClass.java

public static void main(String args[]) {
    Double d1 = new Double(1 / 0.);
    Double d2 = new Double(0 / 0.);
    System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
    System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
}

From source file:Main.java

public static double tanh(double t) {
    Double aux = new Double(sinh(t) / cosh(t));
    if (aux.isNaN()) {
        if (t > 0.0)
            return 1.0;
        else//  www .  j  a v  a2  s .c o m
            return -1.0;
    }
    return aux.doubleValue();
}

From source file:de.cosmocode.collections.utility.Convert.java

private static Double doIntoDouble(Object value) {
    if (value == null)
        return null;
    if (value instanceof Double)
        return Double.class.cast(value);
    if (value instanceof Number)
        return Number.class.cast(value).doubleValue();
    final String s = doIntoString(value);
    try {//ww w  . j ava  2s. c o m
        final Double d = Double.valueOf(s);
        LOG.debug("Converted {} into {}", value, d);
        if (d.isInfinite() || d.isNaN())
            return null;
        return d;
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:ml.shifu.shifu.core.Normalizer.java

/**
 * Check specified standard deviation cutoff and return the correct value.
 * /*from w w w .java  2s.c  o m*/
 * @param cutoff
 *            specified standard deviation cutoff
 * @return If cutoff is valid then return it, else return {@link Normalizer#STD_DEV_CUTOFF}
 */
public static double checkCutOff(Double cutoff) {
    double stdDevCutOff;
    if (cutoff != null && !cutoff.isInfinite() && !cutoff.isNaN()) {
        stdDevCutOff = cutoff;
    } else {
        stdDevCutOff = STD_DEV_CUTOFF;
    }

    return stdDevCutOff;
}

From source file:au.org.ala.layers.intersect.IntersectConfig.java

static private List<Double> getDoublesFrom(String property) {
    List<Double> l = new ArrayList<Double>();
    if (property != null) {
        for (String s : property.split(",")) {
            try {
                Double d = Double.parseDouble(s.trim());
                if (d != null && !d.isNaN()) {
                    l.add(d);// w  w w.ja va2s. c  om
                } else {
                    logger.warn("Cannot parse '" + s + "' to Double");
                }
            } catch (Exception e) {
                logger.warn("Cannot parse '" + s + "' to Double", e);
            }
        }
    }
    java.util.Collections.sort(l);
    return l;
}

From source file:com.splicemachine.orc.OrcTester.java

private static void assertColumnValueEquals(DataType type, Object actual, Object expected) {
    if (actual == null) {
        assertNull(expected);/*ww w  .jav  a  2s  . c om*/
        return;
    }
    if (type instanceof ArrayType) {
        List<?> actualArray = (List<?>) actual;
        List<?> expectedArray = (List<?>) expected;
        assertEquals(actualArray.size(), expectedArray.size());
        DataType elementType = ((ArrayType) type).elementType();
        for (int i = 0; i < actualArray.size(); i++) {
            Object actualElement = actualArray.get(i);
            Object expectedElement = expectedArray.get(i);
            assertColumnValueEquals(elementType, actualElement, expectedElement);
        }
    } else if (type instanceof MapType) {
        Map<?, ?> actualMap = (Map<?, ?>) actual;
        Map<?, ?> expectedMap = (Map<?, ?>) expected;
        assertEquals(actualMap.size(), expectedMap.size());

        DataType keyType = ((MapType) type).keyType();
        DataType valueType = ((MapType) type).valueType();

        List<Entry<?, ?>> expectedEntries = new ArrayList<>(expectedMap.entrySet());
        for (Entry<?, ?> actualEntry : actualMap.entrySet()) {
            Iterator<Entry<?, ?>> iterator = expectedEntries.iterator();
            while (iterator.hasNext()) {
                Entry<?, ?> expectedEntry = iterator.next();
                try {
                    assertColumnValueEquals(keyType, actualEntry.getKey(), expectedEntry.getKey());
                    assertColumnValueEquals(valueType, actualEntry.getValue(), expectedEntry.getValue());
                    iterator.remove();
                } catch (AssertionError ignored) {
                }
            }
        }
        assertTrue("Unmatched entries " + expectedEntries, expectedEntries.isEmpty());
    } else if (type instanceof StructType) {

        StructField[] fieldTypes = ((StructType) type).fields();

        List<?> actualRow = (List<?>) actual;
        List<?> expectedRow = (List<?>) expected;
        assertEquals(actualRow.size(), fieldTypes.length);
        assertEquals(actualRow.size(), expectedRow.size());

        for (int fieldId = 0; fieldId < actualRow.size(); fieldId++) {
            DataType fieldType = fieldTypes[fieldId].dataType();
            Object actualElement = actualRow.get(fieldId);
            Object expectedElement = expectedRow.get(fieldId);
            assertColumnValueEquals(fieldType, actualElement, expectedElement);
        }
    } else if (type instanceof DoubleType) {
        Double actualDouble = (Double) actual;
        Double expectedDouble = (Double) expected;
        if (actualDouble.isNaN()) {
            assertTrue("expected double to be NaN", expectedDouble.isNaN());
        } else {
            assertEquals(actualDouble, expectedDouble, 0.001);
        }
    } else if (!Objects.equals(actual, expected)) {
        assertEquals(expected, actual);
    }
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "signum", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "Returns -1 if the argument is negative, +1 if it is positive, 0 if it is equal to zero or not a number", examples = {
        @example(value = "signum(-12)", equals = "-1"), @example(value = "signum(14)", equals = "1"),
        @example(value = "signum(0)", equals = "0") })
public static Integer signum(final Double d) {
    if (d == null || d.isNaN() || Comparison.equal(d, 0d)) {
        return 0;
    }//  w w  w  .  j a  v  a2  s  .c o m
    if (d < 0) {
        return -1;
    }
    return 1;
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

private static Map<MarkerKey, MarkerManhattenData> assembleManhattenPlotData(OperationKey testOpKey)
        throws IOException {

    Map<MarkerKey, MarkerManhattenData> markerKeyChrPosPVal;

    CommonTestOperationDataSet<? extends TrendTestOperationEntry> testOpDS = (CommonTestOperationDataSet<? extends TrendTestOperationEntry>) OperationManager
            .generateOperationDataSet(testOpKey);
    final Iterator<MarkerKey> testOpMarkerKeys = testOpDS.getMarkersKeysSource().iterator();
    final Iterator<Double> testOpPValues = testOpDS.getPs(-1, -1).iterator();

    final DataSetSource matrixDS = MatrixFactory.generateMatrixDataSetSource(testOpKey.getParentMatrixKey());
    final MarkersMetadataSource matrixMarkersMS = matrixDS.getMarkersMetadatasSource();
    final Iterator<String> matrixMarkersChromosomes = matrixMarkersMS.getChromosomes().iterator();
    final Iterator<Integer> matrixMarkersPositions = matrixMarkersMS.getPositions().iterator();
    markerKeyChrPosPVal = new LinkedHashMap<MarkerKey, MarkerManhattenData>(matrixMarkersMS.size());
    MarkerKey nextTestMarkerKey = testOpMarkerKeys.hasNext() ? testOpMarkerKeys.next() : null;
    for (final MarkerKey markerKey : matrixDS.getMarkersKeysSource()) {
        final String chromosome = matrixMarkersChromosomes.next();
        final int position = matrixMarkersPositions.next();
        Double pValue;
        if (markerKey.equals(nextTestMarkerKey)) {
            pValue = testOpPValues.next();
            if (pValue.isNaN() || pValue.isInfinite()) { // Ignore invalid P-Values
                pValue = null;/*from  w w  w. ja v  a 2 s .c  om*/
            }
            nextTestMarkerKey = testOpMarkerKeys.hasNext() ? testOpMarkerKeys.next() : null;
        } else {
            // The current markerKey has no entry in the test operation,
            // thus we have no P-Value for it, so we mark it as totally insignificant.
            pValue = 1.0;
        }
        MarkerManhattenData data = new MarkerManhattenData(chromosome, position, pValue);
        markerKeyChrPosPVal.put(markerKey, data);
    }

    //      long snpNumber = rdInfoMarkerSet.getMarkerSetSize();
    //      if (snpNumber < 250000) {
    //         hetzyThreshold = 0.5 / snpNumber;  // (0.05 / 10^6 SNPs => 5*10^(-7))
    //      }

    return markerKeyChrPosPVal;
}