diff options
author | Eike Rathke <erack@redhat.com> | 2016-03-02 21:18:24 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-03-02 21:20:39 +0100 |
commit | b2f5336b08b5f638f890a626eb2aeefaf499a79b (patch) | |
tree | 6bb891a23ddb708b8a70464625c47f1b54c844d3 /sc/source | |
parent | 6d7aeebcce020125caf660636e7dc7a5f160858e (diff) |
Resolves: tdf#98297 exclude error values from COUNT in array/matrix
Change-Id: I202dcc2a2b90ee8ed27815b97a2aad6e4df2f1b9
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/tool/interpr6.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 32 |
2 files changed, 26 insertions, 10 deletions
diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx index 306d81fef1dc..78d6f47c2589 100644 --- a/sc/source/core/tool/interpr6.cxx +++ b/sc/source/core/tool/interpr6.cxx @@ -433,10 +433,10 @@ void IterateMatrix( } break; case ifCOUNT: - rCount += pMat->Count(bTextAsZero); + rCount += pMat->Count(bTextAsZero, false); // do not count error values break; case ifCOUNT2: - rCount += pMat->Count(true); + rCount += pMat->Count(true, true); // do count error values break; case ifPRODUCT: { diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index 279701e98cbf..1a5d0121389f 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -284,7 +284,7 @@ public: ScMatrix::IterateResult Sum(bool bTextAsZero) const; ScMatrix::IterateResult SumSquare(bool bTextAsZero) const; ScMatrix::IterateResult Product(bool bTextAsZero) const; - size_t Count(bool bCountStrings) const; + size_t Count(bool bCountStrings, bool bCountErrors) const; size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const; size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const; @@ -1163,8 +1163,10 @@ class CountElements : public std::unary_function<MatrixImplType::element_block_n { size_t mnCount; bool mbCountString; + bool mbCountErrors; public: - explicit CountElements(bool bCountString) : mnCount(0), mbCountString(bCountString) {} + explicit CountElements(bool bCountString, bool bCountErrors) : + mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors) {} size_t getCount() const { return mnCount; } @@ -1173,6 +1175,20 @@ public: switch (node.type) { case mdds::mtm::element_numeric: + mnCount += node.size; + if (!mbCountErrors) + { + typedef MatrixImplType::numeric_block_type block_type; + + block_type::const_iterator it = block_type::begin(*node.data); + block_type::const_iterator itEnd = block_type::end(*node.data); + for (; it != itEnd; ++it) + { + if (!::rtl::math::isFinite(*it)) + --mnCount; + } + } + break; case mdds::mtm::element_boolean: mnCount += node.size; break; @@ -1782,9 +1798,9 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const return GetValueWithCount<sc::op::Product>(bTextAsZero, maMat); } -size_t ScMatrixImpl::Count(bool bCountStrings) const +size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors) const { - CountElements aFunc(bCountStrings); + CountElements aFunc(bCountStrings, bCountErrors); maMat.walk(aFunc); return aFunc.getCount(); } @@ -2682,9 +2698,9 @@ ScMatrix::IterateResult ScFullMatrix::Product(bool bTextAsZero) const return pImpl->Product(bTextAsZero); } -size_t ScFullMatrix::Count(bool bCountStrings) const +size_t ScFullMatrix::Count(bool bCountStrings, bool bCountErrors) const { - return pImpl->Count(bCountStrings); + return pImpl->Count(bCountStrings, bCountErrors); } size_t ScFullMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const @@ -3581,10 +3597,10 @@ ScMatrix::IterateResult ScVectorRefMatrix::Product(bool bTextAsZero) const return mpFullMatrix->Product(bTextAsZero); } -size_t ScVectorRefMatrix::Count(bool bCountStrings) const +size_t ScVectorRefMatrix::Count(bool bCountStrings, bool bCountErrors) const { const_cast<ScVectorRefMatrix*>(this)->ensureFullMatrix(); - return mpFullMatrix->Count(bCountStrings); + return mpFullMatrix->Count(bCountStrings, bCountErrors); } size_t ScVectorRefMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const |