Alex Herbert created STATISTICS-83:
--------------------------------------
Summary: Mean returns a non-finite value that can be incorrect
Key: STATISTICS-83
URL: https://issues.apache.org/jira/browse/STATISTICS-83
Project: Commons Statistics
Issue Type: Bug
Components: descriptive
Reporter: Alex Herbert
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:
{code:java}
double[] values = {Double.MAX_VALUE, Double.MAX_VALUE,
Double.NEGATIVE_INFINITY};
// Computed value = NaN
Assertions.assertEquals(Double.NEGATIVE_INFINITY,
Mean.of(values).getAsDouble());
{code}
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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)