Hallo,
I made a mistake, to commit before testing. Therefore are 2 patch-files.
Please, can anybody test this extension.
Greetings
Wolfgang
From 18dddf4faa96a12e254e3f5c0fe4c8451a61601c Mon Sep 17 00:00:00 2001
From: Wolfgang Pechlaner <libo@pechlaner.at>
Date: Wed, 21 Sep 2011 19:30:41 +0200
Subject: [PATCH 1/2] fdo# 40835, 4th parameter for FDIST
---
sc/source/core/inc/interpre.hxx | 1 +
sc/source/core/tool/interpr3.cxx | 24 +++++++++++++++++++++---
sc/source/ui/src/scfuncs.src | 10 +++++++++-
3 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index a693f58..5dbbb94 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -716,6 +716,7 @@ double GetChiDist(double fChi, double fDF); // for LEGACY.CHIDIST, returns r
double GetChiSqDistCDF(double fX, double fDF); // for CHISQDIST, returns left tail
double GetChiSqDistPDF(double fX, double fDF); // probability density function
double GetFDist(double x, double fF1, double fF2);
+double GetFDistPDF(double x, double fF1, double fF2);
double GetTDist(double T, double fDF);
double Fakultaet(double x);
double BinomKoeff(double n, double k);
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 728faea..beca279 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -645,13 +645,22 @@ double ScInterpreter::GetLogGamma(double fZ)
double ScInterpreter::GetFDist(double x, double fF1, double fF2)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetFDist" );
+ RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetFDistPDF" );
double arg = fF2/(fF2+fF1*x);
double alpha = fF2/2.0;
double beta = fF1/2.0;
return (GetBetaDist(arg, alpha, beta));
}
+double ScInterpreter::GetFDistPDF(double x, double fF1, double fF2)
+{
+ RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetFDistPDF" );
+ double arg = fF2/(fF2+fF1*x);
+ double alpha = fF2/2.0;
+ double beta = fF1/2.0;
+ return (GetBetaDistPDF(arg, alpha, beta));
+}
+
double ScInterpreter::GetTDist(double T, double fDF)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetTDist" );
@@ -1558,8 +1567,10 @@ void ScInterpreter::ScTDist()
void ScInterpreter::ScFDist()
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScFDist" );
- if ( !MustHaveParamCount( GetByte(), 3 ) )
+ sal_uInt8 nParamCount = GetByte();
+ if ( !MustHaveParamCount( nParamCount, 3, 4))
return;
+ bool bCumulative = nParamCount == 4 ? GetBool() : true;
double fF2 = ::rtl::math::approxFloor(GetDouble());
double fF1 = ::rtl::math::approxFloor(GetDouble());
double fF = GetDouble();
@@ -1568,7 +1579,14 @@ void ScInterpreter::ScFDist()
PushIllegalArgument();
return;
}
- PushDouble(GetFDist(fF, fF1, fF2));
+ if (bCumulative)
+ {
+ PushDouble(GetFDist(fF, fF1, fF2));
+ }
+ else
+ {
+ PushDouble(GetFDistPDF(fF, fF1, fF2));
+ }
}
void ScInterpreter::ScChiDist()
diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src
index 8f8bb04..d4e781d 100644
--- a/sc/source/ui/src/scfuncs.src
+++ b/sc/source/ui/src/scfuncs.src
@@ -6406,7 +6406,7 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2
0;
ID_FUNCTION_GRP_STATISTIC;
U2S( HID_FUNC_FVERT );
- 3; 0; 0; 0;
+ 4; 0; 0; 0; 1;
0;
};
String 2 // Name of Parameter 1
@@ -6433,6 +6433,14 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2
{
Text [ en-US ] = "The degrees of freedom in the denominator of the F 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.";
+ };
};
// -=*# Resource for function FINV #*=-
Resource SC_OPCODE_F_INV
--
1.7.3.4
From 9bc05a400c28981786cd2282f546cee87115c7cc Mon Sep 17 00:00:00 2001
From: Wolfgang Pechlaner <libo@pechlaner.at>
Date: Sat, 24 Sep 2011 21:31:20 +0200
Subject: [PATCH 2/2] fdo# 40835, 4th parameter for FDIST
---
sc/source/core/tool/interpr3.cxx | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index beca279..adcc7a9 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -645,7 +645,7 @@ double ScInterpreter::GetLogGamma(double fZ)
double ScInterpreter::GetFDist(double x, double fF1, double fF2)
{
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetFDistPDF" );
+ RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetFDist" );
double arg = fF2/(fF2+fF1*x);
double alpha = fF2/2.0;
double beta = fF1/2.0;
@@ -655,10 +655,13 @@ double ScInterpreter::GetFDist(double x, double fF1, double fF2)
double ScInterpreter::GetFDistPDF(double x, double fF1, double fF2)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetFDistPDF" );
- double arg = fF2/(fF2+fF1*x);
- double alpha = fF2/2.0;
- double beta = fF1/2.0;
- return (GetBetaDistPDF(arg, alpha, beta));
+ if (x == 0 && fF1 == 1)
+ {
+ SetError(errIllegalArgument);
+ return HUGE_VAL;
+ }
+ double prefix = (1.0 /GetBeta(fF1 / 2.0, fF2 / 2.0)) * pow(fF1 / fF2, fF1/2);
+ return prefix * pow(x, fF1/2 -1) / pow(1.0 + fF1/fF2 * x, (fF1 + fF2) / 2);
}
double ScInterpreter::GetTDist(double T, double fDF)
--
1.7.3.4
Context
- [Libreoffice] [PATCH] fdo# 40835 4th Parameter in FDIST · Wolfgang Pechlaner
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.