Updated: 2022/Sep/29

Please read Privacy Policy. It's for your privacy.

ROUNDUP(9) Kernel Developer's Manual ROUNDUP(9)NAMEroundup- macros for counting and roundingSYNOPSIS#include<sys/param.h>sizehowmany(x, size); sizeroundup(x, size); sizerounddown(x, size); sizeroundup2(x, size); sizerounddown2(x, size); intpowerof2(x);DESCRIPTIONTheroundup() androunddown() macros return an integer from rounding x up and down, respectively, to the next size. Thehowmany() macro in turn reveals how many times size fits into x, rounding the residual up. Theroundup2() androunddown2() macros also round up and down, respectively, but with the assumption that size is a power of two. If x is indeed a power of two,powerof2() return 1.RETURNVALUESThe return value is an integer from the respective operation. If x is 0, all macros exceptpowerof2() return 0. The behavior is undefined if size is 0.EXAMPLESThe following example rounds the variable rx to a 32-bit boundary: uint16_t rx; ... rx = roundup2(rx, sizeof(uint32_t));SEE ALSOilog2(3), param(3), imax(9)CAVEATSAll described macros make no assumptions about the type of the parameters. These are implicitly assumed to be unsigned integers. NetBSD 9.99 October 2, 2019 NetBSD 9.99