[Libreoffice-commits] core.git: formula/source include/formula sc/inc sc/qa sc/source

Winfried Donkers winfrieddonkers at libreoffice.org
Thu Oct 31 17:26:27 CET 2013


 formula/source/core/resource/core_resource.src |   12 ++
 include/formula/compiler.hrc                   |    4 
 include/formula/opcode.hxx                     |    2 
 sc/inc/helpids.h                               |    2 
 sc/qa/unit/ucalc.cxx                           |    2 
 sc/source/core/inc/interpre.hxx                |    1 
 sc/source/core/tool/interpr3.cxx               |   61 ++++++++++++
 sc/source/core/tool/interpr4.cxx               |    4 
 sc/source/filter/excel/xlformula.cxx           |    4 
 sc/source/filter/oox/formulabase.cxx           |    4 
 sc/source/ui/src/scfuncs.src                   |  120 +++++++++++++++++++++++++
 11 files changed, 212 insertions(+), 4 deletions(-)

New commits:
commit 6d2f42199c2a9b48c9e19d7ae087f5452bfbd401
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Thu Oct 31 10:33:06 2013 +0100

    fdo#71008 add Excel 2010 functions BETA.DEST and BETA.INV
    
    Change-Id: I65863031cc2795713bf80c17dfc787e2700a556a
    Reviewed-on: https://gerrit.libreoffice.org/6505
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src
index 3ec56c0..8f49229 100644
--- a/formula/source/core/resource/core_resource.src
+++ b/formula/source/core/resource/core_resource.src
@@ -335,6 +335,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF
     String SC_OPCODE_TABLE_OP { Text = "MULTIPLE.OPERATIONS" ; };
     String SC_OPCODE_BETA_DIST { Text = "BETADIST" ; };
     String SC_OPCODE_BETA_INV { Text = "BETAINV" ; };
+    String SC_OPCODE_BETA_DIST_MS { Text = "COM.MICROSOFT.BETA.DIST" ; };
+    String SC_OPCODE_BETA_INV_MS { Text = "COM.MICROSOFT.BETA.INV" ; };
     String SC_OPCODE_WEEK { Text = "ISOWEEKNUM" ; };
     String SC_OPCODE_EASTERSUNDAY { Text = "ORG.OPENOFFICE.EASTERSUNDAY" ; };
     String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
@@ -689,6 +691,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
     String SC_OPCODE_TABLE_OP { Text = "TABLE" ; };
     String SC_OPCODE_BETA_DIST { Text = "BETADIST" ; };
     String SC_OPCODE_BETA_INV { Text = "BETAINV" ; };
+    String SC_OPCODE_BETA_DIST_MS { Text = "BETA.DIST" ; };
+    String SC_OPCODE_BETA_INV_MS { Text = "BETA.INV" ; };
     String SC_OPCODE_WEEK { Text = "WEEKNUM" ; };
     String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; };
     String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
@@ -1904,6 +1908,14 @@ Resource RID_STRLIST_FUNCTION_NAMES
     {
         Text [ en-US ] = "BETAINV" ;
     };
+    String SC_OPCODE_BETA_DIST_MS
+    {
+        Text [ en-US ] = "BETA.DIST" ;
+    };
+    String SC_OPCODE_BETA_INV_MS
+    {
+        Text [ en-US ] = "BETA.INV" ;
+    };
     String SC_OPCODE_WEEK
     {
         Text [ en-US ] = "WEEKNUM" ;
diff --git a/include/formula/compiler.hrc b/include/formula/compiler.hrc
index b9b4f7a..d8c45b2 100644
--- a/include/formula/compiler.hrc
+++ b/include/formula/compiler.hrc
@@ -414,8 +414,10 @@
 #define SC_OPCODE_ST_DEV_S          416
 #define SC_OPCODE_VAR_P_MS          417
 #define SC_OPCODE_VAR_S             418
+#define SC_OPCODE_BETA_DIST_MS      419
+#define SC_OPCODE_BETA_INV_MS       420
 
-#define SC_OPCODE_STOP_2_PAR        419     /* last function with two or more parameters' OpCode + 1 */
+#define SC_OPCODE_STOP_2_PAR        421     /* last function with two or more parameters' OpCode + 1 */
 #define SC_OPCODE_STOP_FUNCTION     SC_OPCODE_STOP_2_PAR            /* last function's OpCode + 1 */
 #define SC_OPCODE_LAST_OPCODE_ID    (SC_OPCODE_STOP_FUNCTION - 1)   /* last OpCode */
 
diff --git a/include/formula/opcode.hxx b/include/formula/opcode.hxx
index 6dd28d3..5d96e07 100644
--- a/include/formula/opcode.hxx
+++ b/include/formula/opcode.hxx
@@ -378,6 +378,8 @@ enum OpCodeEnum
         ocTableOp           = SC_OPCODE_TABLE_OP,
         ocBetaDist          = SC_OPCODE_BETA_DIST,
         ocBetaInv           = SC_OPCODE_BETA_INV,
+        ocBetaDist_MS       = SC_OPCODE_BETA_DIST_MS,
+        ocBetaInv_MS        = SC_OPCODE_BETA_INV_MS,
     // Bit functions
         ocBitAnd            = SC_OPCODE_BITAND,
         ocBitOr             = SC_OPCODE_BITOR,
diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h
index 831e2d9..820086e 100644
--- a/sc/inc/helpids.h
+++ b/sc/inc/helpids.h
@@ -684,5 +684,7 @@
 #define HID_FUNC_ST_DEV_S                                       "SC_HID_FUNC_ST_DEV_S"
 #define HID_FUNC_VAR_P_MS                                       "SC_HID_FUNC_VAR_P_MS"
 #define HID_FUNC_VAR_S                                          "SC_HID_FUNC_VAR_S"
+#define HID_FUNC_BETADIST_MS                                    "SC_HID_FUNC_BETADIST_MS"
+#define HID_FUNC_BETAINV_MS                                     "SC_HID_FUNC_BETAINV_MS"
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 90af819..b5de6a5 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2357,6 +2357,8 @@ void Test::testFunctionLists()
         "AVERAGEIF",
         "AVERAGEIFS",
         "B",
+        "BETA.DIST",
+        "BETA.INV",
         "BETADIST",
         "BETAINV",
         "BINOMDIST",
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index bece096..d5305d1 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -754,6 +754,7 @@ void ScChiSqDist(); // returns left tail or density
 void ScChiSqInv(); //invers to CHISQDIST
 void ScWeibull();
 void ScBetaDist();
+void ScBetaDist_MS();
 void ScFInv();
 void ScTInv();
 void ScChiInv();
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 62568ee..e7b071f 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -1040,6 +1040,67 @@ void ScInterpreter::ScBetaDist()
     }
 }
 
+/**
+  fdo#71008
+  Microsoft version has parameters in different order
+  Also, upper and lowerbound are optional and have default values
+  otherwise, function is identical with ScInterpreter::ScBetaDist()
+*/
+void ScInterpreter::ScBetaDist_MS()
+{
+    sal_uInt8 nParamCount = GetByte();
+    if ( !MustHaveParamCount( nParamCount, 4, 6 ) )
+        return;
+    double fLowerBound, fUpperBound;
+    double alpha, beta, x;
+    bool bIsCumulative;
+    if (nParamCount == 6)
+        fUpperBound = GetDouble();
+    else
+        fUpperBound = 1.0;
+    if (nParamCount >= 4)
+        fLowerBound = GetDouble();
+    else
+        fLowerBound = 0.0;
+    bIsCumulative = GetBool();
+    beta = GetDouble();
+    alpha = GetDouble();
+    x = GetDouble();
+    double fScale = fUpperBound - fLowerBound;
+    if (fScale <= 0.0 || alpha <= 0.0 || beta <= 0.0)
+    {
+        PushIllegalArgument();
+        return;
+    }
+    if (bIsCumulative) // cumulative distribution function
+    {
+        // special cases
+        if (x < fLowerBound)
+        {
+            PushDouble(0.0); return; //see spec
+        }
+        if (x > fUpperBound)
+        {
+            PushDouble(1.0); return; //see spec
+        }
+        // normal cases
+        x = (x-fLowerBound)/fScale;  // convert to standard form
+        PushDouble(GetBetaDist(x, alpha, beta));
+        return;
+    }
+    else // probability density function
+    {
+        if (x < fLowerBound || x > fUpperBound)
+        {
+            PushDouble(0.0);
+            return;
+        }
+        x = (x-fLowerBound)/fScale;
+        PushDouble(GetBetaDistPDF(x, alpha, beta)/fScale);
+        return;
+    }
+}
+
 void ScInterpreter::ScPhi()
 {
     PushDouble(phi(GetDouble()));
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index daa66c6..97db18c 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4167,7 +4167,9 @@ StackVar ScInterpreter::Interpret()
                 case ocFInv             : ScFInv();                     break;
                 case ocLogInv           : ScLogNormInv();               break;
                 case ocBetaDist         : ScBetaDist();                 break;
-                case ocBetaInv          : ScBetaInv();                  break;
+                case ocBetaDist_MS      : ScBetaDist_MS();              break;
+                case ocBetaInv          :
+                case ocBetaInv_MS       : ScBetaInv();                  break;
                 case ocExternal         : ScExternal();                 break;
                 case ocTableOp          : ScTableOp();                  break;
                 case ocStop :                                           break;
diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx
index 025827f..064d1ab 100644
--- a/sc/source/filter/excel/xlformula.cxx
+++ b/sc/source/filter/excel/xlformula.cxx
@@ -412,7 +412,9 @@ static const XclFunctionInfo saFuncTable_2010[] =
     EXC_FUNCENTRY_V_RX(         ocStDevP_MS,     1, MX,  0,  "STDEV.P" ),
     EXC_FUNCENTRY_V_RX(         ocStDevS,        1, MX,  0,  "STDEV.S" ),
     EXC_FUNCENTRY_V_RX(         ocVarP_MS,       1, MX,  0,  "VAR.P" ),
-    EXC_FUNCENTRY_V_RX(         ocVarS,          1, MX,  0,  "VAR.S" )
+    EXC_FUNCENTRY_V_RX(         ocVarS,          1, MX,  0,  "VAR.S" ),
+    EXC_FUNCENTRY_V_VR(         ocBetaDist_MS,   4,  6,  0,  "BETA.DIST" ),
+    EXC_FUNCENTRY_V_VR(         ocBetaInv_MS,    3,  5,  0,  "BETA.INV" )
 };
 
 /** Functions new in Excel 2013.
diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx
index 794deff..420c1a2 100644
--- a/sc/source/filter/oox/formulabase.cxx
+++ b/sc/source/filter/oox/formulabase.cxx
@@ -751,7 +751,9 @@ static const FunctionData saFuncTable2010[] =
     { "COM.MICROSOFT.STDEV.P",                "STDEV.P",             NOID,    NOID,   1, MX,  V, { RX }, FUNCFLAG_MACROCALL_NEW },
     { "COM.MICROSOFT.STDEV.S",                "STDEV.S",             NOID,    NOID,   1, MX,  V, { RX }, FUNCFLAG_MACROCALL_NEW },
     { "COM.MICROSOFT.VAR.P",                  "VAR.P"  ,             NOID,    NOID,   1, MX,  V, { RX }, FUNCFLAG_MACROCALL_NEW },
-    { "COM.MICROSOFT.VAR.S",                  "VAR.S",               NOID,    NOID,   1, MX,  V, { RX }, FUNCFLAG_MACROCALL_NEW }
+    { "COM.MICROSOFT.VAR.S",                  "VAR.S",               NOID,    NOID,   1, MX,  V, { RX }, FUNCFLAG_MACROCALL_NEW },
+    { "COM.MICROSOFT.BETA.DIST",              "BETA.DIST"  ,         NOID,    NOID,   4,  6,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "COM.MICROSOFT.BETA.INV",               "BETA.INV",            NOID,    NOID,   3,  5,  V, { VR }, FUNCFLAG_MACROCALL_NEW }
 };
 
 /** Functions new in Excel 2013.
diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src
index 86be3de..0ee26ce 100644
--- a/sc/source/ui/src/scfuncs.src
+++ b/sc/source/ui/src/scfuncs.src
@@ -6729,6 +6729,126 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2
             Text [ en-US ] = "The final value for the value interval of the distribution." ;
         };
     };
+     // -=*# Resource for function BETA.DIST #*=-
+    Resource SC_OPCODE_BETA_DIST_MS
+    {
+        String 1 // Description
+        {
+            Text [ en-US ] = "Values of the beta distribution." ;
+        };
+        ExtraData =
+        {
+            0;
+            ID_FUNCTION_GRP_STATISTIC;
+            U2S( HID_FUNC_BETADIST_MS );
+            6;  0;  0;  0;  0;  1;  1;
+            0;
+        };
+        String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "The value for which the beta distribution is to be calculated." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+            Text [ en-US ] = "alpha" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "The Alpha parameter of the Beta distribution." ;
+        };
+        String 6 // Name of Parameter 3
+        {
+            Text [ en-US ] = "beta" ;
+        };
+        String 7 // Description of Parameter 3
+        {
+            Text [ en-US ] = "The Beta parameter of the Beta distribution." ;
+        };
+        String 8 // Name of Parameter 4
+        {
+            Text [en-US ] = "Cumulative" ;
+        };
+        String 9 // Description of Parameter 4
+        {
+            Text [ en-US ] = "0 or FALSE for probability density function, any other value or TRUE or omitted for cumulative distribution function.";
+        };
+        String 10 // Name of Parameter 5
+        {
+            Text [ en-US ] = "Start" ;
+        };
+        String 11 // Description of Parameter 5
+        {
+            Text [ en-US ] = "The starting value for the value interval of the distribution." ;
+        };
+        String 12 // Name of Parameter 6
+        {
+            Text [ en-US ] = "End" ;
+        };
+        String 13 // Description of Parameter 6
+        {
+            Text [ en-US ] = "The final value for the value interval of the distribution." ;
+        };
+    };
+     // -=*# Resource for function BETA.INV #*=-
+    Resource SC_OPCODE_BETA_INV_MS
+    {
+        String 1 // Description
+        {
+            Text [ en-US ] = "Values of the inverse beta distribution." ;
+        };
+        ExtraData =
+        {
+            0;
+            ID_FUNCTION_GRP_STATISTIC;
+            U2S( HID_FUNC_BETAINV_MS );
+            5;  0;  0;  0;  1;  1;
+            0;
+        };
+        String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "The probability value for which the inverse beta distribution is to be calculated." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+            Text [ en-US ] = "alpha" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "The Alpha parameter of the Beta distribution." ;
+        };
+        String 6 // Name of Parameter 3
+        {
+            Text [ en-US ] = "beta" ;
+        };
+        String 7 // Description of Parameter 3
+        {
+            Text [ en-US ] = "The Beta parameter of the Beta distribution." ;
+        };
+        String 8 // Name of Parameter 4
+        {
+            Text [ en-US ] = "Start" ;
+        };
+        String 9 // Description of Parameter 4
+        {
+            Text [ en-US ] = "The starting value for the value interval of the distribution." ;
+        };
+        String 10 // Name of Parameter 5
+        {
+            Text [ en-US ] = "End" ;
+        };
+        String 11 // Description of Parameter 5
+        {
+            Text [ en-US ] = "The final value for the value interval of the distribution." ;
+        };
+    };
      // -=*# Resource for function WEIBULL #*=-
     Resource SC_OPCODE_WEIBULL
     {


More information about the Libreoffice-commits mailing list