Integer ceiling division (for unsigned values).
Synopsis
Declared in <util/overflow.h>
template<
std::unsigned_integral Dividend,
std::unsigned_integral Divisor>
[[nodiscard]]
constexpr
auto
CeilDiv(
Dividend const dividend,
Divisor const divisor);
Description
Computes the smallest integer q such that q * divisor >= dividend. Both dividend and divisor must be unsigned, and divisor must be non‐zero.
The implementation avoids overflow that can occur with (dividend + divisor ‐ 1) / divisor.
Return Value
The smallest integer q such that q * divisor >= dividend.
|
Note
|
The return value should not be discarded. |
Parameters
Name |
Description |
dividend |
The value being divided. |
divisor |
The value to divide by, which must be non‐zero. |
Created with MrDocs