List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:net.pms.util.Rational.java
/** * Returns a {@link Rational} whose value is {@code (this * value)}. * * @param value the value to be multiplied by this {@link Rational}. * @return The multiplication result.//ww w . j ava 2s . c o m */ @Nonnull public Rational multiply(double value) { if (isNaN() || Double.isNaN(value)) { return NaN; } if (isInfinite() || Double.isInfinite(value)) { if (signum() == 0 || value == 0f) { return NaN; // Infinity by zero } if (value > 0) { return signum() > 0 ? POSITIVE_INFINITY : NEGATIVE_INFINITY; } return signum() < 0 ? POSITIVE_INFINITY : NEGATIVE_INFINITY; } if (value == 0f) { return ZERO; } return multiply(valueOf(value)); }
From source file:org.orekit.time.AbsoluteDateTest.java
@Test public void testInfinity() { Assert.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(AbsoluteDate.PAST_INFINITY) > 0); Assert.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0); Assert.assertTrue(AbsoluteDate.J2000_EPOCH.compareTo(AbsoluteDate.PAST_INFINITY) > 0); Assert.assertTrue(AbsoluteDate.J2000_EPOCH.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0); Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.JULIAN_EPOCH) < 0); Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.J2000_EPOCH) < 0); Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0); Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.JULIAN_EPOCH) > 0); Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.J2000_EPOCH) > 0); Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.PAST_INFINITY) > 0); Assert.assertTrue(Double.isInfinite(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.J2000_EPOCH))); Assert.assertTrue(Double.isInfinite(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.PAST_INFINITY))); Assert.assertTrue(Double.isInfinite(AbsoluteDate.PAST_INFINITY.durationFrom(AbsoluteDate.J2000_EPOCH))); }
From source file:org.tros.utils.Random.java
/** * Returns a random integer from a Poisson distribution with mean λ. * * @param lambda the mean of the Poisson distribution * @return a random integer from a Poisson distribution with mean * <tt>lambda</tt>//from ww w . j a va2 s. co m * @throws IllegalArgumentException unless <tt>lambda > 0.0</tt> and not * infinite */ public static int poisson(double lambda) { if (!(lambda > 0.0)) { throw new IllegalArgumentException("Parameter lambda must be positive"); } if (Double.isInfinite(lambda)) { throw new IllegalArgumentException("Parameter lambda must not be infinite"); } // using algorithm given by Knuth // see http://en.wikipedia.org/wiki/Poisson_distribution int k = 0; double p = 1.0; double L = Math.exp(-lambda); do { k++; p *= nextDouble(); } while (p >= L); return k - 1; }
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Finds out if n represents a Double.// w w w . j a va2 s . c o m * * @return true if n is instanceOf Double or the literal value can be * evaluated as a Double. */ private static boolean isDouble(Number n) { if (n instanceof Double) { return true; } try { double d = Double.parseDouble(String.valueOf(n)); return !Double.isInfinite(d); } catch (NumberFormatException e) { return false; } }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("round to given number of decimal places") @ScalarFunction/* ww w.j av a2s.c om*/ @SqlType(StandardTypes.DOUBLE) public static double round(@SqlType(StandardTypes.DOUBLE) double num, @SqlType(StandardTypes.INTEGER) long decimals) { if (Double.isNaN(num) || Double.isInfinite(num)) { return num; } double factor = Math.pow(10, decimals); if (num < 0) { return -(Math.round(-num * factor) / factor); } return Math.round(num * factor) / factor; }
From source file:Complex.java
/** * Compute the/*from w w w . ja v a 2 s. c o m*/ * <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top"> * tangent</a> of this complex number. * Implements the formula: * <pre> * <code> * tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i * </code> * </pre> * where the (real) functions on the right-hand side are * {@link FastMath#sin}, {@link FastMath#cos}, {@link FastMath#cosh} and * {@link FastMath#sinh}. * <br/> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN}. * <br/> * Infinite (or critical) values in real or imaginary parts of the input may * result in infinite or NaN values returned in parts of the result. * <pre> * Examples: * <code> * tan(a ± INFINITY i) = 0 ± i * tan(±INFINITY + bi) = NaN + NaN i * tan(±INFINITY ± INFINITY i) = NaN + NaN i * tan(±π/2 + 0 i) = ±INFINITY + NaN i * </code> * </pre> * * @return the tangent of {@code this}. * @since 1.2 */ public Complex tan() { if (isNaN || Double.isInfinite(real)) { return NaN; } if (imaginary > 20.0) { return createComplex(0.0, 1.0); } if (imaginary < -20.0) { return createComplex(0.0, -1.0); } double real2 = 2.0 * real; double imaginary2 = 2.0 * imaginary; double d = FastMath.cos(real2) + FastMath.cosh(imaginary2); return createComplex(FastMath.sin(real2) / d, FastMath.sinh(imaginary2) / d); }
From source file:org.apache.sysml.hops.codegen.opt.PlanSelectionFuseCostBased.java
private static double rGetPlanCosts(CPlanMemoTable memo, Hop current, HashSet<Pair<Long, Long>> visited, HashSet<Long> partition, ArrayList<Long> M, boolean[] plan, HashMap<Long, Double> computeCosts, CostVector costsCurrent, TemplateType currentType) { //memoization per hop id and cost vector to account for redundant //computation without double counting materialized results or compute //costs of complex operation DAGs within a single fused operator Pair<Long, Long> tag = Pair.of(current.getHopID(), (costsCurrent == null) ? 0 : costsCurrent.ID); if (visited.contains(tag)) return 0; visited.add(tag);//from www. ja v a2s .co m //open template if necessary, including memoization //under awareness of current plan choice MemoTableEntry best = null; boolean opened = false; if (memo.contains(current.getHopID())) { if (currentType == null) { best = memo.get(current.getHopID()).stream().filter(p -> p.isValid()) .filter(p -> hasNoRefToMaterialization(p, M, plan)).min(new BasicPlanComparator()) .orElse(null); opened = true; } else { best = memo.get(current.getHopID()).stream() .filter(p -> p.type == currentType || p.type == TemplateType.CELL) .filter(p -> hasNoRefToMaterialization(p, M, plan)) .min(Comparator.comparing(p -> 7 - ((p.type == currentType) ? 4 : 0) - p.countPlanRefs())) .orElse(null); } } //create new cost vector if opened, initialized with write costs CostVector costVect = !opened ? costsCurrent : new CostVector(Math.max(current.getDim1(), 1) * Math.max(current.getDim2(), 1)); //add compute costs of current operator to costs vector if (partition.contains(current.getHopID())) costVect.computeCosts += computeCosts.get(current.getHopID()); //process children recursively double costs = 0; for (int i = 0; i < current.getInput().size(); i++) { Hop c = current.getInput().get(i); if (best != null && best.isPlanRef(i)) costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, costVect, best.type); else if (best != null && isImplicitlyFused(current, i, best.type)) costVect.addInputSize(c.getInput().get(0).getHopID(), Math.max(c.getDim1(), 1) * Math.max(c.getDim2(), 1)); else { //include children and I/O costs costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, null, null); if (costVect != null && c.getDataType().isMatrix()) costVect.addInputSize(c.getHopID(), Math.max(c.getDim1(), 1) * Math.max(c.getDim2(), 1)); } } //add costs for opened fused operator if (partition.contains(current.getHopID())) { if (opened) { if (LOG.isTraceEnabled()) LOG.trace("Cost vector for fused operator (hop " + current.getHopID() + "): " + costVect); costs += costVect.outSize * 8 / WRITE_BANDWIDTH; //time for output write costs += Math.max(costVect.computeCosts * costVect.getMaxInputSize() / COMPUTE_BANDWIDTH, costVect.getSumInputSizes() * 8 / READ_BANDWIDTH); } //add costs for non-partition read in the middle of fused operator else if (hasNonPartitionConsumer(current, partition)) { costs += rGetPlanCosts(memo, current, visited, partition, M, plan, computeCosts, null, null); } } //sanity check non-negative costs if (costs < 0 || Double.isNaN(costs) || Double.isInfinite(costs)) throw new RuntimeException("Wrong cost estimate: " + costs); return costs; }
From source file:org.eclipse.dataset.AbstractDataset.java
protected static long toLong(final Object b) { if (b instanceof Number) { double t = ((Number) b).doubleValue(); if (Double.isNaN(t) || Double.isInfinite(t)) { return 0; }/* www. jav a 2 s. co m*/ return ((Number) b).longValue(); } else if (b instanceof Boolean) { return ((Boolean) b).booleanValue() ? 1 : 0; } else if (b instanceof Complex) { return (long) ((Complex) b).getReal(); } else if (b instanceof Dataset) { Dataset db = (Dataset) b; if (db.getSize() != 1) { logger.error("Given dataset must have only one item"); throw new IllegalArgumentException("Given dataset must have only one item"); } return toLong(db.getObjectAbs(0)); } else if (b instanceof IDataset) { IDataset db = (Dataset) b; if (db.getSize() != 1) { logger.error("Given dataset must have only one item"); throw new IllegalArgumentException("Given dataset must have only one item"); } return toLong(db.getObject(new int[db.getRank()])); } else { logger.error("Argument is of unsupported class"); throw new IllegalArgumentException("Argument is of unsupported class"); } }
From source file:Complex.java
/** * Compute the//from w ww. ja va 2 s. c o m * <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top"> * hyperbolic tangent</a> of this complex number. * Implements the formula: * <pre> * <code> * tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i * </code> * </pre> * where the (real) functions on the right-hand side are * {@link FastMath#sin}, {@link FastMath#cos}, {@link FastMath#cosh} and * {@link FastMath#sinh}. * <br/> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN}. * <br/> * Infinite values in real or imaginary parts of the input may result in * infinite or NaN values returned in parts of the result. * <pre> * Examples: * <code> * tanh(a ± INFINITY i) = NaN + NaN i * tanh(±INFINITY + bi) = ±1 + 0 i * tanh(±INFINITY ± INFINITY i) = NaN + NaN i * tanh(0 + (π/2)i) = NaN + INFINITY i * </code> * </pre> * * @return the hyperbolic tangent of {@code this}. * @since 1.2 */ public Complex tanh() { if (isNaN || Double.isInfinite(imaginary)) { return NaN; } if (real > 20.0) { return createComplex(1.0, 0.0); } if (real < -20.0) { return createComplex(-1.0, 0.0); } double real2 = 2.0 * real; double imaginary2 = 2.0 * imaginary; double d = FastMath.cosh(real2) + FastMath.cos(imaginary2); return createComplex(FastMath.sinh(real2) / d, FastMath.sin(imaginary2) / d); }
From source file:org.eclipse.dataset.DoubleDataset.java
@Override public boolean containsInfs() { IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY if (Double.isInfinite(data[iter.index])) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY return false; }