diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-07-17 13:57:43 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-07-19 14:05:10 -0400 |
commit | c79305f2a1218a3cbf74c7db3c9745429e8b7883 (patch) | |
tree | f2087c290724f4020aefcca65ab4dafc2db4e256 /sc | |
parent | 608fdfe12329094604d9424f1225e23d94ac7537 (diff) |
For sum product, the initial accumulator value should be 1, not 0.
Change-Id: I16ce22150627f75eab08cc4d58fc63a76572c010
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index 67f2ffb9ee93..9e358435044f 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -960,6 +960,8 @@ namespace { struct SumOp { + static const double initVal = 0.0; + void operator() (double& rAccum, double fVal) { rAccum += fVal; @@ -968,6 +970,8 @@ struct SumOp struct SumSquareOp { + static const double initVal = 0.0; + void operator() (double& rAccum, double fVal) { rAccum += fVal*fVal; @@ -976,6 +980,8 @@ struct SumSquareOp struct ProductOp { + static const double initVal = 1.0; + void operator() (double& rAccum, double fVal) { rAccum *= fVal; @@ -991,7 +997,7 @@ class WalkElementBlocks : std::unary_function<MatrixImplType::element_block_node bool mbFirst:1; bool mbTextAsZero:1; public: - WalkElementBlocks(bool bTextAsZero) : maRes(0.0, 0.0, 0), mbFirst(true), mbTextAsZero(bTextAsZero) {} + WalkElementBlocks(bool bTextAsZero) : maRes(0.0, _Op::initVal, 0), mbFirst(true), mbTextAsZero(bTextAsZero) {} const ScMatrix::IterateResult& getResult() const { return maRes; } @@ -1092,7 +1098,8 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const { WalkElementBlocks<ProductOp> aFunc(bTextAsZero); maMat.walk(aFunc); - return aFunc.getResult(); + ScMatrix::IterateResult aRes = aFunc.getResult(); + return aRes; } size_t ScMatrixImpl::Count(bool bCountStrings) const |