Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2015-07-21 15:33:52 +0000
committerJuergen Haug2015-07-31 10:02:07 +0000
commit33c71f0684c7483aa25428d765ebfb089a954a67 (patch)
tree103aa43a654afbe3fee105de51dff0ca19067c38 /runtime/org.eclipse.etrice.runtime.c/src/util
parenta988c716e9c73a44fc1db44a0ec1d779a60c2599 (diff)
downloadorg.eclipse.etrice-33c71f0684c7483aa25428d765ebfb089a954a67.tar.gz
org.eclipse.etrice-33c71f0684c7483aa25428d765ebfb089a954a67.tar.xz
org.eclipse.etrice-33c71f0684c7483aa25428d765ebfb089a954a67.zip
Bug 472908 - refactor etDatatypes.h
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