MySQL 8.3.0
Source Code Documentation
mysql::binlog::event::math Namespace Reference

Functions

template<typename T , std::enable_if_t< std::is_integral< T >::value &&std::is_unsigned< T >::value, bool > = true>
constexpr T add_bounded (const T x, const T y, const T maximum)
 Return x+y, limited to the given maximum. More...
 
template<typename T , typename T2 , std::enable_if_t< std::is_integral< T >::value &&std::is_unsigned< T >::value &&std::is_arithmetic< T2 >::value, bool > = true>
constexpr T multiply_bounded (const T x, const T2 y, const T maximum)
 Return x*y, limited to the given maximum. More...
 
template<typename T , std::enable_if_t< std::is_integral< T >::value &&std::is_unsigned< T >::value, bool > = true>
constexpr T ceil_div (const T x, const T y)
 Return ceil(x / y), where x and y are unsigned integer types. More...
 

Function Documentation

◆ add_bounded()

template<typename T , std::enable_if_t< std::is_integral< T >::value &&std::is_unsigned< T >::value, bool > = true>
constexpr T mysql::binlog::event::math::add_bounded ( const T  x,
const T  y,
const T  maximum 
)
constexpr

Return x+y, limited to the given maximum.

Note
This works even when x+y would exceed the maximum for the datatype.
Template Parameters
TData type. Must be an unsigned integral datatype.
Parameters
xThe first term.
yThe second term.
maximumThe maximum allowed value.
Returns
The smallest of (x + y) and (maximum), computed as if using infinite precision arithmetic.

◆ ceil_div()

template<typename T , std::enable_if_t< std::is_integral< T >::value &&std::is_unsigned< T >::value, bool > = true>
constexpr T mysql::binlog::event::math::ceil_div ( const T  x,
const T  y 
)
constexpr

Return ceil(x / y), where x and y are unsigned integer types.

◆ multiply_bounded()

template<typename T , typename T2 , std::enable_if_t< std::is_integral< T >::value &&std::is_unsigned< T >::value &&std::is_arithmetic< T2 >::value, bool > = true>
constexpr T mysql::binlog::event::math::multiply_bounded ( const T  x,
const T2  y,
const T  maximum 
)
constexpr

Return x*y, limited to the given maximum.

Note
This works even when x * y would exceed the maximum for any of the data type.
Template Parameters
TData type for the first factor, the maximum, and the result. This must be an unsigned integral.
T2datatype for the second factor. This can be any arithmetic type, including floating point types.
Parameters
xThe first factor.
yThe second factor.
maximumThe maximum allowed value.
Returns
The smallest of (x + y) and (maximum), computed as if using infinite precision arithmetic; or 0 if y is negative.