[Libreoffice-commits] core.git: sc/source

Eike Rathke erack at redhat.com
Mon May 22 12:44:52 UTC 2017


 sc/source/core/inc/interpre.hxx  |    2 -
 sc/source/core/tool/interpr1.cxx |   61 +++++++++++++++++++--------------------
 sc/source/core/tool/interpr3.cxx |    9 +++--
 3 files changed, 37 insertions(+), 35 deletions(-)

New commits:
commit 2ab771e0acd54ee164075f71fc4701f7b7cc3d06
Author: Eike Rathke <erack at redhat.com>
Date:   Mon May 22 14:44:00 2017 +0200

    Move result token push into GetStVarParams(), tdf#58874
    
    Change-Id: If38637f2dcaf0457e95444a9d46636d91def4f9c

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 6936cb210394..29cb26c05220 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -582,7 +582,7 @@ void ScProduct();
 void ScAverage( bool bTextAsZero = false );
 void ScCount();
 void ScCount2();
-void GetStVarParams( double& rVal, double& rValCount, bool bTextAsZero );
+void GetStVarParams( bool bTextAsZero, double(*VarResult)( double fVal, size_t nValCount ) );
 void ScVar( bool bTextAsZero = false );
 void ScVarP( bool bTextAsZero = false );
 void ScStDev( bool bTextAsZero = false );
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index f455cb43dccf..23f599e45a2d 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -3782,7 +3782,7 @@ void ScInterpreter::ScMax( bool bTextAsZero )
     }
 }
 
-void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, bool bTextAsZero )
+void ScInterpreter::GetStVarParams( bool bTextAsZero, double(*VarResult)( double fVal, size_t nValCount ) )
 {
     short nParamCount = GetByte();
 
@@ -3790,7 +3790,6 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, bool bTextA
     double fSum    = 0.0;
     double vSum    = 0.0;
     double fVal = 0.0;
-    rValCount = 0.0;
     ScAddress aAdr;
     ScRange aRange;
     size_t nRefInList = 0;
@@ -3895,7 +3894,6 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, bool bTextA
     }
 
     ::std::vector<double>::size_type n = values.size();
-    rValCount = n;
     if (!n)
         SetError( FormulaError::DivisionByZero);
     if (nGlobalError == FormulaError::NONE)
@@ -3904,50 +3902,53 @@ void ScInterpreter::GetStVarParams( double& rVal, double& rValCount, bool bTextA
         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;
+    PushDouble( VarResult( vSum, n));
 }
 
 void ScInterpreter::ScVar( bool bTextAsZero )
 {
-    double nVal;
-    double nValCount;
-    GetStVarParams( nVal, nValCount, bTextAsZero );
-
-    if (nValCount <= 1.0)
-        PushError( FormulaError::DivisionByZero );
-    else
-        PushDouble( nVal / (nValCount - 1.0));
+    auto VarResult = []( double fVal, size_t nValCount )
+    {
+        if (nValCount <= 1)
+            return CreateDoubleError( FormulaError::DivisionByZero );
+        else
+            return fVal / (nValCount - 1);
+    };
+    GetStVarParams( bTextAsZero, VarResult );
 }
 
 void ScInterpreter::ScVarP( bool bTextAsZero )
 {
-    double nVal;
-    double nValCount;
-    GetStVarParams( nVal, nValCount, bTextAsZero );
+    auto VarResult = []( double fVal, size_t nValCount )
+    {
+        return sc::div( fVal, nValCount);
+    };
+    GetStVarParams( bTextAsZero, VarResult );
 
-    PushDouble( div( nVal, nValCount));
 }
 
 void ScInterpreter::ScStDev( bool bTextAsZero )
 {
-    double nVal;
-    double nValCount;
-    GetStVarParams( nVal, nValCount, bTextAsZero );
-    if (nValCount <= 1.0)
-        PushError( FormulaError::DivisionByZero );
-    else
-        PushDouble( sqrt( nVal / (nValCount - 1.0)));
+    auto VarResult = []( double fVal, size_t nValCount )
+    {
+        if (nValCount <= 1)
+            return CreateDoubleError( FormulaError::DivisionByZero );
+        else
+            return sqrt( fVal / (nValCount - 1));
+    };
+    GetStVarParams( bTextAsZero, VarResult );
 }
 
 void ScInterpreter::ScStDevP( bool bTextAsZero )
 {
-    double nVal;
-    double nValCount;
-    GetStVarParams( nVal, nValCount, bTextAsZero );
-    if (nValCount == 0.0)
-        PushError( FormulaError::DivisionByZero );
-    else
-        PushDouble( sqrt( nVal / nValCount));
+    auto VarResult = []( double fVal, size_t nValCount )
+    {
+        if (nValCount == 0)
+            return CreateDoubleError( FormulaError::DivisionByZero );
+        else
+            return sqrt( fVal / nValCount);
+    };
+    GetStVarParams( bTextAsZero, VarResult );
 
     /* this was: PushDouble( sqrt( div( nVal, nValCount)));
      *
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index b725eeb2631a..9c7ce4921db5 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -4089,10 +4089,11 @@ void ScInterpreter::ScAveDev()
 
 void ScInterpreter::ScDevSq()
 {
-    double nVal;
-    double nValCount;
-    GetStVarParams(nVal, nValCount, false /*bTextAsZero*/);
-    PushDouble(nVal);
+    auto VarResult = []( double fVal, size_t /*nValCount*/ )
+    {
+        return fVal;
+    };
+    GetStVarParams( false /*bTextAsZero*/, VarResult);
 }
 
 void ScInterpreter::ScProbability()


More information about the Libreoffice-commits mailing list