[poincare] Change natural comparison names in Integer

Change-Id: Ifdd4ef3991e650d601a378a9742ae2371915ce77
This commit is contained in:
Émilie Feral
2017-10-31 12:02:31 +01:00
parent ae31a78ca6
commit 889a0d8eb4
5 changed files with 12 additions and 15 deletions

View File

@@ -42,7 +42,7 @@ public:
void setNegative(bool negative);
// Comparison
int compareTo(const Integer * i) const;
static int NaturalOrder(const Integer & i, const Integer & j);
bool isEqualTo(const Integer & other) const;
bool isLowerThan(const Integer & other) const;

View File

@@ -77,7 +77,6 @@ Integer Integer::exponent(int fractionalPartLength, const char * exponent, int e
}
Integer Integer::numerator(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative, Integer * exponent) {
Integer zero = Integer(0);
Integer base = Integer(10);
Integer numerator = Integer(integralPart, negative);
for (int i = 0; i < fractionalPartLength; i++) {
@@ -86,7 +85,7 @@ Integer Integer::numerator(const char * integralPart, int integralPartLength, co
fractionalPart++;
}
if (exponent->isNegative()) {
while (exponent->compareTo(&zero) != 0) {
while (!exponent->isEqualTo(Integer(0))) {
numerator = Multiplication(numerator, base);
*exponent = Addition(*exponent, Integer(1));
}
@@ -95,11 +94,10 @@ Integer Integer::numerator(const char * integralPart, int integralPartLength, co
}
Integer Integer::denominator(Integer * exponent) {
Integer zero = Integer(0);
Integer base = Integer(10);
Integer denominator = Integer(1);
if (!exponent->isNegative()) {
while (exponent->compareTo(&zero) != 0) {
while (!exponent->isEqualTo(Integer(0))) {
denominator = Multiplication(denominator, base);
*exponent = Subtraction(*exponent, Integer(1));
}
@@ -188,22 +186,22 @@ void Integer::setNegative(bool negative) {
// Comparison
int Integer::compareTo(const Integer * other) const {
if (m_negative && !other->m_negative) {
int Integer::NaturalOrder(const Integer & i, const Integer & j) {
if (i.isNegative() && !j.isNegative()) {
return -1;
}
if (!m_negative && other->m_negative) {
if (!i.isNegative() && j.isNegative()) {
return 1;
}
return ::Poincare::sign(m_negative)*ucmp(*this, *other);
return ::Poincare::sign(i.isNegative())*ucmp(i, j);
}
bool Integer::isEqualTo(const Integer & other) const {
return (compareTo(&other) == 0);
return (NaturalOrder(*this, other) == 0);
}
bool Integer::isLowerThan(const Integer & other) const {
return (compareTo(&other) < 0);
return (NaturalOrder(*this, other) < 0);
}
// Arithmetic

View File

@@ -336,8 +336,7 @@ Expression * Power::shallowBeautify(Context& context, AngleUnit angleUnit) {
}
if (operand(1)->type() == Type::Rational && static_cast<const Rational *>(operand(1))->numerator().isOne()) {
Integer index = static_cast<const Rational *>(operand(1))->denominator();
Integer two = Integer(2);
if (index.compareTo(&two) == 0) {
if (index.isEqualTo(Integer(2))) {
const Expression * sqrtOperand[1] = {operand(0)};
SquareRoot * sqr = new SquareRoot(sqrtOperand, true);
return replaceWith(sqr, true);

View File

@@ -119,7 +119,7 @@ int Rational::simplificationOrderSameType(const Expression * e) const {
const Rational * other = static_cast<const Rational *>(e);
Integer i1 = Integer::Multiplication(m_numerator, other->denominator());
Integer i2 = Integer::Multiplication(m_denominator, other->numerator());
return i1.compareTo(&i2);
return Integer::NaturalOrder(i1, i2);
}
template<typename T> Evaluation<T> * Rational::templatedEvaluate(Context& context, Expression::AngleUnit angleUnit) const {

View File

@@ -22,7 +22,7 @@ void assert_gcd_equals_to(Integer a, Integer b, Integer c) {
#if POINCARE_TESTS_PRINT_EXPRESSIONS
cout << gcd.approximate<float>() << endl;
#endif
assert(gcd.compareTo(&c) == 0);
assert(gcd.isEqualTo(c));
}
void assert_prime_factorization_equals_to(Integer a, int * factors, int * coefficients, int length) {