mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 00:00:44 +01:00
Merge changes Icbba7712,Ib810a319,I3895897f,I1080cbc4
* changes: [Kandinsky] New glyph for i complex [poincare] Create a class hyperbolic tangent [poincare] Create a class hyperbolic sine [poincare] Create a class hyperbolic cosine
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -15,6 +15,9 @@ objs += $(addprefix poincare/src/,\
|
||||
fraction.o\
|
||||
function.o\
|
||||
global_context.o\
|
||||
hyperbolic_cosine.o\
|
||||
hyperbolic_sine.o\
|
||||
hyperbolic_tangent.o\
|
||||
integer.o\
|
||||
integral.o\
|
||||
list_data.o\
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include <poincare/fraction.h>
|
||||
#include <poincare/function.h>
|
||||
#include <poincare/global_context.h>
|
||||
#include <poincare/hyperbolic_cosine.h>
|
||||
#include <poincare/hyperbolic_sine.h>
|
||||
#include <poincare/hyperbolic_tangent.h>
|
||||
#include <poincare/integer.h>
|
||||
#include <poincare/integral.h>
|
||||
#include <poincare/list_data.h>
|
||||
|
||||
@@ -15,6 +15,9 @@ class Expression {
|
||||
Cosine,
|
||||
Derivative,
|
||||
Float,
|
||||
HyperbolicCosine,
|
||||
HyperbolicSine,
|
||||
HyperbolicTangent,
|
||||
Integer,
|
||||
Integral,
|
||||
Logarithm,
|
||||
|
||||
16
poincare/include/poincare/hyperbolic_cosine.h
Normal file
16
poincare/include/poincare/hyperbolic_cosine.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef POINCARE_HYPERBOLIC_COSINE_H
|
||||
#define POINCARE_HYPERBOLIC_COSINE_H
|
||||
|
||||
#include <poincare/function.h>
|
||||
|
||||
class HyperbolicCosine : public Function {
|
||||
public:
|
||||
HyperbolicCosine();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
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
|
||||
16
poincare/include/poincare/hyperbolic_sine.h
Normal file
16
poincare/include/poincare/hyperbolic_sine.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef POINCARE_HYPERBOLIC_SINE_H
|
||||
#define POINCARE_HYPERBOLIC_SINE_H
|
||||
|
||||
#include <poincare/function.h>
|
||||
|
||||
class HyperbolicSine : public Function {
|
||||
public:
|
||||
HyperbolicSine();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
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
|
||||
16
poincare/include/poincare/hyperbolic_tangent.h
Normal file
16
poincare/include/poincare/hyperbolic_tangent.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef POINCARE_HYPERBOLIC_TANGENT_H
|
||||
#define POINCARE_HYPERBOLIC_TANGENT_H
|
||||
|
||||
#include <poincare/function.h>
|
||||
|
||||
class HyperbolicTangent : public Function {
|
||||
public:
|
||||
HyperbolicTangent();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
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
|
||||
@@ -88,9 +88,12 @@ abs { poincare_expression_yylval.expression = new AbsoluteValue(); return FUNCTI
|
||||
diff { poincare_expression_yylval.expression = new Derivative(); return FUNCTION; }
|
||||
ans { poincare_expression_yylval.character = Symbol::SpecialSymbols::Ans; return SYMBOL; }
|
||||
sin { poincare_expression_yylval.expression = new Sine(); return FUNCTION; }
|
||||
sinh { poincare_expression_yylval.expression = new HyperbolicSine(); return FUNCTION; }
|
||||
cos { poincare_expression_yylval.expression = new Cosine(); return FUNCTION; }
|
||||
cosh { poincare_expression_yylval.expression = new HyperbolicCosine(); return FUNCTION; }
|
||||
int { poincare_expression_yylval.expression = new Integral(); return FUNCTION; }
|
||||
tan { poincare_expression_yylval.expression = new Tangent(); return FUNCTION; }
|
||||
tanh { poincare_expression_yylval.expression = new HyperbolicTangent(); 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; }
|
||||
|
||||
63
poincare/src/hyperbolic_cosine.cpp
Normal file
63
poincare/src/hyperbolic_cosine.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <poincare/hyperbolic_cosine.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/power.h>
|
||||
#include <poincare/fraction.h>
|
||||
#include <poincare/opposite.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
}
|
||||
|
||||
HyperbolicCosine::HyperbolicCosine() :
|
||||
Function("cosh")
|
||||
{
|
||||
}
|
||||
|
||||
Expression::Type HyperbolicCosine::type() const {
|
||||
return Type::HyperbolicCosine;
|
||||
}
|
||||
|
||||
Expression * HyperbolicCosine::cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
assert(numberOfOperands == 1);
|
||||
assert(newOperands != nullptr);
|
||||
HyperbolicCosine * hc = new HyperbolicCosine();
|
||||
hc->setArgument(newOperands, numberOfOperands, cloneOperands);
|
||||
return hc;
|
||||
}
|
||||
|
||||
float HyperbolicCosine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return (expf(m_args[0]->approximate(context, angleUnit))+expf(-m_args[0]->approximate(context, angleUnit)))/2.0f;
|
||||
}
|
||||
|
||||
Expression * HyperbolicCosine::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 Complex(M_E);
|
||||
arguments[1] = evaluation;
|
||||
Expression * exp1 = new Power(arguments, true);
|
||||
arguments[1] = new Opposite(evaluation, true);
|
||||
Expression * exp2 = new Power(arguments, true);
|
||||
delete arguments[1];
|
||||
delete arguments[0];
|
||||
delete evaluation;
|
||||
arguments[0] = exp1;
|
||||
arguments[1] = exp2;
|
||||
Expression * sum = new Addition(arguments, true);
|
||||
delete exp1;
|
||||
delete exp2;
|
||||
arguments[0] = sum;
|
||||
arguments[1] = new Complex(2.0f);
|
||||
Expression * result = new Fraction(arguments, true);
|
||||
delete arguments[1];
|
||||
delete arguments[0];
|
||||
Expression * resultEvaluation = result->evaluate(context, angleUnit);
|
||||
delete result;
|
||||
return resultEvaluation;
|
||||
}
|
||||
63
poincare/src/hyperbolic_sine.cpp
Normal file
63
poincare/src/hyperbolic_sine.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <poincare/hyperbolic_sine.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/subtraction.h>
|
||||
#include <poincare/power.h>
|
||||
#include <poincare/fraction.h>
|
||||
#include <poincare/opposite.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
}
|
||||
|
||||
HyperbolicSine::HyperbolicSine() :
|
||||
Function("sinh")
|
||||
{
|
||||
}
|
||||
|
||||
Expression::Type HyperbolicSine::type() const {
|
||||
return Type::HyperbolicSine;
|
||||
}
|
||||
|
||||
Expression * HyperbolicSine::cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
assert(numberOfOperands == 1);
|
||||
assert(newOperands != nullptr);
|
||||
HyperbolicSine * hs = new HyperbolicSine();
|
||||
hs->setArgument(newOperands, numberOfOperands, cloneOperands);
|
||||
return hs;
|
||||
}
|
||||
|
||||
float HyperbolicSine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return (expf(m_args[0]->approximate(context, angleUnit))-expf(-m_args[0]->approximate(context, angleUnit)))/2.0f;
|
||||
}
|
||||
|
||||
Expression * HyperbolicSine::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 Complex(M_E);
|
||||
arguments[1] = evaluation;
|
||||
Expression * exp1 = new Power(arguments, true);
|
||||
arguments[1] = new Opposite(evaluation, true);
|
||||
Expression * exp2 = new Power(arguments, true);
|
||||
delete arguments[1];
|
||||
delete arguments[0];
|
||||
delete evaluation;
|
||||
arguments[0] = exp1;
|
||||
arguments[1] = exp2;
|
||||
Expression * sub = new Subtraction(arguments, true);
|
||||
delete exp1;
|
||||
delete exp2;
|
||||
arguments[0] = sub;
|
||||
arguments[1] = new Complex(2.0f);
|
||||
Expression * result = new Fraction(arguments, true);
|
||||
delete arguments[1];
|
||||
delete arguments[0];
|
||||
Expression * resultEvaluation = result->evaluate(context, angleUnit);
|
||||
delete result;
|
||||
return resultEvaluation;
|
||||
}
|
||||
53
poincare/src/hyperbolic_tangent.cpp
Normal file
53
poincare/src/hyperbolic_tangent.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <poincare/hyperbolic_tangent.h>
|
||||
#include <poincare/hyperbolic_cosine.h>
|
||||
#include <poincare/hyperbolic_sine.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/fraction.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
}
|
||||
|
||||
HyperbolicTangent::HyperbolicTangent() :
|
||||
Function("tanh")
|
||||
{
|
||||
}
|
||||
|
||||
Expression::Type HyperbolicTangent::type() const {
|
||||
return Type::HyperbolicTangent;
|
||||
}
|
||||
|
||||
Expression * HyperbolicTangent::cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands) const {
|
||||
assert(numberOfOperands == 1);
|
||||
assert(newOperands != nullptr);
|
||||
HyperbolicTangent * ht = new HyperbolicTangent();
|
||||
ht->setArgument(newOperands, numberOfOperands, cloneOperands);
|
||||
return ht;
|
||||
}
|
||||
|
||||
float HyperbolicTangent::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return (expf(m_args[0]->approximate(context, angleUnit))-expf(-m_args[0]->approximate(context, angleUnit)))/
|
||||
(expf(m_args[0]->approximate(context, angleUnit))+expf(-m_args[0]->approximate(context, angleUnit)));
|
||||
}
|
||||
|
||||
Expression * HyperbolicTangent::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 HyperbolicSine();
|
||||
((Function *)arguments[0])->setArgument(&evaluation, 1, true);
|
||||
arguments[1] = new HyperbolicCosine();
|
||||
((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