diff options
author | Eike Rathke <erack@redhat.com> | 2016-07-08 20:22:50 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-07-08 20:26:57 +0200 |
commit | 1e0f1b62c3162b858a331ebf823b5c1b61a4cf4e (patch) | |
tree | e64ef07825375c810922f3db961deb37a753ef4a /sc | |
parent | b9c9bf666b4eb7ee4568fe155a2c8b50a02c4ad5 (diff) |
GetStVarParams: unnecessary to count if we have a size anyway
... and streamline the error handling.
Change-Id: Idbae0487aa7052aa39cb1dd8cb8d0072aef3c90c
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 2b117cdcce60..156da0f9b12e 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -3611,8 +3611,7 @@ void ScInterpreter::ScMax( bool bTextAsZero ) PushDouble(nMax); } -void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, - bool bTextAsZero ) +void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, bool bTextAsZero ) { short nParamCount = GetByte(); @@ -3625,18 +3624,18 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, ScAddress aAdr; ScRange aRange; size_t nRefInList = 0; - while (nParamCount-- > 0) + while (!nGlobalError && nParamCount-- > 0) { switch (GetStackType()) { case svDouble : { fVal = GetDouble(); - if ( nGlobalError ) - return; - values.push_back(fVal); - fSum += fVal; - rValCount++; + if (!nGlobalError) + { + values.push_back(fVal); + fSum += fVal; + } } break; case svSingleRef : @@ -3646,16 +3645,15 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, if (aCell.hasNumeric()) { fVal = GetCellValue(aAdr, aCell); - if ( nGlobalError ) - return; - values.push_back(fVal); - fSum += fVal; - rValCount++; + if (!nGlobalError) + { + values.push_back(fVal); + fSum += fVal; + } } else if (bTextAsZero && aCell.hasString()) { values.push_back(0.0); - rValCount++; } } break; @@ -3671,14 +3669,12 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, { values.push_back(fVal); fSum += fVal; - rValCount++; } while ((nErr == 0) && aValIter.GetNext(fVal, nErr)); } if ( nErr ) { SetError(nErr); - return; } } break; @@ -3696,14 +3692,15 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, if (!pMat->IsString(nMatCol,nMatRow)) { fVal= pMat->GetDouble(nMatCol,nMatRow); - values.push_back(fVal); - fSum += fVal; - rValCount++; + if (!nGlobalError) + { + values.push_back(fVal); + fSum += fVal; + } } else if ( bTextAsZero ) { values.push_back(0.0); - rValCount++; } } } @@ -3716,7 +3713,6 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, if ( bTextAsZero ) { values.push_back(0.0); - rValCount++; } else SetError(errIllegalParameter); @@ -3729,9 +3725,15 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, } ::std::vector<double>::size_type n = values.size(); - vMean = fSum / n; - for (::std::vector<double>::size_type i = 0; i < n; i++) - vSum += ::rtl::math::approxSub( values[i], vMean) * ::rtl::math::approxSub( values[i], vMean); + rValCount = n; + if (!n) + SetError( errDivisionByZero); + if (!nGlobalError) + { + vMean = fSum / n; + for (::std::vector<double>::size_type i = 0; i < n; i++) + vSum += ::rtl::math::approxSub( values[i], vMean) * ::rtl::math::approxSub( values[i], vMean); + } rVal = vSum; } |