diff options
| author | Alejandro Colomar <alx@kernel.org> | 2022-12-31 02:58:34 +0100 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2022-12-31 02:58:34 +0100 |
| commit | ca48829aad6801796d212c61add23e4a885786c7 (patch) | |
| tree | b31a59e030fcb7ae3cff9fed2dfca4741d1fdca7 | |
| parent | fca6c89e1c8c0a09b97b1067a36dd7599afba559 (diff) | |
| download | man-pages-ca48829aad6801796d212c61add23e4a885786c7.tar.gz | |
powerof2.3: New page documenting powerof2(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
| -rw-r--r-- | man3/powerof2.3 | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/man3/powerof2.3 b/man3/powerof2.3 new file mode 100644 index 0000000000..04d58dbf89 --- /dev/null +++ b/man3/powerof2.3 @@ -0,0 +1,46 @@ +.\" Copyright (C) 2022 Alejandro Colomar <alx@kernel.org> +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH powerof2 3 (date) "Linux man-pages (unreleased)" +.SH NAME +powerof2 \- test if a value is a power of 2 +.SH LIBRARY +Standard C library +.RI ( libc ) +.SH SYNOPSIS +.nf +.B #include <sys/param.h> +.PP +.BI "int powerof2(" x ); +.fi +.SH DESCRIPTION +This macro returns true if +.I x +is a power of 2, +and false otherwise. +.PP +.B 0 +is considered a power of 2. +This can make sense considering wrapping of unsigned integers, +and has interesting properties. +.SH RETURN VALUE +True or false, +if +.I x +is a power of 2 or not, +respectively. +.SH STANDARDS +This nonstandard macro is present in glibc and the BSDs. +.SH CAVEATS +The arguments may be evaluated more than once. +.PP +Because this macro is implemented using bitwise operations, +some negative values can invoke undefined behavior. +For example, +the following invokes undefined behavior: +.IR "powerof2(INT_MIN);". +Call it only with unsigned types to be safe. +.SH SEE ALSO +.BR stdc_bit_ceil (3), +.BR stdc_bit_floor (3) |
