tdf104532 handle constraints for NEGBINOM.DIST correctly.

Also changed variable names for easier understanding of their meaning.

Change-Id: Iab558d7d1d9533f2a0c42e3d5f4acecead2e818e
Reviewed-on: https://gerrit.libreoffice.org/31807
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
This commit is contained in:
Winfried Donkers
2016-12-09 17:26:17 +01:00
committed by Eike Rathke
parent ae9b514453
commit ccbb0dd878

View File

@@ -1514,21 +1514,21 @@ void ScInterpreter::ScNegBinomDist_MS()
if ( MustHaveParamCount( GetByte(), 4 ) ) if ( MustHaveParamCount( GetByte(), 4 ) )
{ {
bool bCumulative = GetBool(); bool bCumulative = GetBool();
double p = GetDouble(); // p double p = GetDouble(); // probability
double r = GetDouble(); // r double s = ::rtl::math::approxFloor(GetDouble()); // No of successes
double x = GetDouble(); // x double f = ::rtl::math::approxFloor(GetDouble()); // No of failures
if ( r < 0.0 || x < 0.0 || p < 0.0 || p > 1.0 ) if ( s < 1.0 || f < 0.0 || p < 0.0 || p > 1.0 )
PushIllegalArgument(); PushIllegalArgument();
else else
{ {
double q = 1.0 - p; double q = 1.0 - p;
if ( bCumulative ) if ( bCumulative )
PushDouble( 1.0 - GetBetaDist( q, x + 1, r ) ); PushDouble( 1.0 - GetBetaDist( q, f + 1, s ) );
else else
{ {
double fFactor = pow( p, r ); double fFactor = pow( p, s );
for ( double i = 0.0; i < x; i++ ) for ( double i = 0.0; i < f; i++ )
fFactor *= ( i + r ) / ( i + 1.0 ) * q; fFactor *= ( i + s ) / ( i + 1.0 ) * q;
PushDouble( fFactor ); PushDouble( fFactor );
} }
} }