aboutsummaryrefslogtreecommitdiffstats
path: root/core/wiring_math.cpp
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-03-30 22:03:00 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-03-30 22:03:00 -0400
commit2c33d55bae8f9e0e009634072ab05302fc734a65 (patch)
tree63285f96e795fc423cd5bf573340d12f6c8d5513 /core/wiring_math.cpp
parent23149e9706ff0a6a338e13804456dff4c655e34b (diff)
parent1d3861ef93f8423176c6010ab606abdab00a7cbd (diff)
downloadlibrambutan-2c33d55bae8f9e0e009634072ab05302fc734a65.tar.gz
librambutan-2c33d55bae8f9e0e009634072ab05302fc734a65.zip
Merge branch 'master' into rcc-dev
Conflicts: Makefile
Diffstat (limited to 'core/wiring_math.cpp')
-rw-r--r--core/wiring_math.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/core/wiring_math.cpp b/core/wiring_math.cpp
new file mode 100644
index 0000000..9be7dc3
--- /dev/null
+++ b/core/wiring_math.cpp
@@ -0,0 +1,38 @@
+#include <stdlib.h>
+#include "math.h"
+
+/* from newlib:
+ *
+ * rand returns the next pseudo-random integer in sequence; it is a number
+ * between 0 and RAND_MAX (inclusive).
+ *
+ * srand does not return a result. */
+
+
+/* The rest copied from WMath.cpp */
+void randomSeed(unsigned int seed) {
+ if (seed != 0) {
+ srand(seed);
+ }
+}
+
+long random(long howbig) {
+ if (howbig == 0) {
+ return 0;
+ }
+ return rand() % howbig;
+}
+
+long random(long howsmall, long howbig) {
+ if (howsmall >= howbig) {
+ return howsmall;
+ }
+ long diff = howbig - howsmall;
+ return random(diff) + howsmall;
+}
+
+long map(long x, long in_min, long in_max, long out_min, long out_max) {
+ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+