Numworks Epsilon  1.4.1
Graphing Calculator Operating System
store.cpp
Go to the documentation of this file.
1 extern "C" {
2 #include <assert.h>
3 #include <stdlib.h>
4 #include <math.h>
5 }
6 #include <poincare/store.h>
7 #include <ion.h>
8 #include <poincare/complex.h>
9 #include <poincare/context.h>
11 #include "layout/string_layout.h"
12 
13 namespace Poincare {
14 
16  return Type::Store;
17 }
18 
20  return new Store(operands(), true);
21 }
22 
23 int Store::polynomialDegree(char symbolName) const {
24  return -1;
25 }
26 
27 static_assert('\x8F' == Ion::Charset::Sto, "Incorrect");
28 int Store::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const {
29  return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "\x8F");
30 }
31 
32 Expression * Store::shallowReduce(Context& context, AngleUnit angleUnit) {
33  context.setExpressionForSymbolName(value(), symbol(), context);
34  return replaceWith(editableOperand(1), true)->shallowReduce(context, angleUnit);
35 }
36 
37 ExpressionLayout * Store::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
38  assert(floatDisplayMode != PrintFloat::Mode::Default);
39  assert(complexFormat != ComplexFormat::Default);
40  ExpressionLayout * childrenLayouts[3];
41  childrenLayouts[0] = value()->createLayout(floatDisplayMode, complexFormat);
42  const char stoSymbol[2] = {Ion::Charset::Sto, 0};
43  childrenLayouts[1] = new StringLayout(stoSymbol, 1);
44  childrenLayouts[2] = symbol()->createLayout(floatDisplayMode, complexFormat);
45  return new HorizontalLayout(childrenLayouts, 3);
46 }
47 
48 template<typename T>
49 Expression * Store::templatedApproximate(Context& context, AngleUnit angleUnit) const {
50  context.setExpressionForSymbolName(value(), symbol(), context);
51  if (context.expressionForSymbol(symbol()) != nullptr) {
52  return context.expressionForSymbol(symbol())->approximate<T>(context, angleUnit);
53  }
54  return new Complex<T>(Complex<T>::Float(NAN));
55 }
56 
57 }
static int writeInfixExpressionTextInBuffer(const Expression *expression, char *buffer, int bufferSize, int numberOfDigits, const char *operatorName)
#define NAN
Definition: math.h:30
int polynomialDegree(char symbolName) const override
Definition: store.cpp:23
#define assert(e)
Definition: assert.h:9
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Definition: expression.cpp:85
#define T(x)
Definition: events.cpp:26
const Expression *const * operands() const override
Expression * editableOperand(int i)
Definition: expression.h:176
Type type() const override
Definition: store.cpp:15
ExpressionLayout * createLayout(PrintFloat::Mode floatDisplayMode=PrintFloat::Mode::Default, ComplexFormat complexFormat=ComplexFormat::Default) const
Definition: expression.cpp:244
static Complex< T > Float(T x)
Definition: complex.cpp:23
friend class Store
Definition: expression.h:26
Expression * clone() const override
Definition: store.cpp:19