integer-gmp-1.0.2.0: Integer library based on GMP

GHC.Integer.Logarithms.Internals

Description

Fast Integer logarithms to base 2. integerLog2# and 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://gitlab.haskell.org/ghc/ghc/issues/5122 for the origin of the code in this module

Synopsis

Documentation

Compute base-2 log of Word#

This is internally implemented as count-leading-zeros machine instruction.

Extended version of integerLog2#

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.