[poincare] parse acos, asin, atan

Change-Id: I1f6c3566315cbe21b5a46c79f3e9dee5123432bb
This commit is contained in:
Émilie Feral
2017-03-09 16:33:52 +01:00
parent d11fede7e3
commit ce66a582b6
10 changed files with 177 additions and 0 deletions

View File

@@ -5,6 +5,9 @@ include poincare/src/simplify/Makefile
objs += $(addprefix poincare/src/,\
absolute_value.o\
addition.o\
arc_cosine.o\
arc_sine.o\
arc_tangent.o\
binary_operation.o\
binomial_coefficient.o\
ceiling.o\

View File

@@ -3,6 +3,9 @@
#include <poincare/absolute_value.h>
#include <poincare/addition.h>
#include <poincare/arc_cosine.h>
#include <poincare/arc_sine.h>
#include <poincare/arc_tangent.h>
#include <poincare/binomial_coefficient.h>
#include <poincare/ceiling.h>
#include <poincare/complex.h>

View File

@@ -0,0 +1,20 @@
#ifndef POINCARE_ARC_COSINE_H
#define POINCARE_ARC_COSINE_H
#include <poincare/function.h>
namespace Poincare {
class ArcCosine : public Function {
public:
ArcCosine();
Type type() const override;
Expression * cloneWithDifferentOperands(Expression ** newOperands,
int numberOfOperands, bool cloneOperands = true) const override;
private:
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
};
}
#endif

View File

@@ -0,0 +1,20 @@
#ifndef POINCARE_ARC_SINE_H
#define POINCARE_ARC_SINE_H
#include <poincare/function.h>
namespace Poincare {
class ArcSine : public Function {
public:
ArcSine();
Type type() const override;
Expression * cloneWithDifferentOperands(Expression ** newOperands,
int numberOfOperands, bool cloneOperands = true) const override;
private:
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
};
}
#endif

View File

@@ -0,0 +1,20 @@
#ifndef POINCARE_ARC_TANGENT_H
#define POINCARE_ARC_TANGENT_H
#include <poincare/function.h>
namespace Poincare {
class ArcTangent: public Function {
public:
ArcTangent();
Type type() const override;
Expression * cloneWithDifferentOperands(Expression ** newOperands,
int numberOfOperands, bool cloneOperands = true) const override;
private:
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
};
}
#endif

View File

@@ -13,6 +13,9 @@ public:
enum class Type : uint8_t {
AbsoluteValue,
Addition,
ArcCosine,
ArcSine,
ArcTangent,
BinomialCoefficient,
Ceiling,
Complex,

View File

@@ -0,0 +1,35 @@
#include <poincare/arc_cosine.h>
extern "C" {
#include <assert.h>
#include <math.h>
}
namespace Poincare {
ArcCosine::ArcCosine() :
Function("acos")
{
}
Expression::Type ArcCosine::type() const {
return Type::ArcCosine;
}
Expression * ArcCosine::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1);
assert(newOperands != nullptr);
ArcCosine * c = new ArcCosine();
c->setArgument(newOperands, numberOfOperands, cloneOperands);
return c;
}
float ArcCosine::privateApproximate(Context& context, AngleUnit angleUnit) const {
assert(angleUnit != AngleUnit::Default);
if (angleUnit == AngleUnit::Degree) {
return acosf(m_args[0]->approximate(context, angleUnit))*180.0f/M_PI;
}
return acosf(m_args[0]->approximate(context, angleUnit));
}
}

35
poincare/src/arc_sine.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include <poincare/arc_sine.h>
extern "C" {
#include <assert.h>
#include <math.h>
}
namespace Poincare {
ArcSine::ArcSine() :
Function("asin")
{
}
Expression::Type ArcSine::type() const {
return Type::ArcSine;
}
Expression * ArcSine::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1);
assert(newOperands != nullptr);
ArcSine * s = new ArcSine();
s->setArgument(newOperands, numberOfOperands, cloneOperands);
return s;
}
float ArcSine::privateApproximate(Context& context, AngleUnit angleUnit) const {
assert(angleUnit != AngleUnit::Default);
if (angleUnit == AngleUnit::Degree) {
return asinf(m_args[0]->approximate(context, angleUnit))*180.0f/M_PI;
}
return asinf(m_args[0]->approximate(context, angleUnit));
}
}

View File

@@ -0,0 +1,35 @@
#include <poincare/arc_tangent.h>
extern "C" {
#include <assert.h>
#include <math.h>
}
namespace Poincare {
ArcTangent::ArcTangent() :
Function("atan")
{
}
Expression::Type ArcTangent::type() const {
return Type::ArcTangent;
}
Expression * ArcTangent::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1);
assert(newOperands != nullptr);
ArcTangent * t = new ArcTangent();
t->setArgument(newOperands, numberOfOperands, cloneOperands);
return t;
}
float ArcTangent::privateApproximate(Context& context, AngleUnit angleUnit) const {
assert(angleUnit != AngleUnit::Default);
if (angleUnit == AngleUnit::Degree) {
return atanf(m_args[0]->approximate(context, angleUnit))*180.0f/M_PI;
}
return atanf(m_args[0]->approximate(context, angleUnit));
}
}

View File

@@ -89,9 +89,12 @@ v\(n\) { poincare_expression_yylval.character = Symbol::SpecialSymbols::vn; retu
v\(n\+1\) { poincare_expression_yylval.character = Symbol::SpecialSymbols::vn1; return SYMBOL; }
w\(n\) { poincare_expression_yylval.character = Symbol::SpecialSymbols::wn; return SYMBOL; }
w\(n\+1\) { poincare_expression_yylval.character = Symbol::SpecialSymbols::wn1; return SYMBOL; }
acos { poincare_expression_yylval.expression = new ArcCosine(); return FUNCTION; }
abs { poincare_expression_yylval.expression = new AbsoluteValue(); return FUNCTION; }
ans { poincare_expression_yylval.character = Symbol::SpecialSymbols::Ans; return SYMBOL; }
arg { poincare_expression_yylval.expression = new ComplexArgument(); return FUNCTION; }
asin { poincare_expression_yylval.expression = new ArcSine(); return FUNCTION; }
atan { poincare_expression_yylval.expression = new ArcTangent(); return FUNCTION; }
binomial { poincare_expression_yylval.expression = new BinomialCoefficient(); return FUNCTION; }
ceil { poincare_expression_yylval.expression = new Ceiling(); return FUNCTION; }
diff { poincare_expression_yylval.expression = new Derivative(); return FUNCTION; }