26#ifndef MYSQL_BINLOG_EVENT_MATH_MATH_H
27#define MYSQL_BINLOG_EVENT_MATH_MATH_H
51template <typename T, std::enable_if_t<std::is_integral<T>::value &&
52 std::is_unsigned<T>::value,
54constexpr T
add_bounded(
const T x,
const T y,
const T maximum) {
55 if (y >= maximum || maximum - y < x)
return maximum;
79 typename T,
typename T2,
80 std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value &&
81 std::is_arithmetic<T2>::value,
85 if (y > 1 &&
static_cast<T
>(maximum / y) < x)
return maximum;
86 return static_cast<T
>(x * y);
90template <typename T, std::enable_if_t<std::is_integral<T>::value &&
91 std::is_unsigned<T>::value,
94 return (x + y - 1) / y;
constexpr T multiply_bounded(const T x, const T2 y, const T maximum)
Return x*y, limited to the given maximum.
Definition: math.h:83
constexpr T add_bounded(const T x, const T y, const T maximum)
Return x+y, limited to the given maximum.
Definition: math.h:54
constexpr T ceil_div(const T x, const T y)
Return ceil(x / y), where x and y are unsigned integer types.
Definition: math.h:93