#include #include #include #include #include #include "layout/string_layout.h" #include "layout/horizontal_layout.h" extern "C" { #include #include } #include namespace Poincare { ExpressionLayout * Sequence::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const { assert(floatDisplayMode != FloatDisplayMode::Default); assert(complexFormat != ComplexFormat::Default); ExpressionLayout * childrenLayouts[2]; childrenLayouts[0] = new StringLayout("n=", 2); childrenLayouts[1] = operand(1)->createLayout(floatDisplayMode, complexFormat); return createSequenceLayoutWithArgumentLayouts(new HorizontalLayout(childrenLayouts, 2), operand(2)->createLayout(floatDisplayMode, complexFormat), operand(0)->createLayout(floatDisplayMode, complexFormat)); } template Expression * Sequence::templatedApproximate(Context& context, AngleUnit angleUnit) const { Expression * aInput = operand(1)->approximate(context, angleUnit); Expression * bInput = operand(2)->approximate(context, angleUnit); T start = aInput->type() == Type::Complex ? static_cast *>(aInput)->toScalar() : NAN; T end = bInput->type() == Type::Complex ? static_cast *>(bInput)->toScalar() : NAN; delete aInput; delete bInput; if (std::isnan(start) || std::isnan(end) || start != (int)start || end != (int)end || end - start > k_maxNumberOfSteps) { return new Complex(Complex::Float(NAN)); } VariableContext nContext = VariableContext('n', &context); Symbol nSymbol('n'); Expression * result = new Complex(Complex::Float(emptySequenceValue())); for (int i = (int)start; i <= (int)end; i++) { if (shouldStopProcessing()) { delete result; return new Complex(Complex::Float(NAN)); } Complex iExpression = Complex::Float(i); nContext.setExpressionForSymbolName(&iExpression, &nSymbol, nContext); Expression * expression = operand(0)->approximate(nContext, angleUnit); Expression * newResult = evaluateWithNextTerm(T(), result, expression); delete result; delete expression; result = newResult; } return result; } }