Package com.io7m.jequality
Class AlmostEqualDouble
java.lang.Object
com.io7m.jequality.AlmostEqualDouble
Better floating point comparisons.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
The necessary context for floating point comparisons. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
almostEqual
(AlmostEqualDouble.ContextRelative context, double x, double y) Compare the floating point numbersx
andy
using the contextcontext
.
-
Method Details
-
almostEqual
Compare the floating point numbers
x
andy
using the contextcontext
.Essentially, given
diff = abs(x - y)
, ifdiff <= context.getMaxRelativeDifference() * max(abs(x), abs(y))
, thenx
andy
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.
- Parameters:
context
- The equality contextx
- The left parametery
- The right parameter- Returns:
true
ifx
andy
are almost equal
-