mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 17:20:53 +01:00
Merge "[poincare] Implement complex evaluation of trigonometric functions"
This commit is contained in:
@@ -10,6 +10,7 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <poincare/cosine.h>
|
||||
|
||||
#include <poincare/hyperbolic_cosine.h>
|
||||
#include <poincare/complex.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -30,4 +31,19 @@ float Cosine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return cosf(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
//TODO: implement evaluate to handle cos complex
|
||||
Expression * Cosine::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
delete evaluation;
|
||||
return new Complex(NAN);
|
||||
}
|
||||
Expression * arg = new Complex(-((Complex *)evaluation)->b(), ((Complex *)evaluation)->a());
|
||||
Function * cosh = new HyperbolicCosine();
|
||||
cosh->setArgument(&arg, 1, true);
|
||||
delete evaluation;
|
||||
delete arg;
|
||||
Expression * resultEvaluation = cosh->evaluate(context, angleUnit);
|
||||
delete cosh;
|
||||
return resultEvaluation;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <poincare/sine.h>
|
||||
|
||||
#include <poincare/hyperbolic_sine.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/multiplication.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -30,4 +32,25 @@ float Sine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return sinf(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
//TODO: implement evaluate to handle sin complex
|
||||
Expression * Sine::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
delete evaluation;
|
||||
return new Complex(NAN);
|
||||
}
|
||||
Expression * arg = new Complex(-((Complex *)evaluation)->b(), ((Complex *)evaluation)->a());
|
||||
Function * sinh = new HyperbolicSine();
|
||||
sinh->setArgument(&arg, 1, true);
|
||||
delete evaluation;
|
||||
delete arg;
|
||||
Expression * args[2];
|
||||
args[0] = new Complex(0.0f, -1.0f);
|
||||
args[1] = sinh;
|
||||
Multiplication * result = new Multiplication(args, true);
|
||||
delete args[0];
|
||||
delete args[1];
|
||||
Expression * resultEvaluation = result->evaluate(context, angleUnit);
|
||||
delete result;
|
||||
return resultEvaluation;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include <poincare/tangent.h>
|
||||
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/sine.h>
|
||||
#include <poincare/cosine.h>
|
||||
#include <poincare/fraction.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -30,4 +33,23 @@ float Tangent::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return tanf(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
//TODO: implement evaluate to handle tan complex
|
||||
Expression * Tangent::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
delete evaluation;
|
||||
return new Complex(NAN);
|
||||
}
|
||||
Expression * arguments[2];
|
||||
arguments[0] = new Sine();
|
||||
((Function *)arguments[0])->setArgument(&evaluation, 1, true);
|
||||
arguments[1] = new Cosine();
|
||||
((Function *)arguments[1])->setArgument(&evaluation, 1, true);
|
||||
delete evaluation;
|
||||
Expression * result = new Fraction(arguments, true);
|
||||
delete arguments[1];
|
||||
delete arguments[0];
|
||||
Expression * resultEvaluation = result->evaluate(context, angleUnit);
|
||||
delete result;
|
||||
return resultEvaluation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user