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

Winfried Donkers winfrieddonkers at libreoffice.org
Wed Apr 25 20:00:16 UTC 2018


 sc/qa/unit/data/functions/statistical/fods/hypgeomdist.fods |   73 ++++++++++--
 sc/source/core/tool/interpr3.cxx                            |   20 +--
 2 files changed, 71 insertions(+), 22 deletions(-)

New commits:
commit e58b3f987681d0034f692db82345af06de217836
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Fri Apr 20 21:23:08 2018 +0200

    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 at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

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.


More information about the Libreoffice-commits mailing list