#include #include #include #include #include "layout/nth_root_layout.h" extern "C" { #include } #include namespace Poincare { Expression::Type NthRoot::type() const { return Type::NthRoot; } Expression * NthRoot::clone() const { NthRoot * a = new NthRoot(m_operands, true); return a; } Expression * NthRoot::shallowReduce(Context& context, AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; } #if MATRIX_EXACT_REDUCING if (operand(0)->type() == Type::Matrix || operand(1)->type() == Type::Matrix) { return replaceWith(new Undefined(), true); } #endif Power * invIndex = new Power(operand(1), new Rational(-1), false); Power * p = new Power(operand(0), invIndex, false); detachOperands(); invIndex->shallowReduce(context, angleUnit); replaceWith(p, true); return p->shallowReduce(context, angleUnit); } ExpressionLayout * NthRoot::createLayout(PrintFloat::Mode floatDisplayMode, int numberOfSignificantDigits) const { return new NthRootLayout(operand(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), operand(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), false); } template Evaluation * NthRoot::templatedApproximate(Context& context, AngleUnit angleUnit) const { Evaluation * base = operand(0)->privateApproximate(T(), context, angleUnit); Evaluation * index = operand(1)->privateApproximate(T(), context, angleUnit); Complex result = Complex::Undefined(); if (base->type() == Evaluation::Type::Complex && index->type() == Evaluation::Type::Complex) { Complex * basec = static_cast *>(base); Complex * indexc = static_cast *>(index); result = Power::compute(*basec, std::complex(1)/(*indexc)); } delete base; delete index; return new Complex(result); } }