Numworks Epsilon  1.4.1
Graphing Calculator Operating System
frac_part.cpp
Go to the documentation of this file.
1 #include <poincare/frac_part.h>
3 #include <poincare/rational.h>
4 extern "C" {
5 #include <assert.h>
6 }
7 #include <cmath>
8 
9 namespace Poincare {
10 
12  return Type::FracPart;
13 }
14 
16  FracPart * c = new FracPart(m_operands, true);
17  return c;
18 }
19 
20 Expression * FracPart::shallowReduce(Context& context, AngleUnit angleUnit) {
21  Expression * e = Expression::shallowReduce(context, angleUnit);
22  if (e != this) {
23  return e;
24  }
25  Expression * op = editableOperand(0);
26 #if MATRIX_EXACT_REDUCING
27  if (op->type() == Type::Matrix) {
28  return SimplificationEngine::map(this, context, angleUnit);
29  }
30 #endif
31  if (op->type() != Type::Rational) {
32  return this;
33  }
34  Rational * r = static_cast<Rational *>(op);
35  IntegerDivision div = Integer::Division(r->numerator(), r->denominator());
36  return replaceWith(new Rational(div.remainder, r->denominator()), true);
37 }
38 
39 template<typename T>
40 Complex<T> FracPart::computeOnComplex(const Complex<T> c, AngleUnit angleUnit) {
41  if (c.b() != 0) {
42  return Complex<T>::Float(NAN);
43  }
44  return Complex<T>::Float(c.a()-std::floor(c.a()));
45 }
46 
47 }
48 
49 
friend class FracPart
Definition: expression.h:44
#define NAN
Definition: math.h:30
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Definition: expression.cpp:85
Expression * clone() const override
Definition: frac_part.cpp:15
c(generic_all_nodes)
Expression * editableOperand(int i)
Definition: expression.h:176
friend class Rational
Definition: expression.h:18
Type type() const override
Definition: frac_part.cpp:11
const Expression * m_operands[T]
static Complex< T > Float(T x)
Definition: complex.cpp:23
#define floor(x)
Definition: math.h:179
static IntegerDivision Division(const Integer &numerator, const Integer &denominator)
Definition: integer.cpp:281