@EqualityReference public final class AlmostEqualDouble extends Object
Better floating point comparisons.
| Modifier and Type | Class and Description |
|---|---|
static class |
AlmostEqualDouble.ContextRelative
The necessary context for floating point comparisons.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
almostEqual(AlmostEqualDouble.ContextRelative context,
double x,
double y)
Compare the floating point numbers
x and y
using the context context. |
public static boolean almostEqual(AlmostEqualDouble.ContextRelative context, double x, double y)
Compare the floating point numbers x and y
using the context context.
Essentially, given diff = abs(x - y), if
diff <= context.getMaxRelativeDifference() * max(abs(x), abs(y))
, then x and y can be considered to be close
together.
See the article mentioned at the top of this article for suggested absolute and relative epsilon values: There are no values that work well for all possible inputs.
context - The equality contextx - The left parametery - The right parametertrue if x and y are almost
equalCopyright © 2014 <code@io7m.com> http://io7m.com