integer-gmp-1.0.3.0: Integer library based on GMP
Safe HaskellNone
LanguageHaskell2010

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

wordLog2# :: Word# -> Int# Source #

Compute base-2 log of Word#

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

integerLog2IsPowerOf2# :: Integer -> (# Int#, Int# #) Source #

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.

integerLog2# :: Integer -> Int# Source #

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.