[poincare] Create a class undefined

Change-Id: I0d30b907179f38b77ed65136fddede6e16fb08e1
This commit is contained in:
Émilie Feral
2017-10-06 10:16:18 +02:00
parent 96661a53e2
commit 1ede897a37
6 changed files with 63 additions and 8 deletions

View File

@@ -77,6 +77,7 @@ objs += $(addprefix poincare/src/,\
sum.o\
symbol.o\
tangent.o\
undefined.o\
variable_context.o\
)

View File

@@ -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

View 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

View File

@@ -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++) {

View File

@@ -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++) {

View 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);
}
}