mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Add a Logarithm expression
Change-Id: Iaf10dec4b298811edaef1cebd04ac0b0175d9025
This commit is contained in:
@@ -16,6 +16,7 @@ objs += $(addprefix poincare/src/,\
|
||||
function.o\
|
||||
integer.o\
|
||||
leaf_expression.o\
|
||||
logarithm.o\
|
||||
power.o\
|
||||
product.o\
|
||||
sine.o\
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -13,7 +13,7 @@ class Expression {
|
||||
Cosine,
|
||||
Float,
|
||||
Integer,
|
||||
Log,
|
||||
Logarithm,
|
||||
Fraction,
|
||||
Power,
|
||||
Product,
|
||||
|
||||
15
poincare/include/poincare/logarithm.h
Normal file
15
poincare/include/poincare/logarithm.h
Normal 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
|
||||
@@ -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); }
|
||||
|
||||
28
poincare/src/logarithm.cpp
Normal file
28
poincare/src/logarithm.cpp
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user