move round_up() into mnode_math
This commit is contained in:
parent
a679f8aca7
commit
2087933fac
1 changed files with 18 additions and 0 deletions
18
include/mesytec-mnode/mnode_math.h
Normal file
18
include/mesytec-mnode/mnode_math.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef C536E080_25D7_476D_B8E3_25912B9CFC3B
|
||||||
|
#define C536E080_25D7_476D_B8E3_25912B9CFC3B
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
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 */
|
Loading…
Reference in a new issue