formula/source/core/api/token.cxx | 16 ++++++++++++++++ sc/source/core/inc/interpre.hxx | 3 +-- sc/source/core/tool/interpr3.cxx | 38 ++++++++++---------------------------- sc/source/core/tool/interpr4.cxx | 4 ++-- sc/source/ui/src/scfuncs.src | 10 +++++++++- 5 files changed, 38 insertions(+), 33 deletions(-)
New commits: commit cf43ff5262a111f9fbebe58d254b704ec057cbf6 Author: Winfried Donkers <winfrieddonk...@libreoffice.org> Date: Thu Oct 13 13:49:18 2016 +0200 tdf#102948 Make HYPGEOMDIST ODFF1.2 compliant. Also reduce duplicate code. On Export to OOXML, HYPGEOMDIST is converted to HYPGEOM.DIST. Change-Id: I70a70ee6b5c542e272ef574073ebcd1924f31083 Reviewed-on: https://gerrit.libreoffice.org/29767 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Eike Rathke <er...@redhat.com> diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index 7d5528c..a9abdd0 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -1111,10 +1111,12 @@ inline bool MissingConventionOOXML::isRewriteNeeded( OpCode eOp ) case ocPoissonDist: case ocNormDist: case ocLogNormDist: + case ocHypGeomDist: case ocDBCount: case ocDBCount2: return true; + default: return false; } @@ -1244,6 +1246,14 @@ void FormulaMissingContext::AddMoreArgs( FormulaTokenArray *pNewArr, const Missi } break; + case ocHypGeomDist: + if ( mnCurArg == 3 ) + { + pNewArr->AddOpCode( ocSep ); + pNewArr->AddDouble( 0.0 ); // 5th, Cumulative = false() + } + break; + case ocRound: case ocRoundUp: case ocRoundDown: @@ -1515,6 +1525,12 @@ FormulaTokenArray * FormulaTokenArray::RewriteMissing( const MissingConvention & ( pCur->GetOpCode() == ocCeil ? ocCeil_Math : ocFloor_Math ) ); pNewArr->Add( pToken ); } + else if ( pCur->GetOpCode() == ocHypGeomDist && + rConv.getConvention() == MissingConvention::FORMULA_MISSING_CONVENTION_OOXML ) + { + FormulaToken *pToken = new FormulaToken( svByte, ocHypGeomDist_MS ); + pNewArr->Add( pToken ); + } else pNewArr->AddToken( *pCur ); } diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index fadd474..47d5afd 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -866,8 +866,7 @@ void ScCombinA(); void ScPermut(); void ScPermutationA(); void ScB(); -void ScHypGeomDist(); -void ScHypGeomDist_MS(); +void ScHypGeomDist( int nMinParamCount ); void ScLogNormDist( int nMinParamCount ); void ScLogNormInv(); void ScTDist(); diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx index 18f8e33..04b0343 100644 --- a/sc/source/core/tool/interpr3.cxx +++ b/sc/source/core/tool/interpr3.cxx @@ -1844,39 +1844,21 @@ static void lcl_PutFactorialElements( ::std::vector< double >& cn, double fLower @see #i47296# - */ -void ScInterpreter::ScHypGeomDist() -{ - if ( !MustHaveParamCount( GetByte(), 4 ) ) - return; - - double N = ::rtl::math::approxFloor(GetDouble()); - double M = ::rtl::math::approxFloor(GetDouble()); - 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) ) - { - PushIllegalArgument(); - return; - } - - PushDouble( GetHypGeomDist( x, n, M, N ) ); -} - -/** Calculates a value of the hypergeometric distribution (Excel 2010 function). - - This function has an extra argument bCumulative as compared to ScHypGeomDist(), - which only calculates the non-cumulative distribution. + This function has an extra argument bCumulative, + which only calculates the non-cumulative distribution and + which is optional in Calc and mandatory with Excel's HYPGEOM.DIST() @see fdo#71722 -*/ -void ScInterpreter::ScHypGeomDist_MS() + @see tdf#102948, make Calc function ODFF1.2-compliant + + */ +void ScInterpreter::ScHypGeomDist( int nMinParamCount ) { - if ( !MustHaveParamCount( GetByte(), 5 ) ) + sal_uInt8 nParamCount = GetByte(); + if ( !MustHaveParamCount( nParamCount, nMinParamCount, 5 ) ) return; - bool bCumulative = GetBool(); + bool bCumulative = ( nParamCount == 5 && GetBool() ); double N = ::rtl::math::approxFloor(GetDouble()); double M = ::rtl::math::approxFloor(GetDouble()); double n = ::rtl::math::approxFloor(GetDouble()); diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 6f5c87e..11a8870 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -4209,8 +4209,8 @@ StackVar ScInterpreter::Interpret() case ocCombinA : ScCombinA(); break; case ocPermut : ScPermut(); break; case ocPermutationA : ScPermutationA(); break; - case ocHypGeomDist : ScHypGeomDist(); break; - case ocHypGeomDist_MS : ScHypGeomDist_MS(); break; + case ocHypGeomDist : ScHypGeomDist( 4 ); break; + case ocHypGeomDist_MS : ScHypGeomDist( 5 ); break; case ocLogNormDist : ScLogNormDist( 1 ); break; case ocLogNormDist_MS : ScLogNormDist( 4 ); break; case ocTDist : ScTDist(); break; diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src index cb7b978..84dcc9b 100644 --- a/sc/source/ui/src/scfuncs.src +++ b/sc/source/ui/src/scfuncs.src @@ -8346,7 +8346,7 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 0; ID_FUNCTION_GRP_STATISTIC; HID_FUNC_HYPGEOMVERT; - 4; 0; 0; 0; 0; + 5; 0; 0; 0; 0; 1; 0; }; String 2 // Name of Parameter 1 @@ -8381,6 +8381,14 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 { Text [ en-US ] = "The population size." ; }; + String 10 // Name of Parameter 5 + { + Text [ en-US ] = "Cumulative" ; + }; + String 11 // Description of Parameter 5 + { + Text [ en-US ] = "Cumulated. TRUE calculates the cumulative distribution function, FALSE the probability mass function." ; + }; }; // -=*# Resource for function HYPGEOM.DIST #*=- Resource SC_OPCODE_HYP_GEOM_DIST_MS _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits