From ffe156571ff945fccde990b6333ac2b393cf69eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 7 Nov 2017 18:25:26 +0100 Subject: [PATCH] [poincare] Use shortcut constructor Rational(Integer())->Rational() Change-Id: I4af40105e19b3ee94fefd5cdc5dc4d20e76f8f52 --- poincare/src/logarithm.cpp | 2 +- poincare/src/multiplication.cpp | 10 +++++----- poincare/src/power.cpp | 14 +++++++------- poincare/src/square_root.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index ebbe60668..61b5419b1 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -110,7 +110,7 @@ Expression * Logarithm::splitInteger(Integer i, bool isDenominator, Context & co Expression * Logarithm::shallowBeautify(Context & context, AngleUnit angleUnit) { Symbol e = Symbol(Ion::Charset::Exponential); const Expression * op = operand(0); - Rational one = Rational(Integer(1)); + Rational one(1); if (numberOfOperands() == 2 && (operand(1)->isIdenticalTo(&e) || operand(1)->isIdenticalTo(&one))) { detachOperand(op); Expression * nl = operand(1)->isIdenticalTo(&e) ? static_cast(new NaperianLogarithm(op, false)) : static_cast (new Logarithm(op, false)); diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index c95e860ad..aa6445d27 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -120,7 +120,7 @@ Expression * Multiplication::shallowReduce(Context& context, AngleUnit angleUnit } /* Step 2: If any of the operand is zero, the multiplication result is zero */ for (int i = 0; i < numberOfOperands(); i++) { - Expression * o = editableOperand(i++); + Expression * o = editableOperand(i); if (o->type() == Type::Rational && static_cast(o)->isZero()) { return replaceWith(new Rational(0), true); } @@ -188,8 +188,8 @@ Expression * Multiplication::resolveSquareRootAtDenominator(Context & context, A if (o->type() == Type::Power && o->operand(0)->type() == Type::Rational && o->operand(1)->type() == Type::Rational && static_cast(o->operand(1))->isMinusHalf()) { Integer p = static_cast(o->operand(0))->numerator(); Integer q = static_cast(o->operand(0))->denominator(); - Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(Integer(1), Integer(2)), false); - replaceOperand(o, new Rational(Integer(1), Integer(p)), true); + Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(1, 2), false); + replaceOperand(o, new Rational(Integer(1), p), true); Expression * newExpression = shallowReduce(context, angleUnit); if (newExpression->type() == Type::Multiplication) { static_cast(newExpression)->addOperand(sqrt); @@ -223,8 +223,8 @@ Expression * Multiplication::resolveSquareRootAtDenominator(Context & context, A Integer::Power(n2, Integer(2)), Integer::Power(d1, Integer(2))), Integer::Multiplication(p2, q1))); - Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(Integer(1), Integer(2)), false); - Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(Integer(1), Integer(2)), false); + Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(1, 2), false); + Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(1, 2), false); Integer factor1 = Integer::Multiplication( Integer::Multiplication(n1, d1), Integer::Multiplication(Integer::Power(d2, Integer(2)), q2)); diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index c08d104b2..999e49d3b 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -131,7 +131,7 @@ int Power::simplificationOrderGreaterType(const Expression * e) const { if (baseComparison != 0) { return baseComparison; } - Rational one(Integer(1)); + Rational one(1); return SimplificationOrder(operand(1), &one); } @@ -282,8 +282,8 @@ Expression * Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational * r Integer coefficients[Arithmetic::k_maxNumberOfPrimeFactors]; Arithmetic::PrimeFactorization(&i, factors, coefficients, Arithmetic::k_maxNumberOfPrimeFactors); - Integer r1 = Integer(1); - Integer r2 = Integer(1); + Integer r1(1); + Integer r2(1); int index = 0; while (!coefficients[index].isZero() && index < Arithmetic::k_maxNumberOfPrimeFactors) { Integer n = Integer::Multiplication(coefficients[index], r->numerator()); @@ -363,8 +363,8 @@ Expression * Power::resolveSquareRootAtDenominator(Context & context, AngleUnit if (operand(0)->type() == Type::Rational && operand(1)->type() == Type::Rational && static_cast(operand(1))->isMinusHalf()) { Integer p = static_cast(operand(0))->numerator(); Integer q = static_cast(operand(0))->denominator(); - Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(Integer(1), Integer(2)), false); - Expression * newExpression = new Multiplication(new Rational(Integer(1), Integer(p)), sqrt, false); + Power * sqrt = new Power(new Rational(Integer::Multiplication(p, q)), new Rational(1, 2), false); + Expression * newExpression = new Multiplication(new Rational(Integer(1), p), sqrt, false); sqrt->shallowReduce(context, angleUnit); return replaceWith(newExpression, true); } else if (operand(1)->type() == Type::Rational && static_cast(operand(1))->isMinusOne() && operand(0)->type() == Type::Addition && operand(0)->numberOfOperands() == 2 && TermIsARationalSquareRootOrRational(operand(0)->operand(0)) && TermIsARationalSquareRootOrRational(operand(0)->operand(1))) { @@ -392,8 +392,8 @@ Expression * Power::resolveSquareRootAtDenominator(Context & context, AngleUnit Integer::Power(n2, Integer(2)), Integer::Power(d1, Integer(2))), Integer::Multiplication(p2, q1))); - Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(Integer(1), Integer(2)), false); - Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(Integer(1), Integer(2)), false); + Power * sqrt1 = new Power(new Rational(Integer::Multiplication(p1, q1)), new Rational(1, 2), false); + Power * sqrt2 = new Power(new Rational(Integer::Multiplication(p2, q2)), new Rational(1, 2), false); Integer factor1 = Integer::Multiplication( Integer::Multiplication(n1, d1), Integer::Multiplication(Integer::Power(d2, Integer(2)), q2)); diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 4f9033b86..a6e0bb6fe 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -33,7 +33,7 @@ Complex SquareRoot::computeOnComplex(const Complex c, AngleUnit angleUnit) } Expression * SquareRoot::shallowReduce(Context& context, AngleUnit angleUnit) { - Power * p = new Power(operand(0), new Rational(Integer(1), Integer(2)), false); + Power * p = new Power(operand(0), new Rational(1, 2), false); detachOperands(); replaceWith(p, true); return p->shallowReduce(context, angleUnit);