summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-12-15 20:46:41 +0100
committerEike Rathke <erack@redhat.com>2012-12-15 21:42:41 +0100
commitc86a9c4f045dfc8bbcad27cf36f1c6a8178a48a7 (patch)
tree20da6c7087b0b64d7efba6969e07b0c831ea0a4c /sc
parentcf309b04a0780c042393bcacf1666ce6053cdc2c (diff)
EvalMatrix: do not short circuit, propagate errors
Change-Id: I3118fb2a4d30e1626a05e9872b34a3c33bd487be
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/tool/scmatrix.cxx24
1 files changed, 14 insertions, 10 deletions
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 259d7477943b..810b8c20682e 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -296,6 +296,7 @@ void compareMatrix(MatrixImplType& rMat)
double fVal = rMat.get_numeric(i, j);
if (!::rtl::math::isFinite(fVal))
+ /* FIXME: this silently skips an error instead of propagating it! */
continue;
bool b = aComp(fVal);
@@ -897,20 +898,24 @@ namespace {
struct AndEvaluator
{
- bool isBadElem(double fVal) const { return fVal == 0; }
- bool returnOnElem() const { return false; }
- bool returnOnAllElems() const { return true; }
+ bool mbResult;
+ void operate(double fVal) { mbResult &= (fVal != 0.0); }
+ bool result() const { return mbResult; }
+ AndEvaluator() : mbResult(true) {}
};
struct OrEvaluator
{
- bool isBadElem(double fVal) const { return fVal != 0; }
- bool returnOnElem() const { return true; }
- bool returnOnAllElems() const { return false; }
+ bool mbResult;
+ void operate(double fVal) { mbResult |= (fVal != 0.0); }
+ bool result() const { return mbResult; }
+ OrEvaluator() : 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>
-bool EvalMatrix(const MatrixImplType& rMat)
+double EvalMatrix(const MatrixImplType& rMat)
{
_Evaluator aEval;
size_t nRows = rMat.size().row, nCols = rMat.size().column;
@@ -928,11 +933,10 @@ bool EvalMatrix(const MatrixImplType& rMat)
// DoubleError
return fVal;
- if (aEval.isBadElem(fVal))
- return aEval.returnOnElem();
+ aEval.operate(fVal);
}
}
- return aEval.returnOnAllElems();
+ return aEval.result();
}
}