Handbook
Glossary
next-power-of-2 ( m -- n )
Factor handbook
»
The language
»
Numbers
»
Mathematical functions
»
Integer functions
Prev:
log2 ( x -- n )
Next:
^mod ( x y n -- z )
Vocabulary
math
Inputs
m
a non-negative integer
Outputs
n
an
integer
Word description
Outputs the smallest power of 2 greater than or equal to
m
. The output value is always at least 2.
Definition
USING:
kernel
;
IN:
math
:
next-power-of-2
( m -- n )
dup
2
<=
[
drop
2
]
[
1
-
log2
1
+
2^
]
if
;
inline