aboutsummaryrefslogtreecommitdiff
path: root/src/utils/general_utils.h
diff options
context:
space:
mode:
authorClément Zrounba <6691770+clement-z@users.noreply.github.com>2023-09-30 23:06:01 +0200
committerClément Zrounba <6691770+clement-z@users.noreply.github.com>2023-09-30 23:26:46 +0200
commitff9b8bb838ecdfbfc1dc81038fcf3b2a87636982 (patch)
tree21f27be782ce11c6d00b96ce100a2bff88141b2e /src/utils/general_utils.h
downloadspecs-ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982.tar.gz
specs-ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982.zip
Initial release
Diffstat (limited to 'src/utils/general_utils.h')
-rw-r--r--src/utils/general_utils.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/utils/general_utils.h b/src/utils/general_utils.h
new file mode 100644
index 0000000..14757a9
--- /dev/null
+++ b/src/utils/general_utils.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <cmath>
+#include <vector>
+#include <iostream>
+
+using std::abs;
+using std::vector;
+using std::cerr;
+using std::endl;
+
+template <typename T1, typename T2>
+inline bool is_close(const T1& x1, const T2& x2, const double &precision = 1e-12)
+{
+ return abs(x1-x2) < precision;
+}
+
+//double linspace(double minval, double maxval, double npoints);
+
+template <typename T>
+vector<T> range(const T &minval, const T &maxval, const T &step)
+{
+ vector<T> ret;
+ if (maxval <= minval || step <= 0)
+ {
+ cerr << "Invalid range parameters" << endl;
+ // because i don't have time to cover all cases
+ exit(1);
+ }
+ int n = floor((maxval - minval) / step);
+ ret.reserve(n);
+ for (T val = minval; val < maxval; val += step)
+ ret.push_back(val);
+ return ret;
+} \ No newline at end of file