CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
24 #include <type_traits>
26 namespace catapult {
namespace utils {
31 if (value > std::numeric_limits<T>::max() - delta)
39 template<
typename T,
typename X = std::enable_if_t<std::is_
integral_v<T>>>
41 return static_cast<T>(8u *
sizeof(T));
45 template<
typename T,
typename X = std::enable_if_t<std::is_
unsigned_v<T>>>
46 constexpr T
Log2(T value) {
49 if (!_BitScanReverse(&result, value))
50 return std::numeric_limits<T>::max();
52 return static_cast<T>(result);
55 return std::numeric_limits<T>::max();
57 return static_cast<T>(63 - __builtin_clzll(value));
65 template<
typename T,
typename X = std::enable_if_t<std::is_
unsigned_v<T>>>
66 constexpr T
Pow2(T value) {
67 return value >= GetNumBits<T>() ? 0 : static_cast<T>(static_cast<T>(1) << value);
71 template<
typename T,
typename X = std::enable_if_t<std::is_
unsigned_v<T>>>
73 auto remainder = static_cast<T>(value % divisor);
79 template<
typename T,
typename X = std::enable_if_t<std::is_
unsigned_v<T>>>
81 if (lhs > rhs || 0 != rhs % lhs)
84 T quotient = rhs / lhs;
85 while (quotient > 1) {
constexpr T Pow2(T value)
Calculates 2^(value).
Definition: IntegerMath.h:66
uint64_t Log2TimesPowerOfTwo(uint64_t value, uint64_t n)
Calculates log2(value^(2^n)).
Definition: IntegerMath.cpp:48
constexpr T GetNumBits()
Gets the number of bits in the specified type.
Definition: IntegerMath.h:40
#define CATAPULT_THROW_INVALID_ARGUMENT(MESSAGE)
Macro used to throw a catapult invalid argument.
Definition: exceptions.h:179
Definition: AddressExtractionExtension.cpp:28
constexpr T Log2(T value)
Calculates log2(value).
Definition: IntegerMath.h:46
constexpr bool IsPowerMultiple(T lhs, T rhs, T base)
Returns true if rhs is equal to lhs multipled by a power of base.
Definition: IntegerMath.h:80
constexpr T DivideAndGetRemainder(T &value, T divisor)
Divides value by divisor and returns the remainder.
Definition: IntegerMath.h:72
bool CheckedAdd(T &value, T delta)
Adds delta to value if and only if there is no overflow.
Definition: IntegerMath.h:30