mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 07:10:40 +01:00
[poincare] Update Factorial
This commit is contained in:
@@ -32,6 +32,7 @@ class Expression : public TreeByReference {
|
||||
friend class DivisionRemainder;
|
||||
friend class Equal;
|
||||
friend class Factor;
|
||||
friend class Factorial;
|
||||
|
||||
friend class Sine;
|
||||
friend class Store;
|
||||
|
||||
@@ -81,9 +81,11 @@ int FactorialNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl
|
||||
}
|
||||
|
||||
Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
if (e.isUndefinedOrAllocationFailure()) {
|
||||
return e;
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
if (e.isUndefinedOrAllocationFailure()) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
#if MATRIX_EXACT_REDUCING
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) {
|
||||
@@ -93,19 +95,24 @@ Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit an
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Rational) {
|
||||
Rational r = static_cast<Rational>(childAtIndex(0));
|
||||
if (!r.integerDenominator().isOne() || r.sign() == ExpressionNode::Sign::Negative) {
|
||||
return Undefined();
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
if (Integer(k_maxOperandValue).isLowerThan(r.unsignedIntegerNumerator())) {
|
||||
return *this;
|
||||
}
|
||||
Rational fact = Rational(Integer::Factorial(r.unsignedIntegerNumerator()));
|
||||
assert(!fact.numeratorOrDenominatorIsInfinity()); // because fact < k_maxOperandValue!
|
||||
replaceWithInPlace(fact);
|
||||
return fact;
|
||||
}
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Symbol) {
|
||||
Symbol s = static_cast<Symbol>(childAtIndex(0));
|
||||
if (s.name() == Ion::Charset::SmallPi || s.name() == Ion::Charset::Exponential) {
|
||||
return Undefined();
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
@@ -117,7 +124,9 @@ Expression Factorial::shallowBeautify(Context & context, Preferences::AngleUnit
|
||||
|| childAtIndex(0).type() == ExpressionNode::Type::Multiplication
|
||||
|| childAtIndex(0).type() == ExpressionNode::Type::Power)
|
||||
{
|
||||
return Factorial(Parenthesis(childAtIndex(0)));
|
||||
Expression result = Factorial(Parenthesis(childAtIndex(0)));
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user