Home

floorlogk

floorlogk is the floor of the logarithm of a positive number n in base k. Formally, floorlogk(n) = floor(log_k(n)), defined for n > 0 and k > 1. It returns the greatest integer m such that k^m <= n < k^(m+1). The function is nondecreasing in n and increases by 1 whenever n crosses a power of k.

For positive integers, floorlogk(n) is closely related to the base-k representation of n. The number of digits

Computing floorlogk(n) can be done via floating-point arithmetic as floor(log(n)/log(k)), though precautions are needed to avoid

Common applications include analysis of algorithms with logarithmic time or space complexity, estimation of the number

of
n
in
base
k
is
floorlogk(n)
+
1.
For
example,
floorlog2(1)
=
0,
floorlog2(2)
=
1,
floorlog2(3)
=
1,
floorlog10(1000)
=
3,
and
floorlog3(8)
=
1
because
3^1
<=
8
<
3^2.
rounding
errors.
Integer
methods
exist
as
well,
such
as
repeatedly
dividing
n
by
k
to
count
how
many
times
this
is
possible
before
reaching
0
or
1,
or
using
fast
integer
logarithm
algorithms.
of
digits
in
a
given
base,
and
determining
the
size
thresholds
in
data
structures
where
growth
occurs
by
a
constant
factor
k.
The
concept
generalizes
to
real
n
and
to
bases
k
in
(0,1)
with
appropriate
adjustments,
though
standard
usage
typically
assumes
k
>
1
and
n
>
0.