mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Create a class naperian logarithm
Change-Id: Ic71bce73fcb2e915481281a42f5d0a119f89e55e
This commit is contained in:
@@ -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\
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -20,6 +20,7 @@ class Expression {
|
||||
Logarithm,
|
||||
Matrix,
|
||||
Multiplication,
|
||||
NaperianLogarithm,
|
||||
NthRoot,
|
||||
Opposite,
|
||||
Fraction,
|
||||
|
||||
15
poincare/include/poincare/naperian_logarithm.h
Normal file
15
poincare/include/poincare/naperian_logarithm.h
Normal 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
|
||||
@@ -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; }
|
||||
|
||||
31
poincare/src/naperian_logarithm.cpp
Normal file
31
poincare/src/naperian_logarithm.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user