Package com.io7m.jequality
Class AlmostEqualFloat
java.lang.Object
com.io7m.jequality.AlmostEqualFloat
Better floating point comparisons.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe necessary context for floating point comparisons. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanalmostEqual(AlmostEqualFloat.ContextRelative context, float x, float y) Compare the floating point numbersxandyusing the contextcontext.
-
Method Details
-
almostEqual
Compare the floating point numbers
xandyusing the contextcontext.Essentially, given
diff = abs(x - y), ifdiff <= context.getMaxRelativeDifference() * max(abs(x), abs(y)), thenxandycan 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:
trueifxandyare almost equal
-