From 2087933facdda612d350e5b350e5e9b0a0da2369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20L=C3=BCke?= Date: Mon, 23 Dec 2024 12:59:27 +0100 Subject: [PATCH] move round_up() into mnode_math --- include/mesytec-mnode/mnode_math.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/mesytec-mnode/mnode_math.h diff --git a/include/mesytec-mnode/mnode_math.h b/include/mesytec-mnode/mnode_math.h new file mode 100644 index 0000000..a9693c2 --- /dev/null +++ b/include/mesytec-mnode/mnode_math.h @@ -0,0 +1,18 @@ +#ifndef C536E080_25D7_476D_B8E3_25912B9CFC3B +#define C536E080_25D7_476D_B8E3_25912B9CFC3B + +#include + +namespace mesytec::mnode +{ +// round n up to the nearest multiple of p +// source: https://blog.xoria.org/rounding-up/ +inline int64_t round_up(int64_t n, int64_t p) +{ + int64_t mask = p - 1; + return (n + mask) & ~mask; +} + +} + +#endif /* C536E080_25D7_476D_B8E3_25912B9CFC3B */