Handbook
Glossary
log2 ( x -- n )
Factor handbook
»
The language
»
Numbers
»
Mathematical functions
»
Integer functions
Prev:
gcd ( x y -- a d )
Next:
next-power-of-2 ( m -- n )
Vocabulary
math
Inputs
x
a positive integer
Outputs
n
an
integer
Word description
Outputs the largest integer
n
such that
2^n
is less than or equal to
x
.
Errors
Throws an error if
x
is zero or negative.
Definition
USING:
kernel
math.private
;
IN:
math
:
log2
( x -- n )
dup
0
<=
[
log2-expects-positive
]
[
(log2)
]
if
;
inline