[poincare/normal_distribution_function] Factorize code in parent class

This commit is contained in:
Léa Saviot
2019-08-26 10:44:19 +02:00
parent ff0105182d
commit 5c443e0412
12 changed files with 89 additions and 136 deletions

View File

@@ -0,0 +1,41 @@
#include <poincare/normal_distribution_function.h>
#include <poincare/normal_distribution.h>
#include <assert.h>
namespace Poincare {
Expression NormalDistributionFunctionNode::shallowReduce(ReductionContext reductionContext) {
return NormalDistributionFunction(this).shallowReduce(reductionContext.context());
}
Expression NormalDistributionFunction::shallowReduce(Context * context, bool * stopReduction) {
if (stopReduction != nullptr) {
*stopReduction = true;
}
{
Expression e = Expression::defaultShallowReduce();
if (e.isUndefined()) {
return e;
}
}
Expression mu = childAtIndex(1);
Expression var = childAtIndex(2);
// Check mu and var
bool muAndVarOK = false;
bool couldCheckMuAndVar = NormalDistribution::ExpressionParametersAreOK(&muAndVarOK, mu, var, context);
if (!couldCheckMuAndVar) {
return *this;
}
if (!muAndVarOK) {
return replaceWithUndefinedInPlace();
}
if (stopReduction != nullptr) {
*stopReduction = false;
}
return *this;
}
}