diff --git a/poincare/Makefile b/poincare/Makefile index 4ba299147..653a8db84 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -9,6 +9,7 @@ objs += $(addprefix poincare/src/,\ expression_parser.o\ layout_helper.o\ matrix_complex.o\ + complex.o\ multiplication.o\ power.o\ tree_node.o\ diff --git a/poincare/include/poincare/number.h b/poincare/include/poincare/number.h index 90db1d74b..72e622c56 100644 --- a/poincare/include/poincare/number.h +++ b/poincare/include/poincare/number.h @@ -30,8 +30,8 @@ public: using Expression::Expression; /* Return either a Integer, a Decimal or an Infinity. */ static Number ParseInteger(const char * digits, size_t length, bool negative); - /* Return either a DecimalInteger or an Infinity. */ - template static Number ParseDecimal(T f); + /* Return either a DecimalInteger or an Infinity or an Undefined. */ + template static Number DecimalNumber(T f); /* This set of Functions return either a Rational or a Float * or Infinity in case of overflow. Decimal are not taken into * account as it is not an internal node - it will always be turned into a diff --git a/poincare/src/complex.cpp b/poincare/src/complex.cpp index 324f79b14..21329b0d5 100644 --- a/poincare/src/complex.cpp +++ b/poincare/src/complex.cpp @@ -4,19 +4,18 @@ extern "C" { #include } #include -//#include -//#include +#include #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -24,7 +23,7 @@ namespace Poincare { template ComplexNode * ComplexNode::FailedAllocationStaticNode() { - static AllocationFailureExpressionNode> failure; + static AllocationFailureEvaluationNode failure; TreePool::sharedPool()->registerStaticNodeIfRequired(&failure); return &failure; } @@ -57,18 +56,18 @@ Expression ComplexNode::complexToExpression(Preferences::ComplexFormat comple switch (complexFormat) { case Preferences::ComplexFormat::Cartesian: { - Expression real(nullptr); - Expression imag(nullptr); + Expression real; + Expression imag; if (this->real() != 0 || this->imag() == 0) { - real = Number::Decimal(this->real()); + real = Number::DecimalNumber(this->real()); } if (this->imag() != 0) { if (this->imag() == 1.0 || this->imag() == -1) { imag = Symbol(Ion::Charset::IComplex); } else if (this->imag() > 0) { - imag = Multiplication(Number::Decimal(this->imag()), Symbol(Ion::Charset::IComplex)); + imag = Multiplication(Number::DecimalNumber(this->imag()), Symbol(Ion::Charset::IComplex)); } else { - imag = Multiplication(Number::Decimal(-this->imag()), Symbol(Ion::Charset::IComplex)); + imag = Multiplication(Number::DecimalNumber(-this->imag()), Symbol(Ion::Charset::IComplex)); } } if (!imag.isDefined()) { @@ -89,23 +88,23 @@ Expression ComplexNode::complexToExpression(Preferences::ComplexFormat comple default: { assert(complexFormat == Preferences::ComplexFormat::Polar); - Expression norm(nullptr); - Expression exp(nullptr); + Expression norm; + Expression exp; T r = std::abs(*this); T th = std::arg(*this); if (r != 1 || th == 0) { - norm = Number::Decimal(r); + norm = Number::DecimalNumber(r); } if (r != 0 && th != 0) { - Expression arg(nullptr); + Expression arg; if (th == 1.0) { arg = Symbol(Ion::Charset::IComplex); } else if (th == -1.0) { arg = Opposite(Symbol(Ion::Charset::IComplex)); } else if (th > 0) { - arg = Multiplication(Number::Decimal(th), Symbol(Ion::Charset::IComplex)); + arg = Multiplication(Number::DecimalNumber(th), Symbol(Ion::Charset::IComplex)); } else { - arg = OppositeRefrence(Multiplication(Number::Decimal(-th), Symbol(Ion::Charset::IComplex))); + arg = Opposite(Multiplication(Number::DecimalNumber(-th), Symbol(Ion::Charset::IComplex))); } exp = Power(Symbol(Ion::Charset::Exponential), arg); } @@ -120,11 +119,6 @@ Expression ComplexNode::complexToExpression(Preferences::ComplexFormat comple } } -template -Evaluation ComplexNode::inverse() const { - return Complex(Division::compute(std::complex(1.0), *this)); -} - template Complex::Complex(std::complex c) : Evaluation() diff --git a/poincare/src/number.cpp b/poincare/src/number.cpp index 0ac645367..695a6960c 100644 --- a/poincare/src/number.cpp +++ b/poincare/src/number.cpp @@ -64,7 +64,7 @@ Number Number::ParseInteger(const char * digits, size_t length, bool negative) { } template -Number Number::ParseDecimal(T f) { +Number Number::DecimalNumber(T f) { if (std::isnan(f)) { return Undefined(); }