List of usage examples for com.google.common.math DoubleMath fuzzyEquals
public static boolean fuzzyEquals(double a, double b, double tolerance)
From source file:org.eclipse.elk.alg.layered.compaction.oned.CompareFuzzy.java
public static boolean eq(final double d1, final double d2) { return DoubleMath.fuzzyEquals(d1, d2, TOLERANCE); }
From source file:org.tzi.use.util.FloatUtil.java
/** * Compares two floats for equality using the default precision defined by * {@link Options#DEFAULT_FLOAT_PRECISION}. *//*from ww w .j a v a 2 s. c o m*/ public static boolean equals(float a, float b) { return DoubleMath.fuzzyEquals(a, b, EPSILON); }
From source file:org.tzi.use.util.FloatUtil.java
/** * Compares two floats for equality using a given precision. * //w w w. j av a 2s . co m * @param precision number of decimals where the first difference may occur */ public static boolean equals(float a, float b, int precision) { return DoubleMath.fuzzyEquals(a, b, Math.pow(10, -precision)); }
From source file:com.opengamma.strata.math.impl.minimization.MinimumBracketer.java
protected void checkInputs(Function<Double, Double> f, double xLower, double xUpper) { ArgChecker.notNull(f, "function"); if (DoubleMath.fuzzyEquals(xLower, xUpper, ZERO)) { throw new IllegalArgumentException("Lower and upper values were not distinct"); }//w w w . j av a 2 s .co m }
From source file:com.ibm.og.util.Distributions.java
/** * Creates a uniform distribution with a range of [average - spread, average + spread]. * //from w ww .ja v a 2s . co m * @param average the average value of this distribution * @param spread distance from the average * @return a uniform distribution instance * @throws IllegalArgumentException if average or spread are negative, or if average - spread is * negative */ public static Distribution uniform(final double average, final double spread) { checkArgument(average >= 0.0, "average must be >= 0.0 [%s]", average); checkArgument(spread >= 0.0, "spread must be >= 0.0 [%s]", spread); if (DoubleMath.fuzzyEquals(spread, 0.0, Distributions.ERR)) { return constant(average); } final double lower = average - spread; final double upper = average + spread; checkArgument(lower >= 0.0, "average - spread must be >= 0.0 [%s]", lower); final String s = String.format("UniformDistribution [average=%s, spread=%s]", average, spread); return new RealDistributionAdapter(new UniformRealDistribution(lower, upper), s); }
From source file:com.google.errorprone.bugpatterns.testdata.FuzzyEqualsShouldNotBeUsedInEqualsMethodPositiveCases.java
public boolean equals(Object o) { // BUG: Diagnostic contains: DoubleMath.fuzzyEquals should never DoubleMath.fuzzyEquals(0.2, 9.3, 2.0); return true;/*from w w w .j a v a 2 s . c o m*/ }
From source file:org.tzi.use.util.FloatUtil.java
/** * Compares two doubles for equality using the default precision defined by * {@link Options#DEFAULT_FLOAT_PRECISION}. *//*from w w w.j a v a 2 s . c o m*/ public static boolean equals(double a, double b) { return DoubleMath.fuzzyEquals(a, b, EPSILON); }
From source file:com.opengamma.strata.math.impl.statistics.distribution.StudentTOneTailedCriticalValueCalculator.java
@Override public Double apply(Double x) { ArgChecker.notNull(x, "x"); ArgChecker.notNegative(x, "x"); if (DoubleMath.fuzzyEquals(x, 0.5, 1e-14)) { return 0.5; }/*from ww w. j a va 2 s . c o m*/ return _dist.getInverseCDF(x); }
From source file:org.tzi.use.util.FloatUtil.java
/** * Compares two doubles for equality using a given precision. * /*from ww w .j a va2s.c o m*/ * @param precision number of decimals where the first difference may occur */ public static boolean equals(double a, double b, int precision) { return DoubleMath.fuzzyEquals(a, b, Math.pow(10, -precision)); }
From source file:com.opengamma.strata.math.impl.rootfinding.CubicRealRootFinder.java
@Override public Double[] getRoots(RealPolynomialFunction1D function) { ArgChecker.notNull(function, "function"); double[] coefficients = function.getCoefficients(); if (coefficients.length != 4) { throw new IllegalArgumentException("Function is not a cubic"); }/*from w w w . jav a 2s.c om*/ ComplexNumber[] result = ROOT_FINDER.getRoots(function); List<Double> reals = new ArrayList<>(); for (ComplexNumber c : result) { if (DoubleMath.fuzzyEquals(c.getImaginary(), 0d, 1e-16)) { reals.add(c.getReal()); } } ArgChecker.isTrue(reals.size() > 0, "Could not find any real roots"); return reals.toArray(EMPTY_ARRAY); }