mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 01:00:50 +01:00
[poincare/normal_distribution_function] Factorize code in parent class
This commit is contained in:
41
poincare/src/normal_distribution_function.cpp
Normal file
41
poincare/src/normal_distribution_function.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user