CeilDiv

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

NameDescription
dividendThe value being divided.
divisorThe value to divide by, which must be non-zero.