[PATCH] fdo#60322 add calc function SKEWP as in ODFF v1.2

Winfried Donkers (via Code Review) gerrit at gerrit.libreoffice.org
Wed Feb 6 10:09:59 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2020

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/20/2020/1

fdo#60322 add calc function SKEWP as in ODFF v1.2

Change-Id: I4851df1473fc7788af1ac642bb0fb527ec872821
---
M formula/inc/formula/compiler.hrc
M formula/inc/formula/opcode.hxx
M formula/source/core/resource/core_resource.src
M sc/inc/helpids.h
M sc/qa/unit/ucalc.cxx
M sc/source/core/inc/interpre.hxx
M sc/source/core/tool/interpr3.cxx
M sc/source/core/tool/interpr4.cxx
M sc/source/core/tool/parclass.cxx
M sc/source/filter/excel/xlformula.cxx
M sc/source/filter/oox/formulabase.cxx
M sc/source/ui/src/scfuncs.src
12 files changed, 75 insertions(+), 4 deletions(-)



diff --git a/formula/inc/formula/compiler.hrc b/formula/inc/formula/compiler.hrc
index 7f976ae..da27a19 100644
--- a/formula/inc/formula/compiler.hrc
+++ b/formula/inc/formula/compiler.hrc
@@ -398,8 +398,9 @@
 #define SC_OPCODE_SUM_IFS           403
 #define SC_OPCODE_AVERAGE_IFS       404
 #define SC_OPCODE_COUNT_IFS         405
-#define SC_OPCODE_STOP_2_PAR        406
-#define SC_OPCODE_LAST_OPCODE_ID    405     /* last OpCode */
+#define SC_OPCODE_SKEWP             406
+#define SC_OPCODE_STOP_2_PAR        407
+#define SC_OPCODE_LAST_OPCODE_ID    406     /* last OpCode */
 
 /*** Internal ***/
 #define SC_OPCODE_INTERNAL_BEGIN   9999
diff --git a/formula/inc/formula/opcode.hxx b/formula/inc/formula/opcode.hxx
index 007bcd92..b94c066 100644
--- a/formula/inc/formula/opcode.hxx
+++ b/formula/inc/formula/opcode.hxx
@@ -328,6 +328,7 @@
         ocStandard          = SC_OPCODE_STANDARD,
         ocAveDev            = SC_OPCODE_AVE_DEV,
         ocSchiefe           = SC_OPCODE_SCHIEFE,
+        ocSkewp             = SC_OPCODE_SKEWP,
         ocDevSq             = SC_OPCODE_DEV_SQ,
         ocMedian            = SC_OPCODE_MEDIAN,
         ocModalValue        = SC_OPCODE_MODAL_VALUE,
diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src
index f02f806..de8e8d4 100644
--- a/formula/source/core/resource/core_resource.src
+++ b/formula/source/core/resource/core_resource.src
@@ -284,6 +284,7 @@
     String SC_OPCODE_STANDARD { Text = "STANDARDIZE" ; };
     String SC_OPCODE_AVE_DEV { Text = "AVEDEV" ; };
     String SC_OPCODE_SCHIEFE { Text = "SKEW" ; };
+    String SC_OPCODE_SKEWP   { Text = "SKEWP" ; };
     String SC_OPCODE_DEV_SQ { Text = "DEVSQ" ; };
     String SC_OPCODE_MEDIAN { Text = "MEDIAN" ; };
     String SC_OPCODE_MODAL_VALUE { Text = "MODE" ; };
@@ -624,6 +625,7 @@
     String SC_OPCODE_STANDARD { Text = "STANDARDIZE" ; };
     String SC_OPCODE_AVE_DEV { Text = "AVEDEV" ; };
     String SC_OPCODE_SCHIEFE { Text = "SKEW" ; };
+    String SC_OPCODE_SKEWP   { Text = "SKEWP" ; };
     String SC_OPCODE_DEV_SQ { Text = "DEVSQ" ; };
     String SC_OPCODE_MEDIAN { Text = "MEDIAN" ; };
     String SC_OPCODE_MODAL_VALUE { Text = "MODE" ; };
@@ -1675,6 +1677,10 @@
     {
         Text [ en-US ] = "SKEW" ;
     };
+    String SC_OPCODE_SKEWP
+    {
+        Text [ en-US ] = "SKEWP" ;
+    };
     String SC_OPCODE_DEV_SQ
     {
         Text [ en-US ] = "DEVSQ" ;
diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h
index e273ce4..d556337 100644
--- a/sc/inc/helpids.h
+++ b/sc/inc/helpids.h
@@ -530,6 +530,7 @@
 #define HID_FUNC_SUMQUADABW                                     "SC_HID_FUNC_SUMQUADABW"
 #define HID_FUNC_MITTELABW                                      "SC_HID_FUNC_MITTELABW"
 #define HID_FUNC_SCHIEFE                                        "SC_HID_FUNC_SCHIEFE"
+#define HID_FUNC_SKEWP                                          "SC_HID_FUNC_SKEWP"
 #define HID_FUNC_KURT                                           "SC_HID_FUNC_KURT"
 #define HID_FUNC_GEOMITTEL                                      "SC_HID_FUNC_GEOMITTEL"
 #define HID_FUNC_HARMITTEL                                      "SC_HID_FUNC_HARMITTEL"
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ed67ad1..58fde7a 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -4560,6 +4560,7 @@
         "RANK",
         "RSQ",
         "SKEW",
+        "SKEWP",
         "SLOPE",
         "SMALL",
         "STANDARDIZE",
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index cd44780..64d48be 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -762,6 +762,7 @@
 void ScGeoMean();
 void ScStandard();
 void ScSkew();
+void ScSkewp();
 void ScMedian();
 double GetMedian( ::std::vector<double> & rArray );
 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 1b0e85a..df78713 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -3038,6 +3038,39 @@
     PushDouble(((xcube * fCount) / (fCount - 1.0)) / (fCount - 2.0));
 }
 
+//fdo#60322
+void ScInterpreter::ScSkewp()
+{
+    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 );
+    }
+
+    PushDouble( xcube / fCount );
+}
+
 double ScInterpreter::GetMedian( vector<double> & rArray )
 {
     size_t nSize = rArray.size();
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index bc7aa6f..d7df23f 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4110,6 +4110,7 @@
                 case ocDevSq            : ScDevSq();                    break;
                 case ocKurt             : ScKurt();                     break;
                 case ocSchiefe          : ScSkew();                     break;
+                case ocSkewp            : ScSkewp();                    break;
                 case ocModalValue       : ScModalValue();               break;
                 case ocMedian           : ScMedian();                   break;
                 case ocGeoMean          : ScGeoMean();                  break;
diff --git a/sc/source/core/tool/parclass.cxx b/sc/source/core/tool/parclass.cxx
index 6f3cae07..b4187c5 100644
--- a/sc/source/core/tool/parclass.cxx
+++ b/sc/source/core/tool/parclass.cxx
@@ -163,6 +163,7 @@
     { ocRows,            {{ Reference                                            }, 1 }},
     { ocRSQ,             {{ ForceArray, ForceArray                               }, 0 }},
     { ocSchiefe,         {{ Reference                                            }, 1 }},
+    { ocSkewp,           {{ Reference                                            }, 1 }},
     { ocSlope,           {{ ForceArray, ForceArray                               }, 0 }},
     { ocSmall,           {{ Reference, Value                                     }, 0 }},
     { ocStDev,           {{ Reference                                            }, 1 }},
diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx
index 27cbab0..a96b263 100644
--- a/sc/source/filter/excel/xlformula.cxx
+++ b/sc/source/filter/excel/xlformula.cxx
@@ -459,7 +459,7 @@
     EXC_FUNCENTRY_V_VR_IMPORT(  ocSecantHyp,     1,  1,  0,  "SECH" ),
     EXC_FUNCENTRY_V_RO(         ocTable,         0,  1,  0,  "SHEET" ),
     EXC_FUNCENTRY_V_RO(         ocTables,        0,  1,  0,  "SHEETS" ),
-    EXC_FUNCENTRY_V_RX(         ocNoName,        1,  MX, 0,  "SKEW.P" ),
+    EXC_FUNCENTRY_V_RX(         ocSkewp,         1,  MX, 0,  "SKEW.P" ),
     EXC_FUNCENTRY_V_VR(         ocUnichar,       1,  1,  0,  "UNICHAR" ),
     EXC_FUNCENTRY_V_VR(         ocUnicode,       1,  1,  0,  "UNICODE" ),
     EXC_FUNCENTRY_V_VR(         ocNoName,        1,  1,  0,  "WEBSERVICE" ),
diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx
index 623b105..15c045e 100644
--- a/sc/source/filter/oox/formulabase.cxx
+++ b/sc/source/filter/oox/formulabase.cxx
@@ -552,6 +552,7 @@
     { "MODE",                   "MODE",                 330,    330,    1,  MX, V, { VA }, 0 },
     { "TRIMMEAN",               "TRIMMEAN",             331,    331,    2,  2,  V, { RX, VR }, 0 },
     { "TINV",                   "TINV",                 332,    332,    2,  2,  V, { VR }, 0 },
+    { "SKEWP",                  "SKEWP",                333,    333,    1,  MX, V, { RX }, 0 },
 
     // *** Analysis add-in ***
 
@@ -810,7 +811,7 @@
     { "SECH",                   "SECH",                 NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
     { "SHEET",                  "SHEET",                NOID,   NOID,   0,  1,  V, { RO }, FUNCFLAG_MACROCALL_NEW },
     { "SHEETS",                 "SHEETS",               NOID,   NOID,   0,  1,  V, { RO }, FUNCFLAG_MACROCALL_NEW },
-    { 0/*"SKEWP"*/,             "SKEW.P",               NOID,   NOID,   1,  MX, V, { RX }, FUNCFLAG_MACROCALL_NEW },
+    { "SKEWP",                  "SKEW.P",               NOID,   NOID,   1,  MX, V, { RX }, FUNCFLAG_MACROCALL_NEW },
     { "UNICHAR",                "UNICHAR",              NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
     { "UNICODE",                "UNICODE",              NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
     { 0,                        "WEBSERVICE",           NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src
index 5f4c540..433e6fd 100644
--- a/sc/source/ui/src/scfuncs.src
+++ b/sc/source/ui/src/scfuncs.src
@@ -5374,6 +5374,30 @@
             Text [ en-US ] = "Number 1, number 2, ... are 1 to 30 numerical arguments portraying a sample of the distribution." ;
         };
     };
+     // -=*# Resource for function SKEWP #*=-
+    Resource SC_OPCODE_SKEWP
+    {
+        String 1 // Description
+        {
+            Text [ en-US ] = "Returns the skewness of a distribution using the population of a random variable." ;
+        };
+        ExtraData =
+        {
+            0;
+            ID_FUNCTION_GRP_STATISTIC;
+            U2S( HID_FUNC_SKEWP );
+            VAR_ARGS;   0;
+            0;
+        };
+        String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number " ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "Number 1, number 2, ... are 1 to 30 numerical arguments portraying the population." ;
+        };
+    };
      // -=*# Resource for function KURT #*=-
     Resource SC_OPCODE_KURT
     {

-- 
To view, visit https://gerrit.libreoffice.org/2020
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4851df1473fc7788af1ac642bb0fb527ec872821
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Winfried Donkers <osc at dci-electronics.nl>


More information about the LibreOffice mailing list