| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 4 |
.\" |
| 5 |
.TH roundup 3 2025-05-17 "Linux man-pages 6.18" |
| 6 |
.SH NAME |
| 7 |
roundup \- round up in steps |
| 8 |
.SH LIBRARY |
| 9 |
Standard C library |
| 10 |
.RI ( libc ) |
| 11 |
.SH SYNOPSIS |
| 12 |
.nf |
| 13 |
.B #include <sys/param.h> |
| 14 |
.P |
| 15 |
.BI roundup( x ", " step ); |
| 16 |
.fi |
| 17 |
.SH DESCRIPTION |
| 18 |
This macro rounds |
| 19 |
.I x |
| 20 |
to the nearest multiple of |
| 21 |
.I step |
| 22 |
that is not less than |
| 23 |
.IR x . |
| 24 |
.P |
| 25 |
It is typically used for |
| 26 |
rounding up a pointer to align it or |
| 27 |
increasing a buffer to be allocated. |
| 28 |
.P |
| 29 |
This API is not designed to be generic, |
| 30 |
and doesn't work in some cases |
| 31 |
that are not important for the typical use cases described above. |
| 32 |
See CAVEATS. |
| 33 |
.SH RETURN VALUE |
| 34 |
This macro returns the rounded value. |
| 35 |
.SH STANDARDS |
| 36 |
None. |
| 37 |
.SH CAVEATS |
| 38 |
The arguments may be evaluated more than once. |
| 39 |
.P |
| 40 |
.I x |
| 41 |
should be nonnegative, |
| 42 |
and |
| 43 |
.I step |
| 44 |
should be positive. |
| 45 |
.P |
| 46 |
If |
| 47 |
.I x + step |
| 48 |
would overflow or wrap around, |
| 49 |
the behavior is undefined. |
| 50 |
.SH SEE ALSO |
| 51 |
.BR ceil (3), |
| 52 |
.BR floor (3), |
| 53 |
.BR lrint (3), |
| 54 |
.BR rint (3), |
| 55 |
.BR lround (3), |
| 56 |
.BR round (3) |