[poincare] Create a class naperian logarithm

Change-Id: Ic71bce73fcb2e915481281a42f5d0a119f89e55e
This commit is contained in:
Émilie Feral
2017-01-18 14:40:39 +01:00
parent f33250f6ff
commit bc3bc0fcd7
6 changed files with 50 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ objs += $(addprefix poincare/src/,\
matrix.o\
matrix_data.o\
multiplication.o\
naperian_logarithm.o\
n_context.o\
nth_root.o\
opposite.o\

View File

@@ -19,6 +19,7 @@
#include <poincare/matrix.h>
#include <poincare/matrix_data.h>
#include <poincare/multiplication.h>
#include <poincare/naperian_logarithm.h>
#include <poincare/n_context.h>
#include <poincare/nth_root.h>
#include <poincare/opposite.h>

View File

@@ -20,6 +20,7 @@ class Expression {
Logarithm,
Matrix,
Multiplication,
NaperianLogarithm,
NthRoot,
Opposite,
Fraction,

View File

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

View File

@@ -88,6 +88,7 @@ cos { poincare_expression_yylval.expression = new Cosine(); return FUNCTION; }
int { poincare_expression_yylval.expression = new Integral(); return FUNCTION; }
tan { poincare_expression_yylval.expression = new Tangent(); return FUNCTION; }
log { poincare_expression_yylval.expression = new Logarithm(); return FUNCTION; }
ln { poincare_expression_yylval.expression = new NaperianLogarithm(); return FUNCTION; }
root { poincare_expression_yylval.expression = new NthRoot(); return FUNCTION; }
sum { poincare_expression_yylval.expression = new Sum(); return FUNCTION; }
product { poincare_expression_yylval.expression = new Product(); return FUNCTION; }

View File

@@ -0,0 +1,31 @@
#include <poincare/naperian_logarithm.h>
extern "C" {
#include <assert.h>
#include <math.h>
#include <stdlib.h>
}
#include "layout/horizontal_layout.h"
#include "layout/parenthesis_layout.h"
#include "layout/string_layout.h"
NaperianLogarithm::NaperianLogarithm() :
Function("ln")
{
}
Expression::Type NaperianLogarithm::type() const {
return Type::NaperianLogarithm;
}
Expression * NaperianLogarithm::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1 || numberOfOperands == 2);
assert(newOperands != nullptr);
NaperianLogarithm * l = new NaperianLogarithm();
l->setArgument(newOperands, numberOfOperands, cloneOperands);
return l;
}
float NaperianLogarithm::approximate(Context& context) const {
return log10f(m_args[0]->approximate(context))/log10f(M_E);
}