summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2018-04-20 21:23:08 +0200
committerEike Rathke <erack@redhat.com>2018-04-25 21:59:14 +0200
commite58b3f987681d0034f692db82345af06de217836 (patch)
tree5aa5b7215c6b8a4751e5e7de9614aa215e8a3d43
parent1341cefdff68c508941cdda23e5df75c70ea31b4 (diff)
tdf#117041 implement note at end of ODFF1.2 par. 6.18.37
And avoid double code by putting the non-cumulative calculation in the loop as well. Change-Id: I8538582e7d33370f5e44382924b9e3e89efa28dd Reviewed-on: https://gerrit.libreoffice.org/53221 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/qa/unit/data/functions/statistical/fods/hypgeomdist.fods73
-rw-r--r--sc/source/core/tool/interpr3.cxx20
2 files changed, 71 insertions, 22 deletions
diff --git a/sc/qa/unit/data/functions/statistical/fods/hypgeomdist.fods b/sc/qa/unit/data/functions/statistical/fods/hypgeomdist.fods
index 668562200ee5..86e67be89a36 100644
--- a/sc/qa/unit/data/functions/statistical/fods/hypgeomdist.fods
+++ b/sc/qa/unit/data/functions/statistical/fods/hypgeomdist.fods
@@ -4385,11 +4385,22 @@
<table:table-cell table:number-columns-repeated="2"/>
</table:table-row>
<table:table-row table:style-name="ro9">
- <table:table-cell table:style-name="ce10"/>
- <table:table-cell/>
- <table:table-cell table:style-name="ce16"/>
- <table:table-cell table:style-name="ce21"/>
- <table:table-cell table:number-columns-repeated="17"/>
+ <table:table-cell table:style-name="ce10" table:formula="of:=HYPGEOMDIST(53;55;269;300;1)" office:value-type="float" office:value="0.988500551352757" calcext:value-type="float">
+ <text:p>0.988500551352757</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="float" office:value="0.988500551352757" calcext:value-type="float">
+ <text:p>0.988500551352757</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce54" table:formula="of:=ROUND([.A31];12)=ROUND([.B31];12)" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce21" table:formula="of:=FORMULA([.A31])" office:value-type="string" office:string-value="=HYPGEOMDIST(53,55,269,300,1)" calcext:value-type="string">
+ <text:p>=HYPGEOMDIST(53,55,269,300,1)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>tdf117041</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="16"/>
<table:table-cell table:style-name="ce33"/>
<table:table-cell table:style-name="ce35" table:number-columns-repeated="2"/>
<table:table-cell table:number-columns-repeated="3"/>
@@ -4399,12 +4410,52 @@
<table:table-cell table:style-name="ce37"/>
<table:table-cell table:number-columns-repeated="2"/>
</table:table-row>
- <table:table-row table:style-name="ro9" table:number-rows-repeated="2">
- <table:table-cell table:style-name="ce10"/>
+ <table:table-row table:style-name="ro9">
+ <table:table-cell table:style-name="ce10" table:formula="of:=HYPGEOMDIST(34;36;89;100;1)" office:value-type="float" office:value="0.95624768719555" calcext:value-type="float">
+ <text:p>0.95624768719555</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="float" office:value="0.95624768719555" calcext:value-type="float">
+ <text:p>0.95624768719555</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce54" table:formula="of:=ROUND([.A32];12)=ROUND([.B32];12)" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce21" table:formula="of:=FORMULA([.A32])" office:value-type="string" office:string-value="=HYPGEOMDIST(34,36,89,100,1)" calcext:value-type="string">
+ <text:p>=HYPGEOMDIST(34,36,89,100,1)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>tdf117041</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="16"/>
+ <table:table-cell table:style-name="ce33"/>
+ <table:table-cell table:style-name="ce35"/>
+ <table:table-cell table:style-name="ce26"/>
+ <table:table-cell/>
+ <table:table-cell table:style-name="ce36"/>
<table:table-cell/>
- <table:table-cell table:style-name="ce16"/>
- <table:table-cell table:style-name="ce21"/>
- <table:table-cell table:number-columns-repeated="17"/>
+ <table:table-cell table:style-name="ce26" table:number-columns-repeated="2"/>
+ <table:table-cell table:number-columns-repeated="2"/>
+ <table:table-cell table:style-name="ce36"/>
+ <table:table-cell table:style-name="ce37"/>
+ <table:table-cell table:number-columns-repeated="2"/>
+ </table:table-row>
+ <table:table-row table:style-name="ro9">
+ <table:table-cell table:style-name="ce10" table:formula="of:=HYPGEOMDIST(24;36;89;100)" office:value-type="float" office:value="0" calcext:value-type="float">
+ <text:p>0</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="float" office:value="0" calcext:value-type="float">
+ <text:p>0</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce54" table:formula="of:=ROUND([.A33];12)=ROUND([.B33];12)" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce21" table:formula="of:=FORMULA([.A33])" office:value-type="string" office:string-value="=HYPGEOMDIST(24,36,89,100)" calcext:value-type="string">
+ <text:p>=HYPGEOMDIST(24,36,89,100)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>tdf117041</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="16"/>
<table:table-cell table:style-name="ce33"/>
<table:table-cell table:style-name="ce35"/>
<table:table-cell table:style-name="ce26"/>
@@ -5084,4 +5135,4 @@
</table:named-expressions>
</office:spreadsheet>
</office:body>
-</office:document> \ No newline at end of file
+</office:document>
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 46328e5d8009..2a9535e31c8d 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -1844,7 +1844,7 @@ static void lcl_PutFactorialElements( ::std::vector< double >& cn, double fLower
@see fdo#71722
@see tdf#102948, make Calc function ODFF1.2-compliant
-
+ @see tdf#117041, implement note at bottom of ODFF1.2 par.6.18.37
*/
void ScInterpreter::ScHypGeomDist( int nMinParamCount )
{
@@ -1858,23 +1858,21 @@ void ScInterpreter::ScHypGeomDist( int nMinParamCount )
double n = ::rtl::math::approxFloor(GetDouble());
double x = ::rtl::math::approxFloor(GetDouble());
- if( (x < 0.0) || (n < x) || (M < x) || (N < n) || (N < M) || (x < n - N + M) )
+ if ( (x < 0.0) || (n < x) || (N < n) || (N < M) || (M < 0.0) )
{
PushIllegalArgument();
return;
}
- if ( bCumulative )
- {
- double fVal = 0.0;
-
- for ( int i = 0; i <= x && nGlobalError == FormulaError::NONE; i++ )
- fVal += GetHypGeomDist( i, n, M, N );
+ double fVal = 0.0;
- PushDouble( fVal );
+ for ( int i = ( bCumulative ? 0 : x ); i <= x && nGlobalError == FormulaError::NONE; i++ )
+ {
+ if ( (i >= n - N + M) || (i >= M) )
+ fVal += GetHypGeomDist( i, n, M, N );
}
- else
- PushDouble( GetHypGeomDist( x, n, M, N ) );
+
+ PushDouble( fVal );
}
/** Calculates a value of the hypergeometric distribution.