From 4fef87ddb5f82034704a07c7552452a48a9d3170 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Wed, 3 Jul 2019 11:31:08 +0200 Subject: [PATCH] [apps/sequence/sequence] Replace sumBetweenBounds explicit definition by Poincare machinery --- apps/sequence/sequence.cpp | 16 +++------------- apps/sequence/sequence.h | 1 - 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index 9f3e5cab7..296d0e0dc 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "../shared/poincare_helpers.h" #include #include @@ -186,19 +187,8 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const { } double Sequence::sumBetweenBounds(double start, double end, Context * context) const { - double result = 0.0; - if (end-start > k_maxNumberOfTermsInSum || start + 1.0 == start) { - return NAN; - } - for (double i = std::round(start); i <= std::round(end); i = i + 1.0) { - /* When |start| >> 1.0, start + 1.0 = start. In that case, quit the - * infinite loop. */ - if (i == i-1.0 || i == i+1.0) { - return NAN; - } - result += evaluateAtAbscissa(i, context); - } - return result; + Poincare::Sum sum = Poincare::Sum::Builder(expressionReduced(context).clone(), Symbol::Builder(UCodePointUnknownX), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Sum takes ownership of args + return PoincareHelpers::ApproximateToScalar(sum, *context); } Sequence::SequenceRecordDataBuffer * Sequence::recordData() const { diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index 749cc93a0..794d4bdd6 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -70,7 +70,6 @@ public: constexpr static int k_initialRankNumberOfDigits = 3; // m_initialRank is capped by 999 private: constexpr static const KDFont * k_layoutFont = KDFont::LargeFont; - constexpr static double k_maxNumberOfTermsInSum = 100000.0; /* SequenceRecordDataBuffer is the layout of the data buffer of Record * representing a Sequence. See comment in