|
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...
|
|
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::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
-
T | Data type for the first factor, the maximum, and the result. This must be an unsigned integral. |
T2 | datatype for the second factor. This can be any arithmetic type, including floating point types. |
- Parameters
-
x | The first factor. |
y | The second factor. |
maximum | The maximum allowed value. |
- Returns
- The smallest of (x + y) and (maximum), computed as if using infinite precision arithmetic; or 0 if y is negative.