From b689a929882562f3cd282f71b30167b3451047ac Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 13 Jun 2014 14:16:11 +0200 Subject: resolved fdo#79978 propagate error through DoubleArray of matrix Regression introduced with 83f77ab0661df992f241e5f9ecb1aa8f8eaeafec. Interpreter errors are transported using NaN coded doubles, using simple setNan()/isNan() to flag and ignore non-numeric values skips all error values. Change-Id: I0d3cb30262bc5ba7ee77e53a2bc45e56569fbc4b (cherry picked from commit a288bebbcec0b16e1ced09a601de5ffbb6b1bbe0) Reviewed-on: https://gerrit.libreoffice.org/9768 Reviewed-by: Kohei Yoshida Tested-by: Kohei Yoshida --- sc/source/core/tool/interpr1.cxx | 2 +- sc/source/core/tool/interpr5.cxx | 16 ++++++++++++++-- sc/source/core/tool/scmatrix.cxx | 10 +++++----- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'sc') diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 758ce156e057..a834488ee091 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -5615,7 +5615,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc ) continue; fVal = *itMain; - if (rtl::math::isNan(fVal)) + if (GetDoubleErrorValue(fVal) == errElementNaN) continue; ++fCount; diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx index d8b97c03ed5f..6f1b9ba37df8 100644 --- a/sc/source/core/tool/interpr5.cxx +++ b/sc/source/core/tool/interpr5.cxx @@ -1598,13 +1598,25 @@ namespace { class SumValues : std::unary_function { double mfSum; + bool mbError; public: - SumValues() : mfSum(0.0) {} + SumValues() : mfSum(0.0), mbError(false) {} void operator() (double f) { - if (!rtl::math::isNan(f)) + if (mbError) + return; + + sal_uInt16 nErr = GetDoubleErrorValue(f); + if (!nErr) mfSum += f; + else if (nErr != errElementNaN) + { + // Propagate the first error encountered, ignore "this is not a + // number" elements. + mfSum = f; + mbError = true; + } } double getValue() const { return mfSum; } diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index 3b2c42c2bb09..4f210a80bec4 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -1512,7 +1512,7 @@ public: ToDoubleArray( size_t nSize, bool bEmptyAsZero ) : maArray(nSize, 0.0), miPos(maArray.begin()), mbEmptyAsZero(bEmptyAsZero) { - rtl::math::setNan(&mfNaN); + mfNaN = CreateDoubleError( errElementNaN); } void operator() (const MatrixImplType::element_block_node_type& node) @@ -1583,7 +1583,7 @@ class MergeDoubleArrayFunc : std::unary_function& rArray) : mrArray(rArray), miPos(mrArray.begin()) { - rtl::math::setNan(&mfNaN); + mfNaN = CreateDoubleError( errElementNaN); } void operator() (const MatrixImplType::element_block_node_type& node) @@ -1599,7 +1599,7 @@ public: numeric_element_block::const_iterator itEnd = numeric_element_block::end(*node.data); for (; it != itEnd; ++it, ++miPos) { - if (rtl::math::isNan(*miPos)) + if (GetDoubleErrorValue(*miPos) == errElementNaN) continue; *miPos = op(*miPos, *it); @@ -1612,7 +1612,7 @@ public: boolean_element_block::const_iterator itEnd = boolean_element_block::end(*node.data); for (; it != itEnd; ++it, ++miPos) { - if (rtl::math::isNan(*miPos)) + if (GetDoubleErrorValue(*miPos) == errElementNaN) continue; *miPos = op(*miPos, *it ? 1.0 : 0.0); @@ -1630,7 +1630,7 @@ public: // Empty element is equivalent of having a numeric value of 0.0. for (size_t i = 0; i < node.size; ++i, ++miPos) { - if (rtl::math::isNan(*miPos)) + if (GetDoubleErrorValue(*miPos) == errElementNaN) continue; *miPos = op(*miPos, 0.0); -- cgit