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

/**
 * Indicates whether the given double valid, implying it is not null, not
 * infinite and not NaN./*from   w  ww .  j  a  v a 2  s. co  m*/
 *
 * @param d the double.
 * @return true if the given double is valid.
 */
public static boolean isValidDouble(Double d) {
    return d != null && !Double.isInfinite(d) && !Double.isNaN(d);
}

From source file:Main.java

public static double round(double d) {
    if (Double.isNaN(d) || Double.isInfinite(d))
        return d;
    int digits = leadingDigits(d);
    int roundToDecimal = Math.min(MAXDIGIT - digits, MAXDECIMAL);
    double rounded = BigDecimal.valueOf(d).setScale(roundToDecimal, BigDecimal.ROUND_HALF_UP).doubleValue();
    return rounded;
}

From source file:Main.java

/**
 * Converts the given primative <code>double</code> array to a primitive <code>float</code> array
 * //from  www . j  a v a2  s .c o  m
 * @param in
 *            a primative <code>double</code> array
 * 
 * @return a <code>float</code> array equivalent to the specified <code>double</code> array
 */
public static float[] doubleArrayToFloatArray(double[] in) {
    float[] out = new float[in.length];
    for (int i = 0; i < in.length; i++) {
        if (Double.isNaN(in[i])) {
            out[i] = Float.NaN;
        } else {
            out[i] = (float) in[i];
        }
    }
    return out;
}

From source file:Main.java

public static List<String> calculateResolutions(double dpi, double screenSize, boolean standard) {
    List<String> ret = new ArrayList<>();
    double bothSquaredSum = Math.pow(dpi * screenSize, 2);
    for (int i = 0; i < 10000; i++) {
        double other = Math.sqrt(bothSquaredSum - Math.pow(i, 2));
        double higher = Math.max(i, other), lower = Math.min(i, other);
        if (Double.isNaN(lower)) {
            continue;
        }/*from  w  w w  .  ja v  a 2 s. co  m*/
        if (standard) {
            double ratio = higher / lower;
            if (ratio == 4.0 / 3.0 || ratio == 16.0 / 9.0 || ratio == 16.0 / 10.0) {
                ret.add(String.format("%.0fx%.0f", higher, lower));
            }
        } else {
            ret.add(String.format("%.0fx%.0f", higher, lower));
        }
    }
    return ret;
}

From source file:Main.java

public static boolean isNaN(Object number) {
    if (number == null) {
        return false;
    }/*from w ww  .  j a v  a 2 s . com*/
    try {
        return Double.isNaN((Double) number);
    } catch (Exception e) {
        return false;
    }
}

From source file:com.mycompany.semconsolewebapp.FFT.java

public static double[] forward(double[] data) {
    FastFourierTransformer f = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] fftC = f.transform(data, TransformType.FORWARD);

    for (int i = 0; i < data.length; i++) {

        data[i] = fftC[i].abs();//from  w w w . j av a 2  s .co  m

        if (Double.isNaN(data[i])) {
            System.out.println("C " + fftC[i].getReal() + " + i" + fftC[i].getImaginary());
            System.out.println("D " + data[i]);
            break;
        }
    }

    return data;
}

From source file:Util.java

public static String parseDollars(double amount) {
    if (Double.isNaN(amount) || Double.isInfinite(amount))
        return (new Double(amount)).toString();
    return parseDollars((int) Math.round(amount));
}

From source file:dk.nodes.webservice.parser.NJSON.java

/**
 * Returns the input if it is a JSON-permissible value; throws otherwise.
 *///from w w w  . j  a  v a 2s. c  om
static double checkDouble(double d) throws JSONException {
    if (Double.isInfinite(d) || Double.isNaN(d)) {
        throw new JSONException("Forbidden numeric value: " + d);
    }
    return d;
}

From source file:Main.java

public static boolean isLikelyDouble(long value) {
    // Check for some common named double values
    // We don't check for Double.MIN_VALUE, which has a long representation of 1
    if (value == canonicalDoubleNaN || value == maxDouble || value == piDouble || value == eDouble) {
        return true;
    }/*from www.  j a v  a  2  s.co  m*/

    // Check for some named long values
    if (value == Long.MAX_VALUE || value == Long.MIN_VALUE) {
        return false;
    }

    // a non-canocical NaN is more likely to be an long
    double doubleValue = Double.longBitsToDouble(value);
    if (Double.isNaN(doubleValue)) {
        return false;
    }

    // Otherwise, whichever has a shorter scientific notation representation is more likely.
    // Long wins the tie
    String asLong = format.format(value);
    String asDouble = format.format(doubleValue);

    // try to strip off any small imprecision near the end of the mantissa
    int decimalPoint = asDouble.indexOf('.');
    int exponent = asDouble.indexOf("E");
    int zeros = asDouble.indexOf("000");
    if (zeros > decimalPoint && zeros < exponent) {
        asDouble = asDouble.substring(0, zeros) + asDouble.substring(exponent);
    } else {
        int nines = asDouble.indexOf("999");
        if (nines > decimalPoint && nines < exponent) {
            asDouble = asDouble.substring(0, nines) + asDouble.substring(exponent);
        }
    }

    return asDouble.length() < asLong.length();
}

From source file:Main.java

/**
 * For a double precision value x, this method returns +1.0 if x >= 0 and
 * -1.0 if x < 0. Returns <code>NaN</code> if <code>x</code> is
 * <code>NaN</code>.//  www.j  a v a 2  s.  com
 * 
 * @param x the value, a double
 * @return +1.0 or -1.0, depending on the sign of x
 */
public static double indicator(final double x) {
    if (Double.isNaN(x)) {
        return Double.NaN;
    }
    return (x >= 0.0) ? 1.0 : -1.0;
}