Blame view

Giac_maj/epsilon-giac/poincare/src/addition.cpp 2.63 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  #include <poincare/addition.h>
  #include <poincare/complex_matrix.h>
  extern "C" {
  #include <assert.h>
  #include <stdlib.h>
  }
  #include "layout/horizontal_layout.h"
  #include "layout/string_layout.h"
  #include "layout/parenthesis_layout.h"
  
  namespace Poincare {
  
  Expression::Type Addition::type() const {
    return Type::Addition;
  }
  
  ExpressionLayout * Addition::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
    assert(floatDisplayMode != FloatDisplayMode::Default);
    assert(complexFormat != ComplexFormat::Default);
    ExpressionLayout** children_layouts = new ExpressionLayout * [3];
    children_layouts[0] = m_operands[0]->createLayout(floatDisplayMode, complexFormat);
    children_layouts[1] = new StringLayout("+", 1);
    children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(floatDisplayMode, complexFormat)) : m_operands[1]->createLayout(floatDisplayMode, complexFormat);
    ExpressionLayout * layout = new HorizontalLayout(children_layouts, 3);
    delete[] children_layouts;
    return layout;
  }
  
  template<typename T>
  Complex<T> Addition::compute(const Complex<T> c, const Complex<T> d) {
    return Complex<T>::Cartesian(c.a()+d.a(), c.b()+d.b());
  }
  
  template<typename T>
  Evaluation<T> * Addition::computeOnMatrices(Evaluation<T> * m, Evaluation<T> * n) {
    Addition a;
    return a.computeOnComplexMatrices(m,n);
  }
  
  template<typename T>
  Evaluation<T> * Addition::computeOnComplexAndMatrix(const Complex<T> * c, Evaluation<T> * m) {
    Addition a;
    return a.computeOnComplexAndComplexMatrix(c,m);
  }
  
  Expression * Addition::cloneWithDifferentOperands(Expression** newOperands,
      int numberOfOperands, bool cloneOperands) const {
    return new Addition(newOperands, cloneOperands);
  }
  
  bool Addition::isCommutative() const {
    return true;
  }
  
  template Poincare::Complex<float> Poincare::Addition::compute<float>(Poincare::Complex<float>, Poincare::Complex<float>);
  template Poincare::Complex<double> Poincare::Addition::compute<double>(Poincare::Complex<double>, Poincare::Complex<double>);
  
  template Poincare::Evaluation<float>* Poincare::Addition::computeOnMatrices<float>(Poincare::Evaluation<float>*, Poincare::Evaluation<float>*);
  template Poincare::Evaluation<double>* Poincare::Addition::computeOnMatrices<double>(Poincare::Evaluation<double>*, Poincare::Evaluation<double>*);
  
  template Poincare::Evaluation<float>* Poincare::Addition::computeOnComplexAndMatrix<float>(Poincare::Complex<float> const*, Poincare::Evaluation<float>*);
  template Poincare::Evaluation<double>* Poincare::Addition::computeOnComplexAndMatrix<double>(Poincare::Complex<double> const*, Poincare::Evaluation<double>*);
  
  }