Numworks Epsilon  1.4.1
Graphing Calculator Operating System
random.cpp
Go to the documentation of this file.
1 #include <poincare/random.h>
2 #include <ion.h>
3 
4 extern "C" {
5 #include <assert.h>
6 }
7 #include <cmath>
8 
9 namespace Poincare {
10 
12  return Type::Random;
13 }
14 
16  Random * a = new Random();
17  return a;
18 }
19 
20 Expression * Random::setSign(Sign s, Context & context, AngleUnit angleUnit) {
21  assert(s == Sign::Positive);
22  return this;
23 }
24 
25 template<typename T> T Random::random() {
26  if (sizeof(T) == sizeof(float)) {
27  uint32_t r = Ion::random();
28  return (float)r/(float)(0xFFFFFFFF);
29  } else {
30  assert(sizeof(T) == sizeof(double));
31  uint64_t r;
32  uint32_t * rAddress = (uint32_t *)&r;
33  *rAddress = Ion::random();
34  *(rAddress+1) = Ion::random();
35  return (double)r/(double)(0xFFFFFFFFFFFFFFFF);
36  }
37 }
38 
39 template float Random::random();
40 template double Random::random();
41 
42 }
#define assert(e)
Definition: assert.h:9
#define T(x)
Definition: events.cpp:26
uint32_t random()
Definition: device.cpp:52
static T random()
Definition: random.cpp:25
unsigned int uint32_t
Definition: stdint.h:6
Expression * clone() const override
Definition: random.cpp:15
unsigned long long uint64_t
Definition: stdint.h:7
Type type() const override
Definition: random.cpp:11