diff options
Diffstat (limited to 'static/netbsd/man9/roundup.9')
| -rw-r--r-- | static/netbsd/man9/roundup.9 | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/static/netbsd/man9/roundup.9 b/static/netbsd/man9/roundup.9 new file mode 100644 index 00000000..af1cf4d2 --- /dev/null +++ b/static/netbsd/man9/roundup.9 @@ -0,0 +1,106 @@ +.\" $NetBSD: roundup.9,v 1.9 2019/10/02 08:21:08 rin Exp $ +.\" +.\" Copyright (c) 2010 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jukka Ruohonen. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 2, 2019 +.Dt ROUNDUP 9 +.Os +.Sh NAME +.Nm roundup +.Nd macros for counting and rounding +.Sh SYNOPSIS +.In sys/param.h +.Ft size +.Fn howmany "x" "size" +.Ft size +.Fn roundup "x" "size" +.Ft size +.Fn rounddown "x" "size" +.Ft size +.Fn roundup2 "x" "size" +.Ft size +.Fn rounddown2 "x" "size" +.Ft int +.Fn powerof2 "x" +.Sh DESCRIPTION +The +.Fn roundup +and +.Fn rounddown +macros return an integer from rounding +.Fa x +up and down, respectively, to the next +.Fa size . +The +.Fn howmany +macro in turn reveals how many times +.Fa size +fits into +.Fa x , +rounding the residual up. +.Pp +The +.Fn roundup2 +and +.Fn rounddown2 +macros also round up and down, respectively, but with the assumption that +.Fa size +is a power of two. +If +.Fa x +is indeed a power of two, +.Fn powerof2 +return 1. +.Sh RETURN VALUES +The return value is an integer from the respective operation. +If +.Fa x +is 0, all macros except +.Fn powerof2 +return 0. +The behavior is undefined if +.Fa size +is 0. +.Sh EXAMPLES +The following example rounds the variable +.Va rx +to a 32-bit boundary: +.Bd -literal -offset indent +uint16_t rx; + +\&... + +rx = roundup2(rx, sizeof(uint32_t)); +.Ed +.Sh SEE ALSO +.Xr ilog2 3 , +.Xr param 3 , +.Xr imax 9 +.Sh CAVEATS +All described macros make no assumptions about the type of the parameters. +These are implicitly assumed to be unsigned integers. |
