mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare][apps] Replace Ans symbol when preprocessing the calculation
This commit is contained in:
committed by
EmilieNumworks
parent
17fc7998a2
commit
775432efdc
@@ -1,4 +1,5 @@
|
||||
#include "calculation.h"
|
||||
#include "calculation_store.h"
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
using namespace Poincare;
|
||||
@@ -63,9 +64,10 @@ void Calculation::reset() {
|
||||
tidy();
|
||||
}
|
||||
|
||||
void Calculation::setContent(const char * c, Context * context) {
|
||||
void Calculation::setContent(const char * c, Context * context, CalculationStore * calculationStore) {
|
||||
reset();
|
||||
m_input = Expression::parse(c);
|
||||
Expression::ReplaceSymbolWithExpression(&m_input, Symbol::SpecialSymbols::Ans, ansExpression(calculationStore, context));
|
||||
/* We do not store directly the text enter by the user but its serialization
|
||||
* to be able to compare it to the exact ouput text. */
|
||||
m_input->writeTextInBuffer(m_inputText, sizeof(m_inputText));
|
||||
@@ -196,4 +198,16 @@ bool Calculation::shouldDisplayApproximateOutput(Context * context) {
|
||||
return input()->isApproximate(*context);
|
||||
}
|
||||
|
||||
Expression * Calculation::ansExpression(CalculationStore * calculationStore, Context * context) {
|
||||
if (calculationStore->numberOfCalculations() == 0) {
|
||||
static Rational defaultExpression(0);
|
||||
return &defaultExpression;
|
||||
}
|
||||
Calculation * lastCalculation = calculationStore->calculationAtIndex(calculationStore->numberOfCalculations()-1);
|
||||
if (lastCalculation->input()->isApproximate(*context)) {
|
||||
return lastCalculation->approximateOutput(context);
|
||||
}
|
||||
return lastCalculation->exactOutput(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user