Kaydet (Commit) e58b3f98 authored tarafından Winfried Donkers's avatar Winfried Donkers Kaydeden (comit) Eike Rathke

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/53221Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Tested-by: 's avatarEike Rathke <erack@redhat.com>
üst 1341cefd
...@@ -4385,11 +4385,22 @@ ...@@ -4385,11 +4385,22 @@
<table:table-cell table:number-columns-repeated="2"/> <table:table-cell table:number-columns-repeated="2"/>
</table:table-row> </table:table-row>
<table:table-row table:style-name="ro9"> <table:table-row table:style-name="ro9">
<table:table-cell table:style-name="ce10"/> <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">
<table:table-cell/> <text:p>0.988500551352757</text:p>
<table:table-cell table:style-name="ce16"/> </table:table-cell>
<table:table-cell table:style-name="ce21"/> <table:table-cell office:value-type="float" office:value="0.988500551352757" calcext:value-type="float">
<table:table-cell table:number-columns-repeated="17"/> <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="ce33"/>
<table:table-cell table:style-name="ce35" table:number-columns-repeated="2"/> <table:table-cell table:style-name="ce35" table:number-columns-repeated="2"/>
<table:table-cell table:number-columns-repeated="3"/> <table:table-cell table:number-columns-repeated="3"/>
...@@ -4399,12 +4410,52 @@ ...@@ -4399,12 +4410,52 @@
<table:table-cell table:style-name="ce37"/> <table:table-cell table:style-name="ce37"/>
<table:table-cell table:number-columns-repeated="2"/> <table:table-cell table:number-columns-repeated="2"/>
</table:table-row> </table:table-row>
<table:table-row table:style-name="ro9" table:number-rows-repeated="2"> <table:table-row table:style-name="ro9">
<table:table-cell table:style-name="ce10"/> <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:table-cell table:style-name="ce16"/> <table:table-cell table:style-name="ce26" table:number-columns-repeated="2"/>
<table:table-cell table:style-name="ce21"/> <table:table-cell table:number-columns-repeated="2"/>
<table:table-cell table:number-columns-repeated="17"/> <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="ce33"/>
<table:table-cell table:style-name="ce35"/> <table:table-cell table:style-name="ce35"/>
<table:table-cell table:style-name="ce26"/> <table:table-cell table:style-name="ce26"/>
...@@ -5084,4 +5135,4 @@ ...@@ -5084,4 +5135,4 @@
</table:named-expressions> </table:named-expressions>
</office:spreadsheet> </office:spreadsheet>
</office:body> </office:body>
</office:document> </office:document>
\ No newline at end of file
...@@ -1844,7 +1844,7 @@ static void lcl_PutFactorialElements( ::std::vector< double >& cn, double fLower ...@@ -1844,7 +1844,7 @@ static void lcl_PutFactorialElements( ::std::vector< double >& cn, double fLower
@see fdo#71722 @see fdo#71722
@see tdf#102948, make Calc function ODFF1.2-compliant @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 ) void ScInterpreter::ScHypGeomDist( int nMinParamCount )
{ {
...@@ -1858,23 +1858,21 @@ void ScInterpreter::ScHypGeomDist( int nMinParamCount ) ...@@ -1858,23 +1858,21 @@ void ScInterpreter::ScHypGeomDist( int nMinParamCount )
double n = ::rtl::math::approxFloor(GetDouble()); double n = ::rtl::math::approxFloor(GetDouble());
double x = ::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(); PushIllegalArgument();
return; return;
} }
if ( bCumulative ) double fVal = 0.0;
{
double fVal = 0.0;
for ( int i = 0; i <= x && nGlobalError == FormulaError::NONE; i++ )
fVal += GetHypGeomDist( i, n, M, N );
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. /** Calculates a value of the hypergeometric distribution.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment