From be247b0392602fea584b0af5c3d03f6a59fa4089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 4 Jan 2017 17:29:06 +0100 Subject: [PATCH] [apps/graph] When computing derivative function at abscissa, round the result Change-Id: I23817dda6ff9fe335e819086ecad5119eba1d948 --- apps/graph/function.cpp | 2 ++ apps/graph/function.h | 1 + 2 files changed, 3 insertions(+) diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index a69a0beda..3ef3aaf8f 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -1,5 +1,6 @@ #include "function.h" #include +#include namespace Graph { @@ -85,6 +86,7 @@ float Function::approximateDerivative(float x, Context * context) const { float functionPlus = evaluateAtAbscissa(x + k_epsilon, context); float functionMinus = evaluateAtAbscissa(x - k_epsilon, context); float growthRate = (functionPlus - functionMinus)/(2*k_epsilon); + growthRate = roundf(growthRate/k_precision)*k_precision; return growthRate; } diff --git a/apps/graph/function.h b/apps/graph/function.h index d55778d2d..26884032e 100644 --- a/apps/graph/function.h +++ b/apps/graph/function.h @@ -27,6 +27,7 @@ public: float approximateDerivative(float x, Context * context) const; private: constexpr static float k_epsilon = 0.0001f; + constexpr static float k_precision = 0.01f; constexpr static int k_bodyLength = 255; char m_text[k_bodyLength]; const char * m_name;