From 5be68133a143c6d06b9f6cc7e116d9a1e900d8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 9 Sep 2019 11:15:57 +0200 Subject: [PATCH] [apps/shared] CartesianFunction::approximateDerivative returns NAN out of the function domain --- apps/shared/cartesian_function.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index 343d0d5e7..ce3aa5a7a 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -215,6 +215,9 @@ int CartesianFunction::printValue(double cursorT, double cursorX, double cursorY } double CartesianFunction::approximateDerivative(double x, Poincare::Context * context) const { + if (x < tMin() || x > tMax()) { + return NAN; + } Poincare::Derivative derivative = Poincare::Derivative::Builder(expressionReduced(context).clone(), Symbol::Builder(UCodePointUnknownX), Poincare::Float::Builder(x)); // derivative takes ownership of Poincare::Float::Builder(x) and the clone of expression /* TODO: when we approximate derivative, we might want to simplify the * derivative here. However, we might want to do it once for all x (to avoid