Skip to content

CEIL_DIV

Description

Ceiling division: divide num by den rounding up. Equivalent to ceil(num / den) for non-negative inputs. Side-effect-free args only – num is evaluated twice.

Parameters

Name Direction Description
num in Dividend.
den in Divisor (non-zero).

Success

Returns the ceiling quotient.

Failure

Function cannot fail. Behaviour is undefined when den is zero.

Usage example (Cross-references)

Usage examples (Cross-references)
    u64 IntByteLength(Int *value) {
        u64 bits = IntBitLength(value);
        return bits == 0 ? 0 : CEIL_DIV(bits, 8u);
    }
    
        u64       bits      = IntBitLength(value);
        u64       bytes     = bits == 0 ? 0 : CEIL_DIV(bits, 8u);
        const u8 *magnitude = (const u8 *)BitVecData(INT_BITS(value));
        for (u64 i = 0; i < bytes; i++) {
    
        u64       bits      = IntBitLength(&value->significand);
        u64       bytes     = bits == 0 ? 0 : CEIL_DIV(bits, 8u);
        const u8 *magnitude = (const u8 *)BitVecData(&value->significand.bits);
        for (u64 i = 0; i < bytes; i++) {
        }
        size slots_per_slab = page_size >> slab->slot_size_shift;
        size words          = CEIL_DIV(slots_per_slab, 64u);
        if (words == 0u) {
            words = 1u; // one slot fits in one bitmap bit; still need one word.
             PTR_ALIGN_UP_POW2((buf_ptr), 8u),                                                                             \
             0,                                                                                                            \
             CEIL_DIV(                                                                                                     \
                 ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) /                      \
                     ALIGN_UP_POW2((slot_size_bytes), (alignment_value)),                                                  \
             .buf_bytes    = (total_bytes),                                                                                \
             .bitmap       = (u64 *)PTR_ALIGN_UP_POW2((buf_ptr), 8u),                                                      \
             .bitmap_words = (u32)CEIL_DIV(                                                                                \
                 ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) /                      \
                     ALIGN_UP_POW2((slot_size_bytes), (alignment_value)),                                                  \
             .slots = (u8 *)ALIGN_UP_POW2(                                                                                 \
                 ALIGN_UP_POW2((u64)(buf_ptr), 8u) +                                                                       \
                     CEIL_DIV(                                                                                             \
                         ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) /              \
                             ALIGN_UP_POW2((slot_size_bytes), (alignment_value)),                                          \
             .slot_count =                                                                                                 \
                 ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr)) -                       \
                  CEIL_DIV(                                                                                                \
                      ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) /                 \
                          ALIGN_UP_POW2((slot_size_bytes), (alignment_value)),                                             \
                  (size)(ALIGN_UP_POW2(                                                                                    \
                             ALIGN_UP_POW2((u64)(buf_ptr), 8u) +                                                           \
                                 CEIL_DIV(                                                                                 \
                                     ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) /  \
                                         ALIGN_UP_POW2((slot_size_bytes), (alignment_value)),                              \
                         ) -                                                                                               \
                         ALIGN_UP_POW2((u64)(buf_ptr), 8u) -                                                               \
                         CEIL_DIV(                                                                                         \
                             ((size)(total_bytes) - (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr))) /          \
                                 ALIGN_UP_POW2((slot_size_bytes), (alignment_value)),                                      \
Last updated on