aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/utility/NumberUtils.hpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-26 00:25:12 +0200
committer Hop311 <hop3114@gmail.com>2023-09-03 12:53:52 +0200
commit366f1b3941315641bdcb0ee98465b4d2134eee86 (patch)
treeebb1e95b5e874c6eab09f19a323d721fd1fdac1b /src/openvic/utility/NumberUtils.hpp
parentefa88c722fcb6c8fea7a86e1b3b8a83f1f59eb31 (diff)
Followup big dataloader commit
Diffstat (limited to 'src/openvic/utility/NumberUtils.hpp')
-rw-r--r--src/openvic/utility/NumberUtils.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/openvic/utility/NumberUtils.hpp b/src/openvic/utility/NumberUtils.hpp
new file mode 100644
index 0000000..6211772
--- /dev/null
+++ b/src/openvic/utility/NumberUtils.hpp
@@ -0,0 +1,27 @@
+#include <cstdint>
+
+namespace OpenVic::NumberUtils {
+ constexpr int64_t round_to_int64(float num) {
+ return (num > 0.0f) ? (num + 0.5f) : (num - 0.5f);
+ }
+
+ constexpr int64_t round_to_int64(double num) {
+ return (num > 0.0) ? (num + 0.5) : (num - 0.5);
+ }
+
+ constexpr uint64_t pow(uint64_t base, size_t exponent) {
+ uint64_t ret = 1;
+ while (exponent-- > 0) {
+ ret *= base;
+ }
+ return ret;
+ }
+
+ constexpr int64_t pow(int64_t base, size_t exponent) {
+ int64_t ret = 1;
+ while (exponent-- > 0) {
+ ret *= base;
+ }
+ return ret;
+ }
+}