List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:Main.java
/** * Get the next machine representable number after a number, moving * in the direction of another number.//w w w . j a v a 2 s.c om * <p> * If <code>direction</code> is greater than or equal to<code>d</code>, * the smallest machine representable number strictly greater than * <code>d</code> is returned; otherwise the largest representable number * strictly less than <code>d</code> is returned.</p> * <p> * If <code>d</code> is NaN or Infinite, it is returned unchanged.</p> * * @param d base number * @param direction (the only important thing is whether * direction is greater or smaller than d) * @return the next machine representable number in the specified direction * @since 1.2 */ public static double nextAfter(double d, double direction) { // handling of some important special cases if (Double.isNaN(d) || Double.isInfinite(d)) { return d; } else if (d == 0) { return (direction < 0) ? -Double.MIN_VALUE : Double.MIN_VALUE; } // special cases MAX_VALUE to infinity and MIN_VALUE to 0 // are handled just as normal numbers // split the double in raw components long bits = Double.doubleToLongBits(d); long sign = bits & 0x8000000000000000L; long exponent = bits & 0x7ff0000000000000L; long mantissa = bits & 0x000fffffffffffffL; if (d * (direction - d) >= 0) { // we should increase the mantissa if (mantissa == 0x000fffffffffffffL) { return Double.longBitsToDouble(sign | (exponent + 0x0010000000000000L)); } else { return Double.longBitsToDouble(sign | exponent | (mantissa + 1)); } } else { // we should decrease the mantissa if (mantissa == 0L) { return Double.longBitsToDouble(sign | (exponent - 0x0010000000000000L) | 0x000fffffffffffffL); } else { return Double.longBitsToDouble(sign | exponent | (mantissa - 1)); } } }
From source file:com.algoTrader.util.RoundUtil.java
public static BigDecimal getBigDecimal(double value, int scale) { if (!Double.isNaN(value)) { BigDecimal decimal = new BigDecimal(value); return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP); } else {// ww w . j a va2s.c o m return null; } }
From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java
public static double[] calculateSummaryStatistics(Number[] x) { logger.fine("entering calculate summary statistics (" + x.length + " Number values);"); double[] nx = new double[8]; //("mean", "medn", "mode", "vald", "invd", "min", "max", "stdev"); Float testNanValue = new Float(Float.NaN); Number testNumberValue = testNanValue; if (Double.isNaN(testNumberValue.doubleValue())) { logger.fine("Float test NaN value is still recognized as a Double NaN."); }/* w w w . j a v a 2s. co m*/ int invalid = countInvalidValues(x); nx[4] = invalid; logger.fine("counted invalid values: " + nx[4]); nx[3] = x.length - invalid; logger.fine("counted valid values: " + nx[3]); //double[] newx = prepareForSummaryStats(x); double[] newx = prepareForSummaryStatsAlternative(x, x.length - invalid); logger.fine("prepared double vector for summary stats calculation (" + newx.length + " double values);"); ////nx[0] = StatUtils.mean(newx); nx[0] = calculateMean(newx); logger.fine("calculated mean: " + nx[0]); ////nx[1] = StatUtils.percentile(newx, 50); nx[1] = calculateMedian(newx); logger.fine("calculated medn: " + nx[1]); nx[2] = 0.0; //getMode(newx); nx[5] = StatUtils.min(newx); logger.fine("calculated min: " + nx[5]); nx[6] = StatUtils.max(newx); logger.fine("calculated max: " + nx[6]); nx[7] = Math.sqrt(StatUtils.variance(newx)); logger.fine("calculated stdev: " + nx[7]); return nx; }
From source file:MathFunc.java
/** * Returns the arc cosine of an angle, in the range of 0.0 through <code>Math.PI</code>. * Special case:// w w w . j av a 2 s. c om * <ul> * <li>If the argument is <code>NaN</code> or its absolute value is greater than 1, * then the result is <code>NaN</code>. * </ul> * * @param a - the value whose arc cosine is to be returned. * @return the arc cosine of the argument. */ public static double acos(double a) { // Special case. if (Double.isNaN(a) || Math.abs(a) > 1.0) { return Double.NaN; } // Calculate the arc cosine. double aSquared = a * a; double arcCosine = atan2(Math.sqrt(1 - aSquared), a); return arcCosine; }
From source file:ch.algotrader.util.RoundUtil.java
public static BigDecimal getBigDecimal(double value) { if (Double.isNaN(value) || Double.isInfinite(value)) { return null; } else {//from w w w.j a va 2 s .co m BigDecimal decimal = new BigDecimal(value); CommonConfig commonConfig = ConfigLocator.instance().getCommonConfig(); return decimal.setScale(commonConfig.getPortfolioDigits(), BigDecimal.ROUND_HALF_UP); } }
From source file:lirmm.inria.fr.math.TestUtils.java
/** * Verifies that expected and actual are within delta, or are both NaN or * infinities of the same sign.//from w ww. j ava 2s. co m */ public static void assertEquals(String msg, double expected, double actual, double delta) { // check for NaN if (Double.isNaN(expected)) { Assert.assertTrue("" + actual + " is not NaN.", Double.isNaN(actual)); } else { Assert.assertEquals(msg, expected, actual, delta); } }
From source file:com.yahoo.egads.models.tsmm.TimeSeriesAbstractModel.java
private static int compareError(double error1, double error2) { // can't compare NaN if (Double.isNaN(error1) || Double.isNaN(error2)) { return 0; }/* www. j a va 2 s . c o m*/ // positive when error1 is better (smaller) then error2 double diffAbs = Math.abs(error2) - Math.abs(error1); if (Math.abs(diffAbs) <= TOLERANCE) { return 0; } return diffAbs > 0 ? 1 : -1; }
From source file:gedi.lfc.foldchange.PosteriorMeanLog2FoldChange.java
@Override public double computeFoldChange(double a, double b) { if (Double.isNaN(a) || Double.isNaN(b)) return Double.NaN; return (Gamma.digamma(a + priorA) - Gamma.digamma(b + priorB)) / Math.log(2); }
From source file:bots.mctsbot.ai.bots.util.Gaussian.java
public Gaussian(double mean, double variance) { if (Double.isInfinite(mean) || Double.isNaN(mean)) { logger.error("Bad mean: " + mean); throw new IllegalArgumentException("Bad mean: " + mean); }//w w w . j a va 2 s. c om if (Double.isInfinite(variance) || Double.isNaN(variance) || variance < 0) { logger.error("Bad variance: " + variance); throw new IllegalArgumentException("Bad variance: " + variance); } this.mean = mean; this.variance = variance; }
From source file:Main.java
/** * <p>Returns the minimum value in an array.</p> * * @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#min(double[]) IEEE754rUtils for a version of this method that handles NaN differently *///w w w. ja v a2 s . c om public static double min(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 min double min = array[0]; for (int i = 1; i < array.length; i++) { if (Double.isNaN(array[i])) { return Double.NaN; } if (array[i] < min) { min = array[i]; } } return min; }