From 4209f0a26c1a97edd190e407bb4b2f6099a6476f Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Tue, 29 Dec 2020 15:42:47 +0100 Subject: [PATCH] [poincare/function] getVariables always gets the argument When applied to a function f(x) = constant, the method getVariables would not find any, as the search is performed on the function's definition. Thus, when using the "Fill with formula" tool in Statistics, if the formula to fill V1 is "V1=f(V2)", the formula will be considered constant and applied to all values in V1. However, if V1 is longer than V2, the program will attempt to read undefined values of V2. With this change, the formula will only be applied to lines in V1 for which there is a corresponding line in V2. --- poincare/src/function.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index 023a5ed0f..16832db33 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -38,6 +38,10 @@ int FunctionNode::getPolynomialCoefficients(Context * context, const char * symb int FunctionNode::getVariables(Context * context, isVariableTest isVariable, char * variables, int maxSizeVariable, int nextVariableIndex) const { Function f(this); Expression e = SymbolAbstract::Expand(f, context, true); + /* Since templatedApproximate always evaluates the argument, some apps (such + * as Statistics and Regression) need to be aware of it even when it does not + * appear in the formula. */ + nextVariableIndex = childAtIndex(0)->getVariables(context, isVariable, variables, maxSizeVariable, nextVariableIndex); if (e.isUninitialized()) { return nextVariableIndex; }