Numworks Epsilon  1.4.1
Graphing Calculator Operating System
ceiling.cpp
Go to the documentation of this file.
1 #include <poincare/ceiling.h>
3 #include <poincare/symbol.h>
5 #include <poincare/rational.h>
6 #include <ion.h>
7 extern "C" {
8 #include <assert.h>
9 }
10 #include <cmath>
11 
12 namespace Poincare {
13 
15  return Type::Ceiling;
16 }
17 
19  Ceiling * c = new Ceiling(m_operands, true);
20  return c;
21 }
22 
23 Expression * Ceiling::shallowReduce(Context& context, AngleUnit angleUnit) {
24  Expression * e = Expression::shallowReduce(context, angleUnit);
25  if (e != this) {
26  return e;
27  }
28  Expression * op = editableOperand(0);
29 #if MATRIX_EXACT_REDUCING
30  if (op->type() == Type::Matrix) {
31  return SimplificationEngine::map(this, context, angleUnit);
32  }
33 #endif
34  if (op->type() == Type::Symbol) {
35  Symbol * s = static_cast<Symbol *>(op);
36  if (s->name() == Ion::Charset::SmallPi) {
37  return replaceWith(new Rational(4), true);
38  }
39  if (s->name() == Ion::Charset::Exponential) {
40  return replaceWith(new Rational(3), true);
41  }
42  }
43  if (op->type() != Type::Rational) {
44  return this;
45  }
46  Rational * r = static_cast<Rational *>(op);
47  IntegerDivision div = Integer::Division(r->numerator(), r->denominator());
48  if (div.remainder.isZero()) {
49  return replaceWith(new Rational(div.quotient), true);
50  }
51  return replaceWith(new Rational(Integer::Addition(div.quotient, Integer(1))), true);
52 }
53 
54 template<typename T>
55 Complex<T> Ceiling::computeOnComplex(const Complex<T> c, AngleUnit angleUnit) {
56  if (c.b() != 0) {
57  return Complex<T>::Float(NAN);
58  }
59  return Complex<T>::Float(std::ceil(c.a()));
60 }
61 
62 ExpressionLayout * Ceiling::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
63  assert(floatDisplayMode != PrintFloat::Mode::Default);
64  assert(complexFormat != ComplexFormat::Default);
65  return new CeilingLayout(m_operands[0]->createLayout(floatDisplayMode, complexFormat));
66 }
67 
68 }
Type type() const override
Definition: ceiling.cpp:14
#define NAN
Definition: math.h:30
#define assert(e)
Definition: assert.h:9
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Definition: expression.cpp:85
friend class Symbol
Definition: expression.h:72
Expression * clone() const override
Definition: ceiling.cpp:18
friend class Ceiling
Definition: expression.h:35
c(generic_all_nodes)
Expression * editableOperand(int i)
Definition: expression.h:176
friend class Rational
Definition: expression.h:18
static Integer Addition(const Integer &i, const Integer &j)
Definition: integer.cpp:232
const Expression * m_operands[T]
ExpressionLayout * createLayout(PrintFloat::Mode floatDisplayMode=PrintFloat::Mode::Default, ComplexFormat complexFormat=ComplexFormat::Default) const
Definition: expression.cpp:244
#define ceil(x)
Definition: math.h:170
static Complex< T > Float(T x)
Definition: complex.cpp:23
static IntegerDivision Division(const Integer &numerator, const Integer &denominator)
Definition: integer.cpp:281