Blame view

build2/epsilon-master/poincare/src/randint.cpp 939 Bytes
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
  #include <poincare/randint.h>
  #include <poincare/random.h>
  #include <ion.h>
  
  extern "C" {
  #include <assert.h>
  }
  #include <cmath>
  
  namespace Poincare {
  
  Expression::Type Randint::type() const {
    return Type::Randint;
  }
  
  Expression * Randint::clone() const {
    Randint * a = new Randint(m_operands, true);
    return a;
  }
  
  template <typename T> Evaluation<T> * Randint::templateApproximate(Context & context, AngleUnit angleUnit) const {
    Evaluation<T> * aInput = operand(0)->privateApproximate(T(), context, angleUnit);
    Evaluation<T> * bInput = operand(1)->privateApproximate(T(), context, angleUnit);
    T a = aInput->toScalar();
    T b = bInput->toScalar();
    delete aInput;
    delete bInput;
    if (std::isnan(a) || std::isnan(b) || a != std::round(a) || b != std::round(b) || a > b) {
      return new Complex<T>(Complex<T>::Undefined());
  
    }
    T result = std::floor(Random::random<T>()*(b+1.0-a)+a);
    return new Complex<T>(result);
  }
  
  }