#include #include #include extern "C" { #include } #include namespace Poincare { Expression::Type Randint::type() const { return Type::Randint; } Expression * Randint::clone() const { Randint * a = new Randint(m_operands, true); return a; } template Expression * Randint::templateApproximate(Context & context, AngleUnit angleUnit) const { Expression * aInput = operand(0)->approximate(context, angleUnit); Expression * bInput = operand(1)->approximate(context, angleUnit); if (aInput->type() != Type::Complex || bInput->type() != Type::Complex) { return new Complex(Complex::Float(NAN)); } T a = static_cast *>(aInput)->toScalar(); T b = static_cast *>(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(Complex::Float(NAN)); } T result = std::floor(Random::random()*(b+1.0-a)+a); return new Complex(Complex::Float(result)); } }