From 3cedfb84e94d20f5cdf6313eec8dbca975850fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 12 Oct 2018 09:37:53 +0200 Subject: [PATCH] [shared] StorageCartesianFunction: add a method derivativeNameWithArgument --- apps/shared/storage_cartesian_function.cpp | 13 +++++++++++++ apps/shared/storage_cartesian_function.h | 1 + 2 files changed, 14 insertions(+) diff --git a/apps/shared/storage_cartesian_function.cpp b/apps/shared/storage_cartesian_function.cpp index 55db2760a..b70ff1249 100644 --- a/apps/shared/storage_cartesian_function.cpp +++ b/apps/shared/storage_cartesian_function.cpp @@ -46,6 +46,19 @@ StorageCartesianFunction StorageCartesianFunction::NewModel(Ion::Storage::Record return StorageCartesianFunction(Ion::Storage::sharedStorage()->recordNamed(nameBuffer)); } +int StorageCartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize, char arg) { + // Fill buffer with f(x). Keep one char for derivative sign. + int numberOfChars = nameWithArgument(buffer, bufferSize-1, arg); + assert(numberOfChars < bufferSize - 1); + char * lastChar = buffer+numberOfChars; + while (*(lastChar+1) != '(' && lastChar >= buffer) { + *(lastChar+1) = *lastChar; + lastChar--; + } + *lastChar = '\''; + return numberOfChars+1; +} + bool StorageCartesianFunction::displayDerivative() const { return recordData()->displayDerivative(); } diff --git a/apps/shared/storage_cartesian_function.h b/apps/shared/storage_cartesian_function.h index a62d54e0f..e3d221e18 100644 --- a/apps/shared/storage_cartesian_function.h +++ b/apps/shared/storage_cartesian_function.h @@ -18,6 +18,7 @@ public: //bool operator!=(const StorageCartesianFunction & other) const { return !(*(static_cast(this)) == static_cast(other)); } bool displayDerivative() const; void setDisplayDerivative(bool display); + int derivativeNameWithArgument(char * buffer, size_t bufferSize, char arg); double approximateDerivative(double x, Poincare::Context * context) const; double sumBetweenBounds(double start, double end, Poincare::Context * context) const override; Poincare::Expression::Coordinate2D nextMinimumFrom(double start, double step, double max, Poincare::Context * context) const;