1powerof2(3)                Library Functions Manual                powerof2(3)
2
3
4

NAME

6       powerof2 - test if a value is a power of 2
7

LIBRARY

9       Standard C library (libc)
10

SYNOPSIS

12       #include <sys/param.h>
13
14       int powerof2(x);
15

DESCRIPTION

17       This macro returns true if x is a power of 2, and false otherwise.
18
19       0 is considered a power of 2.  This can make sense considering wrapping
20       of unsigned integers, and has interesting properties.
21

RETURN VALUE

23       True or false, if x is a power of 2 or not, respectively.
24

STANDARDS

26       BSD.
27

CAVEATS

29       The arguments may be evaluated more than once.
30
31       Because this macro is implemented using bitwise operations, some  nega‐
32       tive  values can invoke undefined behavior.  For example, the following
33       invokes undefined behavior: powerof2(INT_MIN);.  Call it only with  un‐
34       signed types to be safe.
35

SEE ALSO

37       stdc_bit_ceil(3), stdc_bit_floor(3)
38
39
40
41Linux man-pages 6.04              2023-03-30                       powerof2(3)
Impressum