Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/util')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c10
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h19
2 files changed, 18 insertions, 11 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c
index d849b4edb..b20444b56 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c
@@ -12,9 +12,11 @@
#include "RandomGenerator.h"
+#ifdef ET_FLOAT64
+
#include "math.h"
-void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, float64 max){
+void RandomGenerator_init(RandomGenerator* self, etFloat64 seed, etFloat64 min, etFloat64 max){
self->seed = seed;
self->min = min;
self->max = max;
@@ -23,12 +25,14 @@ void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, floa
}
-float64 RandomGenerator_getNext(RandomGenerator* self){
+etFloat64 RandomGenerator_getNext(RandomGenerator* self){
self->seed = 1000. * fabs(log(self->seed)); /* shift comma 3 times to get nice values */
- int64 resultInt = self->seed; /* get int number left of comma */
+ etInt64 resultInt = self->seed; /* get int number left of comma */
self->seed = self->seed - resultInt; /* cut off everything left of comma */
self->current = self->seed*self->range + self->min; /* stretch to range */
self->seed += 0.1; /** seed must always be bigger than 0 for log in next iteration */
return self->current;
}
+
+#endif
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h
index 3cda64a74..25e3d1b28 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h
@@ -15,12 +15,14 @@
#include "etDatatypes.h"
+#ifdef ET_FLOAT64
+
typedef struct RandomGenerator {
- float64 seed;
- float64 max;
- float64 min;
- float64 range;
- float64 current;
+ etFloat64 seed;
+ etFloat64 max;
+ etFloat64 min;
+ etFloat64 range;
+ etFloat64 current;
}RandomGenerator;
/**
@@ -35,11 +37,11 @@ typedef struct RandomGenerator {
* (...)
* RandomNumberGenerator rand;
* RandomNumberGenerator_init(&rand, 0.321, -10, 10);
-* float64 result = RandomNumberGenerator_getNext(&rand);
+* etFloat64 result = RandomNumberGenerator_getNext(&rand);
* (...)
* result now holds a random number between -10 and 10;
*/
-void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, float64 max);
+void RandomGenerator_init(RandomGenerator* self, etFloat64 seed, etFloat64 min, etFloat64 max);
/**
* initialze once before use.
@@ -48,7 +50,8 @@ void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, floa
* @return A random number between min and max
*
*/
-float64 RandomGenerator_getNext(RandomGenerator* self);
+etFloat64 RandomGenerator_getNext(RandomGenerator* self);
+#endif
#endif /* RANDOMGENERATOR_H_ */

Back to the top