Details
-
Bug
-
Status: Closed
-
Trivial
-
Resolution: Won't Fix
-
None
-
None
-
None
-
Easy
Description
The Mean maintains a non-finite value to return in the event that the input contains non-finite values and the result is not finite.
The non-finite value is a simple sum of the input. This returns the correct result for most cases of nan/infinte values. However if the values contain only one sign of infinity and the other finite values overflow to an opposite infinity before the infinity is encountered the result is incorrect (due to +inf + -inf == nan), e.g. the following test fails:
double[] values = {Double.MAX_VALUE, Double.MAX_VALUE, Double.NEGATIVE_INFINITY}; // Computed value = NaN Assertions.assertEquals(Double.NEGATIVE_INFINITY, Mean.of(values).getAsDouble());
Investigate alternative options for non-finite results and either: correct the support; or drop support if performance is significantly impacted in order to handle for these rare cases.