mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[sequence] Cache context does not need to be a variable context
Fix crash: u(n) = n(n-1) would crash at evaluation
This commit is contained in:
@@ -8,9 +8,9 @@ namespace Sequence {
|
||||
|
||||
template<typename T>
|
||||
CacheContext<T>::CacheContext(Context * parentContext) :
|
||||
VariableContext("n", parentContext),
|
||||
m_values{{NAN, NAN},
|
||||
{NAN, NAN}}
|
||||
{NAN, NAN}},
|
||||
m_parentContext(parentContext)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,7 +24,12 @@ const Expression CacheContext<T>::expressionForSymbol(const SymbolAbstract & sym
|
||||
Symbol s = const_cast<Symbol &>(static_cast<const Symbol &>(symbol));
|
||||
return Float<T>::Builder(m_values[nameIndexForSymbol(s)][rankIndexForSymbol(s)]);
|
||||
}
|
||||
return VariableContext::expressionForSymbol(symbol, clone);
|
||||
return m_parentContext->expressionForSymbol(symbol, clone);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CacheContext<T>::setExpressionForSymbol(const Expression & expression, const SymbolAbstract & symbol, Context & context) {
|
||||
m_parentContext->setExpressionForSymbol(expression, symbol, context);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -4,21 +4,22 @@
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/variable_context.h>
|
||||
#include "sequence_context.h"
|
||||
|
||||
namespace Sequence {
|
||||
|
||||
template<typename T>
|
||||
class CacheContext : public Poincare::VariableContext {
|
||||
class CacheContext : public Poincare::Context {
|
||||
public:
|
||||
CacheContext(Poincare::Context * parentContext);
|
||||
const Poincare::Expression expressionForSymbol(const Poincare::SymbolAbstract & symbol, bool clone) override;
|
||||
void setExpressionForSymbol(const Poincare::Expression & expression, const Poincare::SymbolAbstract & symbol, Poincare::Context & context) override;
|
||||
void setValueForSymbol(T value, const Poincare::Symbol & symbol);
|
||||
private:
|
||||
int nameIndexForSymbol(const Poincare::Symbol & symbol);
|
||||
int rankIndexForSymbol(const Poincare::Symbol & symbol);
|
||||
T m_values[MaxNumberOfSequences][MaxRecurrenceDepth];
|
||||
Context * m_parentContext;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user