From 995c9649cbaa16742ef7c9c20aa58e422ba90a35 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 11 Feb 2019 11:07:06 -0800 Subject: Move some number-related stuff to a separate header --- common/alnumeric.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 common/alnumeric.h (limited to 'common/alnumeric.h') 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 + +inline constexpr int64_t operator "" _i64(unsigned long long int n) noexcept { return static_cast(n); } +inline constexpr uint64_t operator "" _u64(unsigned long long int n) noexcept { return static_cast(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 */ -- cgit v1.2.3