integer-log2 ( x -- n ) (original) (raw)

integer-log2 ( x -- n )
Factor handbook » The language » Numbers » Mathematical functions » Integer functions

Prev: divisor? ( m n -- ? )
Next: integer-log10 ( x -- n )

Vocabulary
math.functions

Inputs

x a positive rational number

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: math math.functions.private ;

IN: math.functions

: integer-log2 ( x -- n ) assert-positive (integer-log2) ;
inline