Integer logarithms to base 2.
wordLog2# are of general usefulness, the others are only needed for a fast implementation of
fromRational. Since they are needed in GHC.Float, we must expose this module, but it should not show up in the docs.
See https://ghc.haskell.org/trac/ghc/ticket/5122 for the origin of the code in this module
Compute base-2 log of
This is internally implemented as count-leading-zeros machine instruction.
Extended version of
Assumption: Integer is strictly positive
First component of result is
log2 n, second is
0# iff n is a power of two.
Calculate the integer base 2 logarithm of an
Integer. The calculation is more efficient than for the general case, on platforms with 32- or 64-bit words much more efficient.
The argument must be strictly positive, that condition is not checked.
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).