[Sequence] Fixed computation error and asan fails

Change-Id: Ib3a619d29bee5cc6f10b939ee066459a5b135c5d
This commit is contained in:
Arthur Camouseigt
2020-10-01 16:18:39 +02:00
committed by Émilie Feral
parent 86d0c19293
commit bf95b460c3
6 changed files with 18 additions and 8 deletions

View File

@@ -399,6 +399,19 @@ QUIZ_CASE(sequence_evaluation) {
conditions1[2] = "6";
conditions2[2] = nullptr;
check_sequences_defined_by(results32, types, definitions, conditions1, conditions2);
// u independent, v depends on u(n+6)
// u(n) = 9n; v(n+1) = u(n+6)+v(0); v(0) = 9
double results33[MaxNumberOfSequences][10] = {{0.0, 9.0, 18.0, 27.0, 36.0, 45.0, 54.0, 63.0, 72.0, 81.0},
{9.0, 63.0, 72.0, 81.0, 90.0, 99.0, 108.0, 117.0, 126.0, 135.0},
{}};
types[0] = Sequence::Type::Explicit;
types[1] = Sequence::Type::SingleRecurrence;
definitions[0] = "9n";
definitions[1] = "u(n+6)+v(0)";
definitions[2] = nullptr;
conditions1[1] = "9";
check_sequences_defined_by(results33, types, definitions, conditions1, conditions2);
}
QUIZ_CASE(sequence_sum_evaluation) {

View File

@@ -243,7 +243,6 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx, int sequenceIn
symbols[i][j] = Symbol::Builder(name[j], strlen(name[j]));
}
}
ctx.setNValue(n);
switch (type()) {
case Type::Explicit:
{

View File

@@ -33,7 +33,7 @@ const Expression SequenceCacheContext<T>::expressionForSymbolAbstract(const Poin
Ion::Storage::Record record = m_sequenceContext->sequenceStore()->recordAtIndex(index);
if (!record.isNull()) {
Sequence * seq = m_sequenceContext->sequenceStore()->modelForRecord(record);
rank.replaceSymbolWithExpression(Symbol::Builder(UCodePointUnknown), Float<T>::Builder(m_nValue));
rank.replaceSymbolWithExpression(Symbol::Builder(UCodePointUnknown), Float<T>::Builder(unknownSymbolValue));
T n = PoincareHelpers::ApproximateToScalar<T>(rank, this);
// In case the sequence referenced is not defined or if the rank is not an int, return NAN
if (seq->fullName() != nullptr) {

View File

@@ -14,12 +14,10 @@ public:
SequenceCacheContext(SequenceContext * sequenceContext);
const Poincare::Expression expressionForSymbolAbstract(const Poincare::SymbolAbstract & symbol, bool clone, float unknownSymbolValue = NAN) override;
void setValueForSymbol(T value, const Poincare::Symbol & symbol);
void setNValue(int n) { m_nValue = n; }
private:
int nameIndexForSymbol(const Poincare::Symbol & symbol);
int rankIndexForSymbol(const Poincare::Symbol & symbol);
T m_values[MaxNumberOfSequences][MaxRecurrenceDepth];
int m_nValue;
SequenceContext * m_sequenceContext;
};

View File

@@ -407,7 +407,7 @@ void Parser::parseReservedFunction(Expression & leftHandSide, const Expression::
}
}
void Parser::parseSequence(Expression & leftHandSide, const char name, Token::Type leftDelimiter1, Token::Type rightDelimiter1, Token::Type leftDelimiter2, Token::Type rightDelimiter2) {
void Parser::parseSequence(Expression & leftHandSide, const char * name, Token::Type leftDelimiter1, Token::Type rightDelimiter1, Token::Type leftDelimiter2, Token::Type rightDelimiter2) {
bool delimiterTypeIsOne = popTokenIfType(leftDelimiter1);
if (!delimiterTypeIsOne && !popTokenIfType(leftDelimiter2)) {
m_status = Status::Error; // Left delimiter missing.
@@ -418,7 +418,7 @@ void Parser::parseSequence(Expression & leftHandSide, const char name, Token::Ty
} else if (!popTokenIfType(rightDelimiter)) {
m_status = Status::Error; // Right delimiter missing
} else {
leftHandSide = Sequence::Builder(&name, 1, rank);
leftHandSide = Sequence::Builder(name, 1, rank);
}
}
}
@@ -439,7 +439,7 @@ void Parser::parseSpecialIdentifier(Expression & leftHandSide) {
/* Special case for sequences (e.g. "u(n)", "u{n}", ...)
* We know that m_currentToken.text()[0] is either 'u', 'v' or 'w', so we do
* not need to pass a code point to parseSequence. */
parseSequence(leftHandSide, m_currentToken.text()[0], Token::LeftParenthesis, Token::RightParenthesis, Token::LeftBrace, Token::RightBrace);
parseSequence(leftHandSide, m_currentToken.text(), Token::LeftParenthesis, Token::RightParenthesis, Token::LeftBrace, Token::RightBrace);
}
}

View File

@@ -75,7 +75,7 @@ private:
Expression parseCommaSeparatedList();
void parseReservedFunction(Expression & leftHandSide, const Expression::FunctionHelper * const * functionHelper);
void parseSpecialIdentifier(Expression & leftHandSide);
void parseSequence(Expression & leftHandSide, const char name, Token::Type leftDelimiter1, Token::Type rightDelimiter1, Token::Type leftDelimiter2, Token::Type rightDelimiter2);
void parseSequence(Expression & leftHandSide, const char * name, Token::Type leftDelimiter1, Token::Type rightDelimiter1, Token::Type leftDelimiter2, Token::Type rightDelimiter2);
void parseCustomIdentifier(Expression & leftHandSide, const char * name, size_t length);
void defaultParseLeftParenthesis(bool isSystemParenthesis, Expression & leftHandSide, Token::Type stoppingType);