List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:Main.java
/** * Determines the minimum and maximum values in the <tt>array</tt>, ignoring any instances of <tt>noDataValue</tt>. * /*from w w w . ja v a 2s .c o m*/ * @param array * @param noDataValue * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum */ public static double[] minMax(double[] array, double noDataValue) { double[] ret = null; double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; double val; for (int i = 0; i < array.length; i++) { val = array[i]; if (val != noDataValue) { min = (val < min) ? val : min; max = (val > max) ? val : max; } } if (!Double.isInfinite(min) & !Double.isInfinite(max)) { ret = new double[] { min, max }; } return ret; }
From source file:com.analog.lyric.math.LyricSingularValueDecomposition.java
private static RealMatrix checkMatrix(RealMatrix m) { for (int i = 0; i < m.getRowDimension(); i++) { for (int j = 0; j < m.getColumnDimension(); j++) { if (Double.isNaN(m.getEntry(i, j)) || Double.isInfinite(m.getEntry(i, j))) { throw new DimpleException("cannot do SVD on matrix that contains NaN or infinite"); }/*from w w w . j av a2 s . c om*/ } } return m; }
From source file:Main.java
/** * Round the given value to the specified number of decimal places. The * value is rounded using the given method which is any method defined in * {@link BigDecimal}./*from www .j a v a 2s . c om*/ * * @param x the value to round. * @param scale the number of digits to the right of the decimal point. * @param roundingMethod the rounding method as defined in * {@link BigDecimal}. * @return the rounded value. * @since 1.1 */ public static double round(double x, int scale, int roundingMethod) { try { return (new BigDecimal(Double.toString(x)).setScale(scale, roundingMethod)).doubleValue(); } catch (NumberFormatException ex) { if (Double.isInfinite(x)) { return x; } else { return Double.NaN; } } }
From source file:de.mpicbg.knime.hcs.base.utils.Table2Matrix.java
public static RealMatrix extractMatrix(List<DataRow> rows, List<Attribute> params) { double[][] matrix = new double[rows.size()][params.size()]; int nbparams = params.size(); int m = 0;/*from ww w .j a va 2 s . c o m*/ for (DataRow row : rows) { int n = 0; for (Attribute readout : params) { Double val = readout.getDoubleAttribute(row); if ((val == null) || Double.isInfinite(val) || Double.isNaN(val)) { break; } matrix[m][n] = val; n += 1; } if (n == nbparams) { m += 1; } } // remove the unused rows. RealMatrix rmatrix = new Array2DRowRealMatrix(matrix); if (m > 0) { rmatrix = rmatrix.getSubMatrix(0, m - 1, 0, nbparams - 1); } return rmatrix; }
From source file:Main.java
/** * Get the next machine representable number after a number, moving * in the direction of another number.//from w w w. j a v a 2s.co m * <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:Main.java
/** * Returns <code>true</code> if the specified number is infinitely * large in magnitude, <code>false</code> otherwise. * * <p>Note that this method is equivalent to the {@link * Double#isInfinite(double) Double.isInfinite} method; the * functionality is included in this class for convenience. * * @param d the value to be tested./*from ww w. j av a 2 s .c o m*/ * @return <code>true</code> if the value of the argument is positive * infinity or negative infinity; <code>false</code> otherwise. */ public static boolean isInfinite(double d) { return Double.isInfinite(d); }
From source file:ch.algotrader.util.RoundUtil.java
public static BigDecimal getBigDecimal(double value) { if (Double.isNaN(value) || Double.isInfinite(value)) { return null; } else {//w w w .ja v a 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:de.tsystems.mms.apm.performancesignature.util.PerfSigUIUtils.java
public static BigDecimal round(final double d, final int scale) { try {// w w w . j a v a 2s . c o m return BigDecimal.valueOf(d).setScale(d % 1 == 0 ? 0 : scale, BigDecimal.ROUND_HALF_UP); } catch (NumberFormatException ex) { if (Double.isInfinite(d)) { return BigDecimal.valueOf(d); } else { return BigDecimal.ZERO; } } }
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); }//from www. ja v a 2 s. com 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:r.base.random.Beta.java
public static double rbeta(double aa, double bb) { double a, b, alpha; double r, s, t, u1, u2, v, w, y, z; boolean qsame; if (aa <= 0. || bb <= 0. || (Double.isInfinite(aa) && Double.isInfinite(bb))) { return (Double.NaN); }//from w ww . ja va2 s . c o m if (Double.isInfinite(aa)) { return 1.0; } if (Double.isInfinite(bb)) { return 0.0; } /* Test if we need new "initializing" */ qsame = (olda == aa) && (oldb == bb); if (!qsame) { olda = aa; oldb = bb; } a = Math.min(aa, bb); b = Math.max(aa, bb); /* a <= b */ alpha = a + b; if (a <= 1.0) { /* --- Algorithm BC --- */ /* changed notation, now also a <= b (was reversed) */ if (!qsame) { /* initialize */ beta = 1.0 / a; delta = 1.0 + b - a; k1 = delta * (0.0138889 + 0.0416667 * a) / (b * beta - 0.777778); k2 = 0.25 + (0.5 + 0.25 / delta) * a; } /* FIXME: "do { } while()", but not trivially because of "continue"s:*/ for (;;) { u1 = RNG.unif_rand(); u2 = RNG.unif_rand(); if (u1 < 0.5) { y = u1 * u2; z = u1 * y; if (0.25 * u2 + z - y >= k1) { continue; } } else { z = u1 * u1 * u2; if (z <= 0.25) { v = beta * Math.log(u1 / (1.0 - u1)); if (v <= expmax) { w = b * Math.exp(v); if (Double.isInfinite(w)) { w = Double.MAX_VALUE; } } else { w = Double.MAX_VALUE; } break; } if (z >= k2) { continue; } } v = beta * Math.log(u1 / (1.0 - u1)); if (v <= expmax) { w = b * Math.exp(v); if (Double.isInfinite(w)) { w = Double.MAX_VALUE; } } else { w = Double.MAX_VALUE; } if (alpha * (Math.log(alpha / (a + w)) + v) - 1.3862944 >= Math.log(z)) { break; } } return (aa == a) ? a / (a + w) : w / (a + w); } else { /* Algorithm BB */ if (!qsame) { /* initialize */ beta = Math.sqrt((alpha - 2.0) / (2.0 * a * b - alpha)); gamma = a + 1.0 / beta; } do { u1 = RNG.unif_rand(); u2 = RNG.unif_rand(); v = beta * Math.log(u1 / (1.0 - u1)); if (v <= expmax) { w = a * Math.exp(v); if (Double.isInfinite(w)) { w = Double.MAX_VALUE; } } else { w = Double.MAX_VALUE; } z = u1 * u1 * u2; r = gamma * v - 1.3862944; s = a + r - w; if (s + 2.609438 >= 5.0 * z) { break; } t = Math.log(z); if (s > t) { break; } } while (r + alpha * Math.log(alpha / (b + w)) < t); return (aa != a) ? b / (b + w) : w / (b + w); } }