Numworks Epsilon  1.4.1
Graphing Calculator Operating System
absolute_value.cpp
Go to the documentation of this file.
2 #include <poincare/complex.h>
5 
6 extern "C" {
7 #include <assert.h>
8 }
9 #include <cmath>
10 
11 namespace Poincare {
12 
14  return Type::AbsoluteValue;
15 }
16 
18  AbsoluteValue * a = new AbsoluteValue(m_operands, true);
19  return a;
20 }
21 
22 Expression * AbsoluteValue::setSign(Sign s, Context & context, AngleUnit angleUnit) {
23  assert(s == Sign::Positive);
24  return this;
25 }
26 
27 ExpressionLayout * AbsoluteValue::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
28  assert(floatDisplayMode != PrintFloat::Mode::Default);
29  assert(complexFormat != ComplexFormat::Default);
30  return new AbsoluteValueLayout(operand(0)->createLayout(floatDisplayMode, complexFormat));
31 }
32 
33 Expression * AbsoluteValue::shallowReduce(Context& context, AngleUnit angleUnit) {
34  Expression * e = Expression::shallowReduce(context, angleUnit);
35  if (e != this) {
36  return e;
37  }
38  Expression * op = editableOperand(0);
39 #if MATRIX_EXACT_REDUCING
40  if (op->type() == Type::Matrix) {
41  return SimplificationEngine::map(this, context, angleUnit);
42  }
43 #endif
44  if (op->sign() == Sign::Positive) {
45  return replaceWith(op, true);
46  }
47  if (op->sign() == Sign::Negative) {
48  Expression * newOp = op->setSign(Sign::Positive, context, angleUnit);
49  return replaceWith(newOp, true);
50  }
51  return this;
52 }
53 
54 template<typename T>
55 Complex<T> AbsoluteValue::computeOnComplex(const Complex<T> c, AngleUnit angleUnit) {
56  return Complex<T>::Float(c.r());
57 }
58 
59 }
#define assert(e)
Definition: assert.h:9
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Definition: expression.cpp:85
friend class AbsoluteValue
Definition: expression.h:30
c(generic_all_nodes)
Expression * editableOperand(int i)
Definition: expression.h:176
const Expression * m_operands[T]
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
const Expression * operand(int i) const
Definition: expression.cpp:78
Expression * clone() const override
Type type() const override