extern "C" { #include #include #include } #include #include #include #include #include #include #include "layout/fraction_layout.h" #include namespace Poincare { Expression::Type Division::type() const { return Type::Division; } Expression * Division::clone() const { return new Division(m_operands, true); } int Division::polynomialDegree(char symbolName) const { if (operand(1)->polynomialDegree(symbolName) != 0) { return -1; } return operand(0)->polynomialDegree(symbolName); } bool Division::needParenthesisWithParent(const Expression * e) const { Type types[] = {Type::Division, Type::Power, Type::Factorial}; return e->isOfType(types, 3); } Expression * Division::shallowReduce(Context& context, AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; } Power * p = new Power(operand(1), new Rational(-1), false); Multiplication * m = new Multiplication(operand(0), p, false); detachOperands(); p->shallowReduce(context, angleUnit); replaceWith(m, true); return m->shallowReduce(context, angleUnit); } template std::complex Division::compute(const std::complex c, const std::complex d) { return c/d; } ExpressionLayout * Division::createLayout(PrintFloat::Mode floatDisplayMode, int numberOfSignificantDigits) const { const Expression * numerator = operand(0)->type() == Type::Parenthesis ? operand(0)->operand(0) : operand(0); const Expression * denominator = operand(1)->type() == Type::Parenthesis ? operand(1)->operand(0) : operand(1); return new FractionLayout(numerator->createLayout(floatDisplayMode, numberOfSignificantDigits), denominator->createLayout(floatDisplayMode, numberOfSignificantDigits), false); } template MatrixComplex Division::computeOnComplexAndMatrix(const std::complex c, const MatrixComplex n) { MatrixComplex * inverse = n.createInverse(); if (inverse == nullptr) { return MatrixComplex::Undefined(); } MatrixComplex result = Multiplication::computeOnComplexAndMatrix(c, *inverse); delete inverse; return result; } template MatrixComplex Division::computeOnMatrices(const MatrixComplex m, const MatrixComplex n) { if (m.numberOfColumns() != n.numberOfColumns()) { return MatrixComplex::Undefined(); } MatrixComplex * inverse = n.createInverse(); if (inverse == nullptr) { return MatrixComplex::Undefined(); } MatrixComplex result = Multiplication::computeOnMatrices(m, *inverse); delete inverse; return result; } }