diff options
author | Eike Rathke <erack@redhat.com> | 2012-12-15 21:24:22 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-12-15 21:42:42 +0100 |
commit | 98a4e4f2ad405b60484f033570e2d2164656007b (patch) | |
tree | 29e026d12a6363b4f5504c1f9aadfefb77ed7f0d /sc | |
parent | EvalMatrix: do not short circuit, propagate errors (diff) | |
download | core-98a4e4f2ad405b60484f033570e2d2164656007b.tar.gz core-98a4e4f2ad405b60484f033570e2d2164656007b.zip |
EvalMatrix<XorEvaluator> for Xor
Change-Id: Ib0fdf7f8916a9d31fbcbedad925361d0cbe03b10
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index 810b8c20682e..66dcb2f83155 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -912,6 +912,14 @@ struct OrEvaluator OrEvaluator() : mbResult(false) {} }; +struct XorEvaluator +{ + bool mbResult; + void operate(double fVal) { mbResult ^= (fVal != 0.0); } + bool result() const { return mbResult; } + XorEvaluator() : mbResult(false) {} +}; + // Do not short circuit logical operations, in case there are error values // these need to be propagated even if the result was determined earlier. template <typename _Evaluator> @@ -959,26 +967,7 @@ double ScMatrixImpl::Xor() const { // All elements must be of value type. // True if an odd number of elements have a non-zero value. - bool bXor = false; - size_t nRows = maMat.size().row, nCols = maMat.size().column; - for (size_t i = 0; i < nRows; ++i) - { - for (size_t j = 0; j < nCols; ++j) - { - mdds::mtm::element_t eType = maMat.get_type(i, j); - if (eType != mdds::mtm::element_numeric && eType != mdds::mtm::element_boolean) - // assuming a CompareMat this is an error - return CreateDoubleError(errIllegalArgument); - - double fVal = maMat.get_numeric(i, j); - if (!::rtl::math::isFinite(fVal)) - // DoubleError - return fVal; - - bXor ^= (fVal != 0.0); - } - } - return bXor; + return EvalMatrix<XorEvaluator>(maMat); } namespace { |