[poincare] Parse arg(2+i)

Change-Id: I4e7736e419398be9b7b252d30ac5c9d14ec0c892
This commit is contained in:
Émilie Feral
2017-03-08 15:56:54 +01:00
parent 091bb17cda
commit f58970f590
6 changed files with 69 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ objs += $(addprefix poincare/src/,\
binary_operation.o\
cosine.o\
complex.o\
complex_argument.o\
derivative.o\
determinant.o\
expression.o\

View File

@@ -4,6 +4,7 @@
#include <poincare/absolute_value.h>
#include <poincare/addition.h>
#include <poincare/complex.h>
#include <poincare/complex_argument.h>
#include <poincare/context.h>
#include <poincare/cosine.h>
#include <poincare/derivative.h>

View File

@@ -0,0 +1,21 @@
#ifndef POINCARE_COMPLEX_ARGUMENT_H
#define POINCARE_COMPLEX_ARGUMENT_H
#include <poincare/function.h>
namespace Poincare {
class ComplexArgument : public Function {
public:
ComplexArgument();
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

@@ -14,6 +14,7 @@ public:
AbsoluteValue,
Addition,
Complex,
ComplexArgument,
Cosine,
Derivative,
Determinant,

View File

@@ -0,0 +1,44 @@
#include <poincare/complex_argument.h>
#include <poincare/complex.h>
extern "C" {
#include <assert.h>
#include <math.h>
}
namespace Poincare {
ComplexArgument::ComplexArgument() :
Function("arg")
{
}
Expression::Type ComplexArgument::type() const {
return Type::ComplexArgument;
}
Expression * ComplexArgument::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1);
assert(newOperands != nullptr);
ComplexArgument * ca = new ComplexArgument();
ca->setArgument(newOperands, numberOfOperands, cloneOperands);
return ca;
}
float ComplexArgument::privateApproximate(Context& context, AngleUnit angleUnit) const {
assert(angleUnit != AngleUnit::Default);
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
float result = 0.0f;
if (evaluation->type() == Type::Matrix) {
result = NAN;
} else {
result = ((Complex *)evaluation)->th();
}
delete evaluation;
return result;
}
}

View File

@@ -92,6 +92,7 @@ w\(n\) { poincare_expression_yylval.character = Symbol::SpecialSymbols::wn; retu
w\(n\+1\) { poincare_expression_yylval.character = Symbol::SpecialSymbols::wn1; return SYMBOL; }
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; }
diff { poincare_expression_yylval.expression = new Derivative(); return FUNCTION; }
det { poincare_expression_yylval.expression = new Determinant(); return FUNCTION; }
cos { poincare_expression_yylval.expression = new Cosine(); return FUNCTION; }