[poincare] Add a Logarithm expression

Change-Id: Iaf10dec4b298811edaef1cebd04ac0b0175d9025
This commit is contained in:
Romain Goyet
2016-10-07 17:11:34 +02:00
parent 4ab77b0ca8
commit ba3eb94be7
6 changed files with 47 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ objs += $(addprefix poincare/src/,\
function.o\
integer.o\
leaf_expression.o\
logarithm.o\
power.o\
product.o\
sine.o\

View File

@@ -9,6 +9,7 @@
#include <poincare/fraction.h>
#include <poincare/function.h>
#include <poincare/integer.h>
#include <poincare/logarithm.h>
#include <poincare/power.h>
#include <poincare/product.h>
#include <poincare/sine.h>

View File

@@ -13,7 +13,7 @@ class Expression {
Cosine,
Float,
Integer,
Log,
Logarithm,
Fraction,
Power,
Product,

View File

@@ -0,0 +1,15 @@
#ifndef POINCARE_LOGARITHM_H
#define POINCARE_LOGARITHM_H
#include <poincare/function.h>
class Logarithm : public Function {
public:
Logarithm();
float approximate(Context & context) const override;
Type type() const override;
Expression * cloneWithDifferentOperands(Expression ** newOperands,
int numberOfOperands, bool cloneOperands = true) const override;
};
#endif

View File

@@ -70,6 +70,7 @@
sin { poincare_expression_yylval.expression = new Sine(); return FUNCTION; }
cos { poincare_expression_yylval.expression = new Cosine(); return FUNCTION; }
tan { poincare_expression_yylval.expression = new Tangent(); return FUNCTION; }
log { poincare_expression_yylval.expression = new Logarithm(); return FUNCTION; }
[A-Za-z]+ { poincare_expression_yylval.string = yytext; return(SYMBOL); }
\+ { return(PLUS); }
\- { return(MINUS); }

View File

@@ -0,0 +1,28 @@
#include <poincare/logarithm.h>
extern "C" {
#include <assert.h>
#include <math.h>
}
Logarithm::Logarithm() :
Function("log")
{
}
Expression::Type Logarithm::type() const {
return Expression::Type::Logarithm;
}
Expression * Logarithm::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1);
assert(newOperands != nullptr);
Logarithm * c = new Logarithm();
c->setArgument(*newOperands, cloneOperands);
return c;
}
float Logarithm::approximate(Context& context) const {
return log10f(m_arg->approximate(context));
}