[BEAM-413] - Improves test for floating point equality.#591
[BEAM-413] - Improves test for floating point equality.#591lucasamorimca wants to merge 1 commit intoapache:masterfrom
Conversation
This operation compares two floating point values for equality. Because floating point calculations may involve rounding, calculated float and double values may not be accurate. For values that must be precise, such as monetary values, consider using a fixed-precision type such as BigDecimal. For values that need not be precise, consider comparing for equality within some range, for example: if ( Math.abs(x - y) < .0000001 ). For more information: https://issues.apache.org/jira/browse/BEAM-413
|
Thanks for your pull request. The choice of 1e-7 here as a cutoff is arbitrary here; when choosing a bound for equality one needs to consider what makes sense in context, and there really isn't any context to go on here, thus I think the only correct thing to do here is leave exact equality. (Either that or simply remove the equals() method on CountSum, it's really not needed.) |
| } | ||
| @SuppressWarnings("unchecked") | ||
| CountSum<?> otherCountSum = (CountSum<?>) other; | ||
| return (count == otherCountSum.count) |
|
Sensible options here:
All three of these are probably better solutions than the current PR. |
|
Thanks for the feedback :) |
|
+1 to removing equals. It should only every be used in tests, if anywhere, and there it should be "equals up to error bound" in context like @robertwb says. |
|
@lucasallan -- thanks for picking this bug and all the other starter issues you fixed recently; excited to have your contributions! Hope you're willing to try again in this PR if interested. |
|
@dhalperi yes, I'll pick this up again and I also have other issues in my queue to work on. Looking forward for more of your feedback. |
This operation compares two floating point values for equality. Because
floating point calculations may involve rounding, calculated float and
double values may not be accurate. For values that must be precise, such
as monetary values, consider using a fixed-precision type such as
BigDecimal. For values that need not be precise, consider comparing for
equality within some range, for example: if ( Math.abs(x - y) < .0000001
).
For more information: https://issues.apache.org/jira/browse/BEAM-413