mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 07:10:40 +01:00
’poincare] Update DivisionQuotient
This commit is contained in:
@@ -50,4 +50,3 @@ public:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class Expression : public TreeByReference {
|
||||
friend class Derivative;
|
||||
friend class Determinant;
|
||||
friend class Division;
|
||||
friend class DivisionQuotient;
|
||||
friend class Sine;
|
||||
friend class Tangent;
|
||||
|
||||
|
||||
@@ -38,27 +38,35 @@ Evaluation<T> DivisionQuotientNode::templatedApproximate(Context& context, Prefe
|
||||
}
|
||||
|
||||
Expression DivisionQuotient::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;
|
||||
}
|
||||
}
|
||||
Expression c0 = childAtIndex(0);
|
||||
Expression c1 = childAtIndex(1);
|
||||
#if MATRIX_EXACT_REDUCING
|
||||
if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) {
|
||||
return Undefined();
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
if (c0.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r0 = static_cast<Rational>(c0);
|
||||
if (!r0.integerDenominator().isOne()) {
|
||||
return Undefined();
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (c1.type() == ExpressionNode::Type::Rational) {
|
||||
Rational r1 = static_cast<Rational>(c1);
|
||||
if (!r1.integerDenominator().isOne()) {
|
||||
return Undefined();
|
||||
Expression result = Undefined();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) {
|
||||
@@ -70,11 +78,15 @@ Expression DivisionQuotient::shallowReduce(Context & context, Preferences::Angle
|
||||
Integer a = r0.signedIntegerNumerator();
|
||||
Integer b = r1.signedIntegerNumerator();
|
||||
if (b.isZero()) {
|
||||
return Infinity(a.isNegative());
|
||||
Expression result = Infinity(a.isNegative());
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
Integer result = Integer::Division(a, b).quotient;
|
||||
assert(!result.isInfinity());
|
||||
return Rational(result);
|
||||
Expression rationalResult = Rational(result);
|
||||
replaceWithInPlace(rationalResult);
|
||||
return rationalResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user