45 #ifndef MATH_FUNCTION_HPP 46 #define MATH_FUNCTION_HPP 48 #include <boost/version.hpp> 49 #if BOOST_VERSION >= 105800 50 #include <boost/integer/common_factor_rt.hpp> 52 #include <boost/math/common_factor_rt.hpp> 56 #include <type_traits> 64 template <
typename Integer>
67 #if BOOST_VERSION >= 105800 68 return boost::integer::gcd<Integer>(first, second);
70 return boost::math::gcd<Integer>(first, second);
80 template <
typename Integer>
83 #if BOOST_VERSION >= 105800 84 return boost::integer::lcm<Integer>(first, second);
86 return boost::math::lcm<Integer>(first, second);
93 return bitsize / 8 + ((bitsize % 8) != 0);
97 #define EXACT_POWER_OF_2_OR_ZERO_P(x) (((x) & ((x)-1)) == 0) 103 unsigned long long t = 0;
107 return static_cast<T
>(-1LL);
110 if(x >= 1ULL << (t + 32))
114 if(x >= 1ULL << (t + 16))
118 if(x >= 1ULL << (t + 8))
122 if(x >= 1ULL << (t + 4))
126 if(x >= 1ULL << (t + 2))
130 if(x >= 1ULL << (t + 1))
135 return static_cast<T
>(t);
145 return static_cast<T
>(-1LL);
156 return static_cast<T
>(-1LL);
164 std::enable_if_t<std::numeric_limits<T>::digits <= std::numeric_limits<unsigned long long>::digits,
bool> =
true>
165 constexpr
inline T ceil_pow2(T _x)
167 unsigned long long x = _x;
176 return static_cast<T
>(
x);
182 const auto rbw =
std::max(T(8), ceil_pow2(bitsize));
187 return bitsize + ((32ULL - (bitsize % 32ULL)) & 31ULL);
193 return std::max(align, ((bitsize / align) + (bitsize % align != 0)) * align);
199 return bitsize + ((64ULL - (bitsize % 64ULL)) & 63ULL);
209 return std::max(T(8), ceil_pow2(value));
T floor_log2(T x)
Given X, an unsigned number, return the largest int Y such that 2**Y <= X. If X is 0...
constexpr T get_aligned_ac_bitsize(T bitsize)
T resize_1_8_pow2(T value)
static unsigned long long int align(unsigned long long int address, unsigned long long int alignment)
STL includes.
T exact_log2(T x)
Return the logarithm of X, base 2, considering X unsigned, if X is a power of 2.
T ceil_log2(T x)
Return the smallest n such that 2**n >= X.
return static_cast< T >(x)
constexpr T get_aligned_bitsize(T bitsize)
T compute_n_bytes(T bitsize)
Integer LeastCommonMultiple(const Integer first, const Integer second)
Return the least common multiple of two integers.
Integer GreatestCommonDivisor(const Integer first, const Integer second)
Return the greatest common divisor.
x
Return the smallest n such that 2^n >= _x.