summaryrefslogtreecommitdiff
path: root/math.h
diff options
context:
space:
mode:
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
*/