diff options
author | Chris Robinson <[email protected]> | 2019-02-11 11:07:06 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-02-11 11:07:06 -0800 |
commit | 995c9649cbaa16742ef7c9c20aa58e422ba90a35 (patch) | |
tree | cd924ffb8f5b360964652bb6dd2fc54511a2dc88 /common/alnumeric.h | |
parent | 69d8c6546d1468473f34092727b3ce776a5f89e5 (diff) |
Move some number-related stuff to a separate header
Diffstat (limited to 'common/alnumeric.h')
-rw-r--r-- | common/alnumeric.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/common/alnumeric.h b/common/alnumeric.h new file mode 100644 index 00000000..fb38bff6 --- /dev/null +++ b/common/alnumeric.h @@ -0,0 +1,31 @@ +#ifndef AL_NUMERIC_H +#define AL_NUMERIC_H + +#include <stdint.h> + +inline constexpr int64_t operator "" _i64(unsigned long long int n) noexcept { return static_cast<int64_t>(n); } +inline constexpr uint64_t operator "" _u64(unsigned long long int n) noexcept { return static_cast<uint64_t>(n); } + +/** Find the next power-of-2 for non-power-of-2 numbers. */ +inline uint32_t NextPowerOf2(uint32_t value) noexcept +{ + if(value > 0) + { + value--; + value |= value>>1; + value |= value>>2; + value |= value>>4; + value |= value>>8; + value |= value>>16; + } + return value+1; +} + +/** Round up a value to the next multiple. */ +inline size_t RoundUp(size_t value, size_t r) noexcept +{ + value += r-1; + return value - (value%r); +} + +#endif /* AL_NUMERIC_H */ |