List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:Main.java
public static void main(String[] args) { double d = (double) 4 / 0; boolean b1 = Double.isInfinite(d); System.out.println(b1);//from w w w. j a v a2 s. c om Double dObj = new Double(d); boolean b2 = dObj.isInfinite(); System.out.println(b2); }
From source file:Main.java
public static void main(String[] args) { Double double1 = new Double(1 / 0.0); System.out.println(Double.isInfinite(double1)); }
From source file:FpError.java
public static void main(String[] args) { double res;//from w ww .j a v a2s . com double divisor = 0; double dividend, root; // Get user input for numerator System.out.println("Forcing division by zero error"); dividend = 10d; res = dividend / divisor; // Test for negative invifinity if (res == Double.NEGATIVE_INFINITY) System.out.println("result is NEGATIVE_INFINITY"); if (res == Double.POSITIVE_INFINITY) System.out.println("result is POSITIVE_INFINITY"); // Test for either infinity if (Double.isInfinite(res)) System.out.println("result is infinite"); // Get user input for square root System.out.println("\nCalculating square root (try negative)"); root = 10d; res = Math.sqrt(root); if (Double.isNaN(res)) System.out.println("result is Nan"); else System.out.println("Square root = " + res); }
From source file:Main.java
/** * Returns true if the number is not NaN or infinite. * @param d/*ww w.j a va2 s .co m*/ * @return */ public static boolean isReal(double d) { return !Double.isNaN(d) && !Double.isInfinite(d); }
From source file:Main.java
/** * Indicates whether the given double valid, implying it is not null, not * infinite and not NaN.//from ww w . jav a2 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
public static boolean isInfinity(Object number) { if (number == null) { return false; }//from w w w . j av a 2 s . c o m try { return Double.isInfinite((Double) number); } catch (Exception e) { return false; } }
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:Main.java
public static double stDist(final double v, final double t) { double sm = 0.5; double sign = 1.0; final double stepSize = t / 5000.0; if (t < 0.0) { sign = -1.0;/*from ww w .j a va 2 s . c o m*/ } else if (t == 0.0 || Double.isInfinite(t)) { return sm; } for (double u = 0.0; u <= sign * t; u += stepSize) { sm += stepSize * student_tDen(v, u); } if (sign < 0.0) { sm = 0.5 - sm; } else { sm = 1.0 - sm; } if (sm < 0.0) { sm = 0.0; } else if (sm > 1.0) { sm = 1.0; } return sm; }
From source file:dk.nodes.webservice.parser.NJSON.java
/** * Returns the input if it is a JSON-permissible value; throws otherwise. *///w ww . j av a 2 s.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; }