summaryrefslogtreecommitdiff
path: root/math.h
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-03-22 10:12:05 +0100
committerLars-Dominik Braun <lars@6xq.net>2015-05-02 21:36:45 +0200
commita093dd0ee969be5150fdff459db385fbc5613452 (patch)
tree2809703489b70d94c7e8fd9deac967abe6ae2bcf /math.h
parent539286a9a5b7663dfba7849328998601816b6f14 (diff)
downloadpucket-a093dd0ee969be5150fdff459db385fbc5613452.tar.gz
pucket-a093dd0ee969be5150fdff459db385fbc5613452.tar.bz2
pucket-a093dd0ee969be5150fdff459db385fbc5613452.zip
Rewrite flam3_random
Disables flam3_mutate.
Diffstat (limited to 'math.h')
-rw-r--r--math.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/math.h b/math.h
index dc72d87..fa49d09 100644
--- a/math.h
+++ b/math.h
@@ -19,6 +19,7 @@
#pragma once
#include <math.h>
+#include <assert.h>
#include "build/config.h"
@@ -79,6 +80,20 @@ inline double sum(const double2 in) {
return in[0] + in[1];
}
+inline void normalize (double * const a, const size_t n) {
+ double sum = 0.0;
+ for (unsigned int j = 0; j < n; j++) {
+ sum += a[j];
+ }
+ assert (sum > 0.0);
+
+ for (unsigned int j = 0; j < n; j++) {
+ a[j] /= sum;
+ }
+}
+
+#define max(a,b) ((a) > (b) ? (a) : (b))
+
/* Vector wrapping function, could be replaced by true vector functions later
*/