PatchworkOS
69292a3
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
new_pow2.c
Go to the documentation of this file.
1
#include <
sys/math.h
>
2
3
uint64_t
next_pow2
(
uint64_t
n)
4
{
5
if
(n <= 1)
6
{
7
return
2;
8
}
9
10
if
((n > 0 && (n & (n - 1)) == 0))
11
{
12
return
n;
13
}
14
15
n--;
16
n |= n >> 1;
17
n |= n >> 2;
18
n |= n >> 4;
19
n |= n >> 8;
20
n |= n >> 16;
21
n |= n >> 32;
22
n++;
23
24
if
(n == 0)
25
{
26
return
(
UINT64_MAX
>> 1) + 1;
27
}
28
29
return
n;
30
}
next_pow2
uint64_t next_pow2(uint64_t n)
Definition
new_pow2.c:3
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
UINT64_MAX
#define UINT64_MAX
Definition
stdint.h:74
math.h
src
libstd
functions
math
new_pow2.c
Generated on Thu Jan 15 2026 15:55:30 for PatchworkOS by
1.9.8