diff options
author | Eike Rathke <erack@redhat.com> | 2013-02-08 11:43:37 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-02-08 11:46:35 +0100 |
commit | df77f67090c722f12d3ae7836acbb908064ff193 (patch) | |
tree | 095359b7adbc302ab4cb821fcbbbfe1f55f0ad97 | |
parent | df931a5b0f48707e34ebfacb695996198ece8f44 (diff) |
factor out common code of SKEW and SKEWP, fdo#60322
Change-Id: Ia79a56f9b68ee11d3a45d30833332c58994383b0
-rw-r--r-- | sc/source/core/inc/interpre.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/interpr3.cxx | 55 |
2 files changed, 19 insertions, 37 deletions
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 64d48bea1914..0d10ab7a89e9 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -682,6 +682,7 @@ void ScSumX2DY2(); void ScSumXMY2(); void ScGrowth(); bool CalculateSkew(double& fSum,double& fCount,double& vSum,std::vector<double>& values); +void CalculateSkewOrSkewp( bool bSkewp ); void CalculateSlopeIntercept(bool bSlope); void CalculateSmallLarge(bool bSmall); void CalculatePearsonCovar(bool _bPearson,bool _bStexy); diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx index df78713f6226..202100ef344f 100644 --- a/sc/source/core/tool/interpr3.cxx +++ b/sc/source/core/tool/interpr3.cxx @@ -3006,20 +3006,21 @@ bool ScInterpreter::CalculateSkew(double& fSum,double& fCount,double& vSum,std:: return true; } -void ScInterpreter::ScSkew() + +void ScInterpreter::CalculateSkewOrSkewp( bool bSkewp ) { - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScSkew" ); - double fSum,fCount,vSum; + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::CalculateSkewOrSkewp" ); + double fSum, fCount, vSum; std::vector<double> values; - if ( !CalculateSkew(fSum,fCount,vSum,values) ) + if (!CalculateSkew( fSum, fCount, vSum, values)) return; double fMean = fSum / fCount; - for (size_t i = 0; i < values.size(); i++) + for (size_t i = 0; i < values.size(); ++i) vSum += (values[i] - fMean) * (values[i] - fMean); - double fStdDev = sqrt(vSum / (fCount - 1.0)); + double fStdDev = sqrt( vSum / (bSkewp ? fCount : (fCount - 1.0))); double dx = 0.0; double xcube = 0.0; @@ -3029,46 +3030,26 @@ void ScInterpreter::ScSkew() return; } - for (size_t i = 0; i < values.size(); i++) + for (size_t i = 0; i < values.size(); ++i) { dx = (values[i] - fMean) / fStdDev; xcube = xcube + (dx * dx * dx); } - PushDouble(((xcube * fCount) / (fCount - 1.0)) / (fCount - 2.0)); + if (bSkewp) + PushDouble( xcube / fCount ); + else + PushDouble( ((xcube * fCount) / (fCount - 1.0)) / (fCount - 2.0) ); } -//fdo#60322 -void ScInterpreter::ScSkewp() +void ScInterpreter::ScSkew() { - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScSkewp" ); - double fSum,fCount,vSum; - std::vector<double> values; - if ( !CalculateSkew( fSum, fCount, vSum, values ) ) - return; - - double fMean = fSum / fCount; - - for ( size_t i = 0; i < values.size(); i++ ) - vSum += ( values[ i ] - fMean ) * ( values[ i ] - fMean ); - - double fStdDevp = sqrt( vSum / fCount ); - double dx = 0.0; - double xcube = 0.0; - - if ( fStdDevp == 0 ) - { - PushIllegalArgument(); - return; - } - - for ( size_t i = 0; i < values.size(); i++ ) - { - dx = ( values[ i ] - fMean ) / fStdDevp; - xcube = xcube + ( dx * dx * dx ); - } + CalculateSkewOrSkewp( false ); +} - PushDouble( xcube / fCount ); +void ScInterpreter::ScSkewp() +{ + CalculateSkewOrSkewp( true ); } double ScInterpreter::GetMedian( vector<double> & rArray ) |