Numworks Epsilon  1.4.1
Graphing Calculator Operating System
random.h
Go to the documentation of this file.
1 #ifndef POINCARE_RANDOM_H
2 #define POINCARE_RANDOM_H
3 
6 #include <poincare/complex.h>
7 
8 namespace Poincare {
9 
10 class Random : public StaticHierarchy<0> {
12 public:
13  Type type() const override;
14  Expression * clone() const override;
15  Sign sign() const override { return Sign::Positive; }
16  template<typename T> static T random();
17 private:
18  Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) override;
19  /* Layout */
20  ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
21  return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
22  }
23  int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
24  return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, name());
25  }
26  const char * name() const { return "random"; }
27  /* Evaluation */
28  Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override {
29  return templateApproximate<float>();
30  }
31  Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override {
32  return templateApproximate<double>();
33  }
34  template <typename T> Expression * templateApproximate() const {
35  return new Complex<T>(Complex<T>::Float(random<T>()));
36  }
37 };
38 
39 }
40 
41 #endif
#define T(x)
Definition: events.cpp:26
static T random()
Definition: random.cpp:25
Expression * clone() const override
Definition: random.cpp:15
Sign sign() const override
Definition: random.h:15
Type type() const override
Definition: random.cpp:11
static ExpressionLayout * createPrefixLayout(const Expression *expression, PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat, const char *operatorName)
static Complex< T > Float(T x)
Definition: complex.cpp:23
static int writePrefixExpressionTextInBuffer(const Expression *expression, char *buffer, int bufferSize, int numberOfDigits, const char *operatorName)