summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2013-10-31 10:33:06 +0100
committerEike Rathke <erack@redhat.com>2013-10-31 16:26:05 +0000
commit6d2f42199c2a9b48c9e19d7ae087f5452bfbd401 (patch)
tree8f43eb34e50fd0d8decb635d033ae62215363355
parente44335abe006d05f0f915279605a03ef084116d6 (diff)
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@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--formula/source/core/resource/core_resource.src12
-rw-r--r--include/formula/compiler.hrc4
-rw-r--r--include/formula/opcode.hxx2
-rw-r--r--sc/inc/helpids.h2
-rw-r--r--sc/qa/unit/ucalc.cxx2
-rw-r--r--sc/source/core/inc/interpre.hxx1
-rw-r--r--sc/source/core/tool/interpr3.cxx61
-rw-r--r--sc/source/core/tool/interpr4.cxx4
-rw-r--r--sc/source/filter/excel/xlformula.cxx4
-rw-r--r--sc/source/filter/oox/formulabase.cxx4
-rw-r--r--sc/source/ui/src/scfuncs.src120
11 files changed, 212 insertions, 4 deletions
diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src
index 3ec56c03bd3b..8f49229eb394 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 b9b4f7a40bb7..d8c45b21989d 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 6dd28d3967ce..5d96e07bc1bf 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 831e2d9acd3f..820086ea31f1 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 90af819d6184..b5de6a5fc5a3 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 bece096acd3d..d5305d1aec31 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 62568eebfb5c..e7b071f88267 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 daa66c6e4c17..97db18c5cc67 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 025827f73926..064d1abf6b3c 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 794deff5d32b..420c1a29e9e4 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 86be3de925ae..0ee26ce4439f 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
{