Apache OpenOffice (AOO) Bugzilla – Issue 101316
STDEV is inaccurate
Last modified: 2017-05-20 11:42:13 UTC
STDEV should return 0 when all numbers are equal. Enter 1e+30 in A1, A2, A3, and =STDEV(A1:A3) in A4. The result should be 0, but it is 172367517075721. (Wrong) Suggested fixes: Centre data before calculating STDEV, use a better algorithm. Some Excel versions suffer from the same problem: see http://www.daheiser.info/ excel/frontpage.html link to Note O.
Created attachment 61770 [details] Illustrate wrong STDEV
I see the error too in a DEV300m44. There is no obvious reason. For 1E+29 the result is correct. It needs a deeper look at. I add dependency to 18704.
The error comes from cancellation with total loss of significance in value-mean in some cases. It seems to be the same kind of error as the known "3*1/3 != 1" problem. I see the error only, when using identical values in the data series, which seems to be a very constructed example. But the results are totally wrong in those cases. I'll attach test cases, where you see the error examples with colored background. You can notice, that the values are correct, if the denominator is 4, which can be represented exactly in binary code. I looked at Gnumeric and Excel too, neither of them correct this kind of errors. You can correct the error, if you use approxSub instead of a simple minus. I have tried to find out, whether this change will decrease accuracy in other cases. I don't find any examples, which would have a decreased accuracy, but perhaps you have got some critical test case?
Created attachment 61825 [details] exchange minus with approxSub; only 1 line
Created attachment 61826 [details] some examples of the error
Reproduced on Linux/x86. Grabbing issue, changing type to PATCH.
In cws odff06: revision 271399 sc/source/core/tool/interpr1.cxx We may want to keep an eye on accuracy with other sample values that could make it necessary to pre-analyze the values for equality. A similarity to SUM and such comes to mind..
Reassigning to QA for verification.
verified in internal build cws_odff06