aherbert commented on code in PR #136:
URL: https://github.com/apache/commons-numbers/pull/136#discussion_r1271292657
##########
commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Sum.java:
##########
@@ -202,7 +202,11 @@ public Sum subtract(final Sum other) {
* @return this instance.
*/
private Sum add(double s, double c) {
- return add(s).add(c);
+ add(s);
+ if (!Double.isNaN(c)) {
Review Comment:
I think this can use `isFinite(c)`. I don't think the compensation can be
infinite if the regular sum is still finite, so we do not have to sum infinite
compensation.
However, the NaN check should be faster so the two variants are the same.
Please add a comment as to why the NaN check is required, e.g. infinite terms
will generate a nan compensation. Do not destroy the regular IEEE754 sum with
spurious nan.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]