1powerof2(3) Library Functions Manual powerof2(3)
2
3
4
6 powerof2 - test if a value is a power of 2
7
9 Standard C library (libc)
10
12 #include <sys/param.h>
13
14 int powerof2(x);
15
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
23 True or false, if x is a power of 2 or not, respectively.
24
26 BSD.
27
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
37 stdc_bit_ceil(3), stdc_bit_floor(3)
38
39
40
41Linux man-pages 6.05 2023-03-30 powerof2(3)