summaryrefslogtreecommitdiffhomepage
path: root/compat/math.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/math.hpp')
-rw-r--r--compat/math.hpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/compat/math.hpp b/compat/math.hpp
new file mode 100644
index 00000000..c5981cc2
--- /dev/null
+++ b/compat/math.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <cmath>
+#include <type_traits>
+
+template<typename t>
+inline auto iround(t val) -> std::enable_if_t<std::is_floating_point_v<std::decay_t<t>>, int>
+{
+ return (int)std::round(val);
+}
+
+template <typename t>
+constexpr int signum(const t& x)
+{
+ return x < t{0} ? -1 : 1;
+}