roundup(9) - NetBSD Manual Pages

Command: Section: Arch: Collection:  
ROUNDUP(9)             NetBSD Kernel Developer's Manual             ROUNDUP(9)

roundup -- macros for counting and rounding
#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);
The roundup() and rounddown() macros return an integer from rounding x up and down, respectively, to the next size. The howmany() macro in turn reveals how many times size fits into x, rounding the residual up. The roundup2() and rounddown2() macros also round up and down, respec- tively, but with the assumption that size is a power of two. If x is indeed a power of two, powerof2() return 1.
The return value is an integer from the respective operation. If x is 0, all macros except powerof2() return 0. The behavior is undefined if size is 0.
The following example rounds the variable rx to a 32-bit boundary: uint16_t rx; ... rx = roundup2(rx, sizeof(uint32_t));
ilog2(3), param(3), imax(9)
All described macros make no assumptions about the type of the parame- ters. These are implicitly assumed to be unsigned integers. NetBSD 9.99 October 2, 2019 NetBSD 9.99
Powered by man-cgi (2020-09-24). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.