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 static boolean isNaN(double v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:Main.java

/**
 * <p>Returns the maximum value in an array.</p>
 * /* w  w w. java 2  s  . c  o  m*/
 * @param array  an array, must not be null or empty
 * @return the minimum value in the array
 * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>array</code> is empty
 * @see IEEE754rUtils#max(double[]) IEEE754rUtils for a version of this method that handles NaN differently
 */
public static double max(double[] array) {
    // Validates input
    if (array == null) {
        throw new IllegalArgumentException("The Array must not be null");
    } else if (array.length == 0) {
        throw new IllegalArgumentException("Array cannot be empty.");
    }

    // Finds and returns max
    double max = array[0];
    for (int j = 1; j < array.length; j++) {
        if (Double.isNaN(array[j])) {
            return Double.NaN;
        }
        if (array[j] > max) {
            max = array[j];
        }
    }

    return max;
}

From source file:jurls.core.becca.Daisychain.java

public double[] in(double[] cable) {
    this.cable = cable;

    double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;

    if ((tp == null) || (tp.getRowDimension() != cable.length)) {
        tp = new Array2DRowRealMatrix(cable.length, cable.length);
        // TODO transfer old probability to the new instance
    }//w w w. java  2 s  .co m

    if (cablePre != null) {
        for (int i = 0; i < cablePre.length; i++) {
            for (int j = 0; j < cable.length; j++) {
                double c = cablePre[i] * cable[j];

                double prevProb = tp.getEntry(i, j);
                if (Double.isNaN(prevProb))
                    prevProb = 0;

                double newProb = c * (updateRate) + prevProb * (1.0 - updateRate);

                if (newProb < min)
                    min = newProb;
                if (newProb > max)
                    max = newProb;

                tp.setEntry(i, j, newProb);
            }
        }
    }

    if ((cablePre == null) || (cablePre.length != cable.length))
        cablePre = new double[cable.length];

    System.arraycopy(cable, 0, cablePre, 0, cable.length);

    return ravel(tp, chainVector, 0, max);
}

From source file:com.insightml.math.distributions.AbstractGaussian.java

public static final String toStringInterval(final IContDistribution gaussian, final double min,
        final double max, final int timesStddev, final int precision) {
    final SimpleFormatter format = new SimpleFormatter(precision, false);
    final double stddev = gaussian.standardDeviation();
    if (stddev < 0.01 || Double.isNaN(stddev)) {
        return format.format(gaussian.expectedValue());
    }//w  ww.  j  a v  a  2s.co m
    final Interval conf = gaussian.confidenceInterval(timesStddev);
    return format.format(Math.max(min, conf.getStart())) + " \u2013 "
            + format.format(Math.min(max, conf.getEnd()));
}

From source file:ch.algotrader.util.RoundUtil.java

public static BigDecimal getBigDecimal(double value, int scale) {

    if (Double.isNaN(value) || Double.isInfinite(value)) {
        return null;
    } else {//w  ww . ja v  a  2s.  com
        BigDecimal decimal = new BigDecimal(value);
        return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP);
    }
}

From source file:com.rapidminer.tools.expression.internal.function.trigonometric.ArcHyperbolicSine.java

@Override
protected double compute(double value) {
    return Double.isNaN(value) ? Double.NaN : FastMath.asinh(value);
}

From source file:com.rapidminer.tools.expression.internal.function.trigonometric.ArcHyperbolicCosine.java

@Override
protected double compute(double value) {
    return Double.isNaN(value) ? Double.NaN : FastMath.acosh(value);
}

From source file:com.rapidminer.tools.expression.internal.function.trigonometric.ArcHyperbolicTangent.java

@Override
protected double compute(double value) {
    return Double.isNaN(value) ? Double.NaN : FastMath.atanh(value);
}

From source file:beast.math.distributions.PoissonDistribution.java

public double logPdf(double x) {

    double pdf = distribution.probability((int) x);
    if (pdf == 0 || Double.isNaN(pdf)) { // bad estimate
        final double mean = mean();
        return x * Math.log(mean) - Poisson.gammln(x + 1) - mean;
    }//from  w ww  . jav a2s  .c om
    return Math.log(pdf);

}

From source file:com.lth.thesis.blepublictransport.Utils.KalmanFilter.java

/**
 * Filter a new value//from   w ww  .  j a  v  a2s.c o m
 *
 * @param z Measurement
 * @param u Control
 * @return x
 */
public double filter(double z, double u) {

    if (Double.isNaN(x)) {
        x = (1 / C) * z;
        x1 = x;
        x2 = x1;
        cov = (1 / C) * Q * (1 / C);
    } else {

        // Calculate previous update step
        B = (x - x1) / 2;

        // Compute prediction
        double predX = (A * x) + (B * u);
        double predCov = ((A * cov) * A) + R;

        // Kalman gain
        double K = predCov * C * (1 / ((C * predCov * C) + Q));

        // Correction
        x1 = x;
        x = predX + K * (z - (C * predX));
        cov = predCov - (K * C * predCov);
    }

    return x;
}

From source file:com.proofpoint.units.DataSize.java

public DataSize(double size, Unit unit) {
    Preconditions.checkArgument(!Double.isInfinite(size), "size is infinite");
    Preconditions.checkArgument(!Double.isNaN(size), "size is not a number");
    Preconditions.checkArgument(size >= 0, "size is negative");
    Preconditions.checkNotNull(unit, "unit is null");

    this.value = size;
    this.unit = unit;
}