ROUNDUP(9)
β¨ ROUNDUP(9) β¨
okay bestie, welcome to ROUNDUP(9) from the Kernel Developer's Manual β this is the one about macros that count and round, and honestly it's giving math-girlie main character energy π
πΈ NAME πΈ
roundup β macros for counting and rounding. no cap, that's literally it.
π SYNOPSIS π
#include <sys/param.h>
size
howmany(x, size);
size
roundup(x, size);
size
rounddown(x, size);
size
roundup2(x, size);
size
rounddown2(x, size);
int
powerof2(x);
π DESCRIPTION π
so the roundup() and rounddown() macros return an integer from rounding x up and down, respectively, to the next size. and the howmany() macro? it reveals how many times size fits into x, rounding the residual up. periodt.
the roundup2() and rounddown2() macros also round up and down, respectively, but with the assumption that size is a power of two. and if x is indeed a power of two, powerof2() returns 1. slay.
π¦ RETURN VALUES π¦
the return value is an integer from the respective operation. if x is 0, all macros except powerof2() return 0. and the behavior is undefined if size is 0 β like, don't do that, bestie π
π EXAMPLES π
the following example rounds the variable rx to a 32-bit boundary:
uint16_t rx;
...
rx = roundup2(rx, sizeof(uint32_t));
iconic behavior, honestly β¨
π«Ά SEE ALSO π«Ά
π CAVEATS π
all described macros make no assumptions about the type of the parameters. these are implicitly assumed to be unsigned integers. so like, vibe check your types before you send it, fr fr π§
this iconic little page is from Debian, dated October 2, 2019 β and that's the whole manual, bestie. you're welcome π
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms