aboutsummaryrefslogtreecommitdiffstats
path: root/src/wiring/math.cpp
diff options
context:
space:
mode:
authoriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-17 02:37:07 +0000
committeriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-17 02:37:07 +0000
commit32e57dac2e61e79b029593eb4d34d727bcc10678 (patch)
tree98d7ff41993576bb150d13d5f63dc744f6812852 /src/wiring/math.cpp
downloadlibrambutan-32e57dac2e61e79b029593eb4d34d727bcc10678.tar.gz
librambutan-32e57dac2e61e79b029593eb4d34d727bcc10678.zip
Initial commit of library code, moved from leaftest repo
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@69 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/wiring/math.cpp')
-rw-r--r--src/wiring/math.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/wiring/math.cpp b/src/wiring/math.cpp
new file mode 100644
index 0000000..9be7dc3
--- /dev/null
+++ b/src/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;
+}
+
+