24#ifndef MYSQL_MATH_INT_POW_H
25#define MYSQL_MATH_INT_POW_H
47template <
class Value_t>
48[[nodiscard]]
constexpr Value_t
int_pow(Value_t base,
unsigned exponent) {
66 if (exponent == 0)
return 1;
67 Value_t ret =
int_pow(base, exponent >> 1);
69 if ((exponent & 1) == 1) ret *= base;
80 requires std::integral<
decltype(base)> && (base >= 2)
83 decltype(base) v = std::numeric_limits<
decltype(base)>
::max();
108template <auto base,
unsigned bound, std::
unsigned_
integral Value_t>
109 requires std::same_as<
decltype(base), Value_t> && (base >= 2)
127 if constexpr (bound == 0)
return 0;
128 constexpr Value_t base_to_power =
int_pow(base, bound);
129 if (
value >= base_to_power) {
157template <auto base, std::
unsigned_
integral Value_t>
158 requires std::same_as<
decltype(base), Value_t> && (base >= 2)
161 constexpr unsigned bound = 1U << (std::bit_width(int_log_max<base>()) - 1);
162 return detail::int_log_helper<base, bound>(
value);
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
constexpr unsigned int_log_helper(Value_t value)
Return the base-base logarithm of value, assuming that value < pow(base, 2 * bound),...
Definition: int_pow.h:110
Definition: bounded_arithmetic.h:34
constexpr unsigned int_log(Value_t value)
Return the base-base logarithm of value.
Definition: int_pow.h:159
constexpr Value_t int_pow(Value_t base, unsigned exponent)
Return pow(base, exponent), where the exponent is an integer.
Definition: int_pow.h:48
constexpr unsigned int_log_max()
Return the floor of the base-base logarithm of numeric_limits<decltype(base>)>max().
Definition: int_pow.h:81