From 889a0d8eb47ca270b479991e4af4d2ac4558a93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 31 Oct 2017 12:02:31 +0100 Subject: [PATCH] [poincare] Change natural comparison names in Integer Change-Id: Ifdd4ef3991e650d601a378a9742ae2371915ce77 --- poincare/include/poincare/integer.h | 2 +- poincare/src/integer.cpp | 18 ++++++++---------- poincare/src/power.cpp | 3 +-- poincare/src/rational.cpp | 2 +- poincare/test/arithmetic.cpp | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index b1e543d83..a31ac6226 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -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; diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 3d7fb80dd..9f7f7799c 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -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 diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index c45a882b3..2995073a5 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -336,8 +336,7 @@ Expression * Power::shallowBeautify(Context& context, AngleUnit angleUnit) { } if (operand(1)->type() == Type::Rational && static_cast(operand(1))->numerator().isOne()) { Integer index = static_cast(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); diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index e2f93eabd..b03e429ef 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -119,7 +119,7 @@ int Rational::simplificationOrderSameType(const Expression * e) const { const Rational * other = static_cast(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 Evaluation * Rational::templatedEvaluate(Context& context, Expression::AngleUnit angleUnit) const { diff --git a/poincare/test/arithmetic.cpp b/poincare/test/arithmetic.cpp index 8064cac01..9ad185b66 100644 --- a/poincare/test/arithmetic.cpp +++ b/poincare/test/arithmetic.cpp @@ -22,7 +22,7 @@ void assert_gcd_equals_to(Integer a, Integer b, Integer c) { #if POINCARE_TESTS_PRINT_EXPRESSIONS cout << gcd.approximate() << 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) {