@EqualityReference public final class AlmostEqualFloat extends Object
Better floating point comparisons.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
AlmostEqualFloat.ContextRelative |
The necessary context for floating point comparisons.
|
| Modifier and Type | Method | Description |
|---|---|---|
static boolean |
almostEqual(AlmostEqualFloat.ContextRelative context,
float x,
float y) |
Compare the floating point numbers
x and y using the
context context. |
public static boolean almostEqual(AlmostEqualFloat.ContextRelative context, float x, float 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 © 2017 <code@io7m.com> http://io7m.com