From ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Zrounba?= <6691770+clement-z@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:06:01 +0200 Subject: Initial release --- src/utils/general_utils.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/utils/general_utils.h (limited to 'src/utils/general_utils.h') 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 +#include +#include + +using std::abs; +using std::vector; +using std::cerr; +using std::endl; + +template +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 +vector range(const T &minval, const T &maxval, const T &step) +{ + vector 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 -- cgit v1.2.3