Add hulk.util and round_up_power_2()
This commit is contained in:
1 parent
2ab388f2e9
commit
ea6f485bd9
3 files changed
+23
-4
No files matched your search
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* HULK utility functions.
|
||||
*/
|
||||
module hulk.util;
|
||||
|
||||
/**
|
||||
* Round a value up to the next power of 2.
|
||||
*
|
||||
* @param v Value to round up.
|
||||
* @param p Power of 2 to round up to.
|
||||
*
|
||||
* @return Rounded up value.
|
||||
*/
|
||||
T round_up_power_2(T)(T v, T p)
|
||||
{
|
||||
return (v + p - 1u) & ~(p - 1u);
|
||||
}
|
||||
Reference in new issue
Block a user