mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 07:10:40 +01:00
[poincare] Update DivisionRemainder
This commit is contained in:
@@ -51,4 +51,3 @@ public:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ class Expression : public TreeByReference {
|
||||
friend class Determinant;
|
||||
friend class Division;
|
||||
friend class DivisionQuotient;
|
||||
friend class DivisionRemainder;
|
||||
friend class Sine;
|
||||
friend class Tangent;
|
||||
|
||||
|
||||
@@ -38,9 +38,11 @@ Evaluation<T> DivisionRemainderNode::templatedApproximate(Context& context, Pref
|
||||
return Complex<T>(std::round(f1-f2*std::floor(f1/f2)));
|
||||
}
|
||||
Expression DivisionRemainder::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);
|
||||
@@ -52,13 +54,17 @@ Expression DivisionRemainder::shallowReduce(Context & context, Preferences::Angl
|
||||
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 +76,15 @@ Expression DivisionRemainder::shallowReduce(Context & context, Preferences::Angl
|
||||
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).remainder;
|
||||
assert(!result.isInfinity());
|
||||
return Rational(result);
|
||||
Expression rationalResult = Rational(result);
|
||||
replaceWithInPlace(rationalResult);
|
||||
return rationalResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user