mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Change name: createEvaluation -> evaluate
Change-Id: I8f241541af0435c6ab4f7ba1f561f880c4e95ac0
This commit is contained in:
@@ -57,7 +57,7 @@ void Calculation::setContent(const char * c, Context * context) {
|
||||
if (m_evaluation != nullptr) {
|
||||
delete m_evaluationLayout;
|
||||
}
|
||||
m_evaluation = m_expression->createEvaluation(*context);
|
||||
m_evaluation = m_expression->evaluate(*context);
|
||||
if (m_evaluationLayout != nullptr) {
|
||||
delete m_evaluationLayout;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ bool ExpressionTextFieldDelegate::textFieldDidReceiveEvent(TextField * textField
|
||||
textField->app()->displayWarning("Attention a la syntaxe jeune padawan");
|
||||
return true;
|
||||
}
|
||||
Expression * evaluation = exp->createEvaluation(*evaluateContext());
|
||||
Expression * evaluation = exp->evaluate(*evaluateContext());
|
||||
if (evaluation == nullptr) {
|
||||
delete exp;
|
||||
textField->app()->displayWarning("Relis ton cours de maths, veux tu?");
|
||||
|
||||
@@ -13,7 +13,7 @@ class Addition : public Expression {
|
||||
int numberOfOperands() const override;
|
||||
Type type() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Expression * clone() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
@@ -21,9 +21,9 @@ class Addition : public Expression {
|
||||
bool isCommutative() const override;
|
||||
private:
|
||||
float operateApproximatevelyOn(float a, float b) const;
|
||||
Expression * createEvaluationOn(Expression * a, Expression * b, Context& context) const;
|
||||
Expression * createEvaluationOnFloatAndMatrix(Float * a, Matrix * m, Context& context) const;
|
||||
Expression * createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
Expression * evaluateOn(Expression * a, Expression * b, Context& context) const;
|
||||
Expression * evaluateOnFloatAndMatrix(Float * a, Matrix * m, Context& context) const;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
const int m_numberOfOperands;
|
||||
Expression ** m_operands;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ class Cosine : public Function {
|
||||
public:
|
||||
Cosine();
|
||||
float approximate(Context & context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
|
||||
@@ -65,8 +65,9 @@ class Expression {
|
||||
|
||||
virtual Type type() const = 0;
|
||||
virtual bool isCommutative() const;
|
||||
|
||||
virtual Expression * createEvaluation(Context& context) const = 0;
|
||||
/* The function evaluate creates a new expression and thus mallocs memory.
|
||||
* Do not forget to delete the new expression to avoid leaking. */
|
||||
virtual Expression * evaluate(Context& context) const = 0;
|
||||
virtual float approximate(Context& context) const = 0;
|
||||
char * text();
|
||||
protected:
|
||||
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
bool valueEquals(const Expression * e) const override;
|
||||
|
||||
@@ -10,13 +10,13 @@ class Fraction : public BinaryOperation {
|
||||
public:
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
Expression * createEvaluationOnMatrixAndFloat(Matrix * m, Float * f, Context& context) const;
|
||||
Expression * createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
Expression * evaluateOnMatrixAndFloat(Matrix * m, Float * f, Context& context) const;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@ class Integer : public LeafExpression {
|
||||
Expression * clone() const override;
|
||||
virtual ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
private:
|
||||
Integer add(const Integer &other, bool inverse_other_negative) const;
|
||||
int8_t ucmp(const Integer &other) const; // -1, 0, or 1
|
||||
|
||||
@@ -7,7 +7,7 @@ class Logarithm : public Function {
|
||||
public:
|
||||
Logarithm();
|
||||
float approximate(Context & context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
|
||||
@@ -15,7 +15,7 @@ class Matrix : public Expression {
|
||||
Expression * clone() const override;
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
|
||||
@@ -12,7 +12,7 @@ class Parenthesis : public Expression {
|
||||
Expression * clone() const override;
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
|
||||
@@ -10,13 +10,13 @@ class Power : public BinaryOperation {
|
||||
using BinaryOperation::BinaryOperation;
|
||||
public:
|
||||
ExpressionLayout * createLayout() const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
float approximate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
Expression * createEvaluationOnMatrixAndInteger(Matrix * m, Integer * i, Context& context) const;
|
||||
Expression * evaluateOnMatrixAndInteger(Matrix * m, Integer * i, Context& context) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,12 +11,12 @@ class Product : public BinaryOperation {
|
||||
Type type() const override;
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
Expression * createEvaluationOnMatrixAndFloat(Matrix * m, Float * f, Context& context) const;
|
||||
Expression * createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
Expression * evaluateOnMatrixAndFloat(Matrix * m, Float * f, Context& context) const;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@ class Sine : public Function {
|
||||
public:
|
||||
Sine();
|
||||
float approximate(Context & context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
|
||||
@@ -11,13 +11,13 @@ class Subtraction : public BinaryOperation {
|
||||
public:
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
Expression * createEvaluationOnMatrixAndFloat(Matrix * m, Float * f, Context& context, bool matrixMinusFloat) const;
|
||||
Expression * createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
Expression * evaluateOnMatrixAndFloat(Matrix * m, Float * f, Context& context, bool matrixMinusFloat) const;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
Symbol(char name);
|
||||
ExpressionLayout * createLayout() const override;
|
||||
float approximate(Context& context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
const char name() const;
|
||||
Expression * clone() const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ class Tangent : public Function {
|
||||
public:
|
||||
Tangent();
|
||||
float approximate(Context & context) const override;
|
||||
Expression * createEvaluation(Context& context) const override;
|
||||
Expression * evaluate(Context& context) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
|
||||
@@ -53,11 +53,11 @@ float Addition::approximate(Context& context) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * Addition::createEvaluation(Context& context) const {
|
||||
Expression * result = m_operands[0]->createEvaluation(context);
|
||||
Expression * Addition::evaluate(Context& context) const {
|
||||
Expression * result = m_operands[0]->evaluate(context);
|
||||
for (int i=1; i<m_numberOfOperands; i++) {
|
||||
Expression * next = m_operands[i]->createEvaluation(context);
|
||||
Expression * newResult = this->createEvaluationOn(result, next, context);
|
||||
Expression * next = m_operands[i]->evaluate(context);
|
||||
Expression * newResult = this->evaluateOn(result, next, context);
|
||||
delete result;
|
||||
result = newResult;
|
||||
delete next;
|
||||
@@ -94,7 +94,7 @@ float Addition::operateApproximatevelyOn(float a, float b) const {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
Expression * Addition::createEvaluationOn(Expression * a, Expression * b, Context& context) const {
|
||||
Expression * Addition::evaluateOn(Expression * a, Expression * b, Context& context) const {
|
||||
if (a == nullptr || b == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -105,18 +105,18 @@ Expression * Addition::createEvaluationOn(Expression * a, Expression * b, Contex
|
||||
result = new Float(a->approximate(context) + b->approximate(context));
|
||||
}
|
||||
if (a->type() == Expression::Type::Float && b->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnFloatAndMatrix((Float *)a, (Matrix *)b, context);
|
||||
result = evaluateOnFloatAndMatrix((Float *)a, (Matrix *)b, context);
|
||||
}
|
||||
if (b->type() == Expression::Type::Float && a->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnFloatAndMatrix((Float *)b, (Matrix *)a, context);
|
||||
result = evaluateOnFloatAndMatrix((Float *)b, (Matrix *)a, context);
|
||||
}
|
||||
if (b->type() == Expression::Type::Matrix && a->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnMatrices((Matrix *)a, (Matrix *)b, context);
|
||||
result = evaluateOnMatrices((Matrix *)a, (Matrix *)b, context);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * Addition::createEvaluationOnFloatAndMatrix(Float * a, Matrix * m, Context& context) const {
|
||||
Expression * Addition::evaluateOnFloatAndMatrix(Float * a, Matrix * m, Context& context) const {
|
||||
Expression * operands[m->numberOfRows() * m->numberOfColumns()];
|
||||
for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) {
|
||||
operands[i] = new Float(a->approximate(context) + m->operand(i)->approximate(context));
|
||||
@@ -124,7 +124,7 @@ Expression * Addition::createEvaluationOnFloatAndMatrix(Float * a, Matrix * m, C
|
||||
return new Matrix(operands, m->numberOfRows() * m->numberOfColumns(), m->numberOfColumns(), m->numberOfRows(), false);
|
||||
}
|
||||
|
||||
Expression * Addition::createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
Expression * Addition::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
if (m->numberOfColumns() != n->numberOfColumns() || m->numberOfRows() != n->numberOfRows()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,6 @@ float Cosine::approximate(Context& context) const {
|
||||
return cosf(m_arg->approximate(context));
|
||||
}
|
||||
|
||||
Expression * Cosine::createEvaluation(Context& context) const {
|
||||
Expression * Cosine::evaluate(Context& context) const {
|
||||
return new Float(cosf(m_arg->approximate(context)));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ float Float::approximate(Context& context) const {
|
||||
return m_float;
|
||||
}
|
||||
|
||||
Expression * Float::createEvaluation(Context& context) const {
|
||||
Expression * Float::evaluate(Context& context) const {
|
||||
return new Float(m_float);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ Expression::Type Fraction::type() const {
|
||||
return Expression::Type::Fraction;
|
||||
}
|
||||
|
||||
Expression * Fraction::createEvaluation(Context& context) const {
|
||||
Expression * numerator = m_operands[0]->createEvaluation(context);
|
||||
Expression * denominator = m_operands[1]->createEvaluation(context);
|
||||
Expression * Fraction::evaluate(Context& context) const {
|
||||
Expression * numerator = m_operands[0]->evaluate(context);
|
||||
Expression * denominator = m_operands[1]->evaluate(context);
|
||||
if (numerator == nullptr || denominator == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -37,20 +37,20 @@ Expression * Fraction::createEvaluation(Context& context) const {
|
||||
result = new Float(this->approximate(context));
|
||||
}
|
||||
if (numerator->type() == Expression::Type::Matrix && denominator->type() == Expression::Type::Float) {
|
||||
result = createEvaluationOnMatrixAndFloat((Matrix *)numerator, (Float *)denominator, context);
|
||||
result = evaluateOnMatrixAndFloat((Matrix *)numerator, (Float *)denominator, context);
|
||||
}
|
||||
if (numerator->type() == Expression::Type::Float && denominator->type() == Expression::Type::Matrix) {
|
||||
result = nullptr;
|
||||
}
|
||||
if (numerator->type() == Expression::Type::Matrix && denominator->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnMatrices((Matrix *)numerator, (Matrix *)denominator, context);
|
||||
result = evaluateOnMatrices((Matrix *)numerator, (Matrix *)denominator, context);
|
||||
}
|
||||
delete numerator;
|
||||
delete denominator;
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * Fraction::createEvaluationOnMatrixAndFloat(Matrix * m, Float * a, Context& context) const {
|
||||
Expression * Fraction::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& context) const {
|
||||
Expression * operands[m->numberOfRows() * m->numberOfColumns()];
|
||||
for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) {
|
||||
operands[i] = new Float(m->operand(i)->approximate(context)/a->approximate(context));
|
||||
@@ -59,7 +59,7 @@ Expression * Fraction::createEvaluationOnMatrixAndFloat(Matrix * m, Float * a, C
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * Fraction::createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
Expression * Fraction::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
if (m->numberOfColumns() != n->numberOfColumns()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ float Integer::approximate(Context& context) const {
|
||||
return float_result;
|
||||
}
|
||||
|
||||
Expression * Integer::createEvaluation(Context& context) const {
|
||||
Expression * Integer::evaluate(Context& context) const {
|
||||
return new Float(approximate(context));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@ float Logarithm::approximate(Context& context) const {
|
||||
return log10f(m_arg->approximate(context));
|
||||
}
|
||||
|
||||
Expression * Logarithm::createEvaluation(Context& context) const {
|
||||
Expression * Logarithm::evaluate(Context& context) const {
|
||||
return new Float(log10f(m_arg->approximate(context)));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ float Matrix::approximate(Context& context) const {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
Expression * Matrix::createEvaluation(Context& context) const {
|
||||
Expression * Matrix::evaluate(Context& context) const {
|
||||
Expression * operands[numberOfOperands()];
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
operands[i] = new Float(operand(i)->approximate(context));
|
||||
|
||||
@@ -45,8 +45,8 @@ float Parenthesis::approximate(Context& context) const {
|
||||
return m_operand->approximate(context);
|
||||
}
|
||||
|
||||
Expression * Parenthesis::createEvaluation(Context& context) const {
|
||||
return m_operand->createEvaluation(context);
|
||||
Expression * Parenthesis::evaluate(Context& context) const {
|
||||
return m_operand->evaluate(context);
|
||||
}
|
||||
|
||||
Expression::Type Parenthesis::type() const {
|
||||
|
||||
@@ -10,9 +10,9 @@ float Power::approximate(Context& context) const {
|
||||
return powf(m_operands[0]->approximate(context), m_operands[1]->approximate(context));
|
||||
}
|
||||
|
||||
Expression * Power::createEvaluation(Context& context) const {
|
||||
Expression * base = m_operands[0]->createEvaluation(context);
|
||||
Expression * exponent = m_operands[1]->createEvaluation(context);
|
||||
Expression * Power::evaluate(Context& context) const {
|
||||
Expression * base = m_operands[0]->evaluate(context);
|
||||
Expression * exponent = m_operands[1]->evaluate(context);
|
||||
if (base == nullptr || exponent == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ Expression * Power::createEvaluation(Context& context) const {
|
||||
result = new Float(this->approximate(context));
|
||||
}
|
||||
if (base->type() == Expression::Type::Matrix && m_operands[1]->type() == Expression::Type::Integer) {
|
||||
result = createEvaluationOnMatrixAndInteger((Matrix *)base, (Integer *)(m_operands[1]), context);
|
||||
result = evaluateOnMatrixAndInteger((Matrix *)base, (Integer *)(m_operands[1]), context);
|
||||
}
|
||||
delete base;
|
||||
delete exponent;
|
||||
@@ -29,7 +29,7 @@ Expression * Power::createEvaluation(Context& context) const {
|
||||
}
|
||||
|
||||
|
||||
Expression * Power::createEvaluationOnMatrixAndInteger(Matrix * m, Integer * i, Context& context) const {
|
||||
Expression * Power::evaluateOnMatrixAndInteger(Matrix * m, Integer * i, Context& context) const {
|
||||
if (m->numberOfColumns() != m->numberOfRows()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -43,9 +43,10 @@ Expression * Power::createEvaluationOnMatrixAndInteger(Matrix * m, Integer * i,
|
||||
Expression * next = new Product(operands, true);
|
||||
/* We do not need to suppress next, as we suppress result and m is handle by
|
||||
* another scope (TODO: something feels wrong. Check again) */
|
||||
Expression * newResult = next->createEvaluation(context);
|
||||
Expression * newResult = next->evaluate(context);
|
||||
delete result;
|
||||
result = newResult;
|
||||
delete next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ Expression * Product::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return new Product(newOperands, cloneOperands);
|
||||
}
|
||||
|
||||
Expression * Product::createEvaluation(Context& context) const {
|
||||
Expression * leftOperand = m_operands[0]->createEvaluation(context);
|
||||
Expression * rightOperand = m_operands[1]->createEvaluation(context);
|
||||
Expression * Product::evaluate(Context& context) const {
|
||||
Expression * leftOperand = m_operands[0]->evaluate(context);
|
||||
Expression * rightOperand = m_operands[1]->evaluate(context);
|
||||
if (leftOperand == nullptr || rightOperand == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -41,20 +41,20 @@ Expression * Product::createEvaluation(Context& context) const {
|
||||
result = new Float(this->approximate(context));
|
||||
}
|
||||
if (leftOperand->type() == Expression::Type::Matrix && rightOperand->type() == Expression::Type::Float) {
|
||||
result = createEvaluationOnMatrixAndFloat((Matrix *)leftOperand, (Float *)rightOperand, context);
|
||||
result = evaluateOnMatrixAndFloat((Matrix *)leftOperand, (Float *)rightOperand, context);
|
||||
}
|
||||
if (leftOperand->type() == Expression::Type::Float && rightOperand->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnMatrixAndFloat((Matrix *)rightOperand, (Float *)leftOperand, context);
|
||||
result = evaluateOnMatrixAndFloat((Matrix *)rightOperand, (Float *)leftOperand, context);
|
||||
}
|
||||
if (leftOperand->type() == Expression::Type::Matrix && rightOperand->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnMatrices((Matrix *)leftOperand, (Matrix *)rightOperand, context);
|
||||
result = evaluateOnMatrices((Matrix *)leftOperand, (Matrix *)rightOperand, context);
|
||||
}
|
||||
delete leftOperand;
|
||||
delete rightOperand;
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * Product::createEvaluationOnMatrixAndFloat(Matrix * m, Float * a, Context& context) const {
|
||||
Expression * Product::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& context) const {
|
||||
Expression * operands[m->numberOfRows() * m->numberOfColumns()];
|
||||
for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) {
|
||||
operands[i] = new Float(m->operand(i)->approximate(context)*a->approximate(context));
|
||||
@@ -62,7 +62,7 @@ Expression * Product::createEvaluationOnMatrixAndFloat(Matrix * m, Float * a, Co
|
||||
return new Matrix(operands, m->numberOfRows() * m->numberOfColumns(), m->numberOfColumns(), m->numberOfRows(), false);
|
||||
}
|
||||
|
||||
Expression * Product::createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
Expression * Product::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
if (m->numberOfColumns() != n->numberOfRows()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,6 @@ float Sine::approximate(Context& context) const {
|
||||
return sinf(m_arg->approximate(context));
|
||||
}
|
||||
|
||||
Expression * Sine::createEvaluation(Context& context) const {
|
||||
Expression * Sine::evaluate(Context& context) const {
|
||||
return new Float(sinf(m_arg->approximate(context)));
|
||||
}
|
||||
@@ -31,9 +31,9 @@ ExpressionLayout * Subtraction::createLayout() const {
|
||||
return new HorizontalLayout(children_layouts, 3);
|
||||
}
|
||||
|
||||
Expression * Subtraction::createEvaluation(Context& context) const {
|
||||
Expression * leftOperand = m_operands[0]->createEvaluation(context);
|
||||
Expression * rightOperand = m_operands[1]->createEvaluation(context);
|
||||
Expression * Subtraction::evaluate(Context& context) const {
|
||||
Expression * leftOperand = m_operands[0]->evaluate(context);
|
||||
Expression * rightOperand = m_operands[1]->evaluate(context);
|
||||
if (leftOperand == nullptr || rightOperand == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -42,20 +42,20 @@ Expression * Subtraction::createEvaluation(Context& context) const {
|
||||
result = new Float(this->approximate(context));
|
||||
}
|
||||
if (leftOperand->type() == Expression::Type::Matrix && rightOperand->type() == Expression::Type::Float) {
|
||||
result = createEvaluationOnMatrixAndFloat((Matrix *)leftOperand, (Float *)rightOperand, context, true);
|
||||
result = evaluateOnMatrixAndFloat((Matrix *)leftOperand, (Float *)rightOperand, context, true);
|
||||
}
|
||||
if (leftOperand->type() == Expression::Type::Float && rightOperand->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnMatrixAndFloat((Matrix *)rightOperand, (Float *)leftOperand, context, false);
|
||||
result = evaluateOnMatrixAndFloat((Matrix *)rightOperand, (Float *)leftOperand, context, false);
|
||||
}
|
||||
if (leftOperand->type() == Expression::Type::Matrix && rightOperand->type() == Expression::Type::Matrix) {
|
||||
result = createEvaluationOnMatrices((Matrix *)leftOperand, (Matrix *)rightOperand, context);
|
||||
result = evaluateOnMatrices((Matrix *)leftOperand, (Matrix *)rightOperand, context);
|
||||
}
|
||||
delete leftOperand;
|
||||
delete rightOperand;
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * Subtraction::createEvaluationOnMatrixAndFloat(Matrix * m, Float * a, Context& context, bool matrixMinusFloat) const {
|
||||
Expression * Subtraction::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& context, bool matrixMinusFloat) const {
|
||||
Expression * operands[m->numberOfRows() * m->numberOfColumns()];
|
||||
for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) {
|
||||
if (matrixMinusFloat) {
|
||||
@@ -67,7 +67,7 @@ Expression * Subtraction::createEvaluationOnMatrixAndFloat(Matrix * m, Float * a
|
||||
return new Matrix(operands, m->numberOfRows() * m->numberOfColumns(), m->numberOfColumns(), m->numberOfRows(), false);
|
||||
}
|
||||
|
||||
Expression * Subtraction::createEvaluationOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
Expression * Subtraction::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const {
|
||||
if (m->numberOfColumns() != n->numberOfColumns() || m->numberOfRows() != n->numberOfColumns()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ float Symbol::approximate(Context& context) const {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
Expression * Symbol::createEvaluation(Context& context) const {
|
||||
return context.expressionForSymbol(this)->createEvaluation(context);
|
||||
Expression * Symbol::evaluate(Context& context) const {
|
||||
return context.expressionForSymbol(this)->evaluate(context);
|
||||
}
|
||||
|
||||
Expression::Type Symbol::type() const {
|
||||
|
||||
@@ -28,6 +28,6 @@ float Tangent::approximate(Context& context) const {
|
||||
return tanf(m_arg->approximate(context));
|
||||
}
|
||||
|
||||
Expression * Tangent::createEvaluation(Context& context) const {
|
||||
Expression * Tangent::evaluate(Context& context) const {
|
||||
return new Float(tanf(m_arg->approximate(context)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user