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 <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
This commit is contained in:
parent
d4ddc8cb00
commit
cf43ff5262
5 changed files with 38 additions and 33 deletions
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue