mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 11:39:58 +02:00
[poincare] Create a class undefined
Change-Id: I0d30b907179f38b77ed65136fddede6e16fb08e1
This commit is contained in:
@@ -77,6 +77,7 @@ objs += $(addprefix poincare/src/,\
|
||||
sum.o\
|
||||
symbol.o\
|
||||
tangent.o\
|
||||
undefined.o\
|
||||
variable_context.o\
|
||||
)
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include <poincare/sum.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/tangent.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/variable_context.h>
|
||||
|
||||
#endif
|
||||
|
||||
20
poincare/include/poincare/undefined.h
Normal file
20
poincare/include/poincare/undefined.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef POINCARE_UNDEFINED_H
|
||||
#define POINCARE_UNDEFINED_H
|
||||
|
||||
#include <poincare/static_hierarchy.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Undefined : public StaticHierarchy<0> {
|
||||
public:
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
|
||||
Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override;
|
||||
Evaluation<double> * privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/undefined.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@@ -28,11 +29,10 @@ void Addition::immediateSimplify() {
|
||||
if (o->type() == Type::Addition) {
|
||||
mergeOperands(static_cast<Addition *>(o));
|
||||
index = 0;
|
||||
} else if (o->type() == Type::Undefined) {
|
||||
replaceWith(new Undefined(), true);
|
||||
return;
|
||||
}
|
||||
/* if (o->type() == Type::Undefined) {
|
||||
* replaceWith(new Undefined(), true);
|
||||
* return;
|
||||
* }*/
|
||||
}
|
||||
sortChildren();
|
||||
for (int i = 0; i < numberOfOperands()-1; i++) {
|
||||
|
||||
@@ -9,6 +9,7 @@ extern "C" {
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/power.h>
|
||||
#include <poincare/complex_matrix.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include "layout/string_layout.h"
|
||||
#include "layout/horizontal_layout.h"
|
||||
#include "layout/parenthesis_layout.h"
|
||||
@@ -79,11 +80,10 @@ void Multiplication::immediateSimplify() {
|
||||
} else if (o->type() == Type::Rational && static_cast<const Rational *>(o)->isZero()) {
|
||||
replaceWith(new Rational(Integer(0)), true);
|
||||
return;
|
||||
} else if (o->type() == Type::Undefined) {
|
||||
replaceWith(new Undefined(), true);
|
||||
return;
|
||||
}
|
||||
/* if (o->type() == Type::Undefined) {
|
||||
* replaceWith(new Undefined(), true);
|
||||
* return;
|
||||
* }*/
|
||||
}
|
||||
/* Second loop, distribute addition */
|
||||
for (int i=0; i<numberOfOperands(); i++) {
|
||||
|
||||
33
poincare/src/undefined.cpp
Normal file
33
poincare/src/undefined.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/complex.h>
|
||||
extern "C" {
|
||||
#include <math.h>
|
||||
}
|
||||
#include "layout/string_layout.h"
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
Expression::Type Undefined::type() const {
|
||||
return Type::Undefined;
|
||||
}
|
||||
|
||||
Expression * Undefined::clone() const {
|
||||
return new Undefined();
|
||||
}
|
||||
|
||||
Evaluation<float> * Undefined::privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const {
|
||||
return new Complex<float>(Complex<float>::Float(NAN));
|
||||
}
|
||||
|
||||
Evaluation<double> * Undefined::privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const {
|
||||
return new Complex<double>(Complex<double>::Float(NAN));
|
||||
}
|
||||
|
||||
ExpressionLayout * Undefined::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
char buffer[16];
|
||||
int numberOfChars = Complex<float>::convertFloatToText(NAN, buffer, 16, 0, floatDisplayMode);
|
||||
return new StringLayout(buffer, numberOfChars);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user