Blame view

Giac_maj/epsilon-giac/poincare/src/sum.cpp 1.27 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
  #include <poincare/sum.h>
  #include <poincare/addition.h>
  #include "layout/sum_layout.h"
  extern "C" {
  #include <assert.h>
  #include <stdlib.h>
  }
  #include <cmath>
  
  namespace Poincare {
  
  Sum::Sum() :
    Sequence("sum")
  {
  }
  
  Expression::Type Sum::type() const {
    return Type::Sum;
  }
  
  Expression * Sum::cloneWithDifferentOperands(Expression** newOperands,
          int numberOfOperands, bool cloneOperands) const {
    assert(newOperands != nullptr);
    Sum * s = new Sum();
    s->setArgument(newOperands, numberOfOperands, cloneOperands);
    return s;
  }
  
  int Sum::emptySequenceValue() const {
    return 0;
  }
  
  ExpressionLayout * Sum::createSequenceLayoutWithArgumentLayouts(ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout, ExpressionLayout * argumentLayout) const {
    return new SumLayout(subscriptLayout, superscriptLayout, argumentLayout);
  }
  
  template<typename T>
  Evaluation<T> * Sum::templatedEvaluateWithNextTerm(Evaluation<T> * a, Evaluation<T> * b) const {
    if (a->numberOfOperands() == 1 && b->numberOfOperands() == 1) {
      return new Complex<T>(Addition::compute(*(a->complexOperand(0)), *(b->complexOperand(0))));
    }
    if (a->numberOfOperands() == 1) {
      return Addition::computeOnComplexAndMatrix(a->complexOperand(0), b);
    }
    return Addition::computeOnMatrices(a, b);
  }
  
  }