aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/utility/NumberUtils.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-09 23:49:54 +0200
committer GitHub <noreply@github.com>2023-09-09 23:49:54 +0200
commit6278a35f4704574933464700026d8deb997da5c1 (patch)
treeeb36a9b030b263d825eb93638e64deb0dbd38a78 /src/openvic-simulation/utility/NumberUtils.hpp
parentbec619fc8f554cb075fcef2428f3b6bdb5e88e82 (diff)
parent3d7fbd9b376811ca0ed226fa78bcc8b6279ba8dc (diff)
Merge pull request #14 from OpenVicProject/dataloading
Dataloading scaffolding + basic culture and pop history loading
Diffstat (limited to 'src/openvic-simulation/utility/NumberUtils.hpp')
-rw-r--r--src/openvic-simulation/utility/NumberUtils.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/openvic-simulation/utility/NumberUtils.hpp b/src/openvic-simulation/utility/NumberUtils.hpp
new file mode 100644
index 0000000..6211772
--- /dev/null
+++ b/src/openvic-simulation/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;
+ }
+}