mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 09:17:23 +01:00
[poincare] DivisionQuotient, DivisionRemainder: add method to reduce on
Integers
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define POINCARE_DIVISION_QUOTIENT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/integer.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -44,6 +45,7 @@ public:
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context * context);
|
||||
static Expression Reduce(const Integer & a, const Integer & b);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <poincare/approximation_helper.h>
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/integer.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -46,6 +47,7 @@ public:
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context * context);
|
||||
static Expression Reduce(const Integer & a, const Integer & b);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -68,16 +68,18 @@ Expression DivisionQuotient::shallowReduce(Context * context) {
|
||||
|
||||
Integer a = r0.signedIntegerNumerator();
|
||||
Integer b = r1.signedIntegerNumerator();
|
||||
Expression result = Reduce(a, b);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression DivisionQuotient::Reduce(const Integer & a, const Integer & b) {
|
||||
if (b.isZero()) {
|
||||
Expression result = Infinity::Builder(a.isNegative());
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return Infinity::Builder(a.isNegative());
|
||||
}
|
||||
Integer result = Integer::Division(a, b).quotient;
|
||||
assert(!result.isOverflow());
|
||||
Expression rationalResult = Rational::Builder(result);
|
||||
replaceWithInPlace(rationalResult);
|
||||
return rationalResult;
|
||||
return Rational::Builder(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,16 +69,18 @@ Expression DivisionRemainder::shallowReduce(Context * context) {
|
||||
|
||||
Integer a = r0.signedIntegerNumerator();
|
||||
Integer b = r1.signedIntegerNumerator();
|
||||
Expression result = Reduce(a, b);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression DivisionRemainder::Reduce(const Integer & a, const Integer & b) {
|
||||
if (b.isZero()) {
|
||||
Expression result = Undefined::Builder();
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
return Undefined::Builder();
|
||||
}
|
||||
Integer result = Integer::Division(a, b).remainder;
|
||||
assert(!result.isOverflow());
|
||||
Expression rationalResult = Rational::Builder(result);
|
||||
replaceWithInPlace(rationalResult);
|
||||
return rationalResult;
|
||||
return Rational::Builder(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user