integer-logarithms-1.0.3.1: Integer logarithms.
Copyright(c) 2011 Daniel Fischer
LicenseMIT
MaintainerDaniel Fischer <daniel.is.fischer@googlemail.com>
StabilityProvisional
PortabilityNon-portable (GHC extensions)
Safe HaskellTrustworthy
LanguageHaskell2010

GHC.Integer.Logarithms.Compat

Contents

Description

Low level stuff for integer logarithms.

Synopsis

Functions

integerLogBase# :: Integer -> Integer -> Int# #

Calculate the integer logarithm for an arbitrary base.

The base must be greater than 1, the second argument, the number whose logarithm is sought, shall be positive, otherwise the result is meaningless.

The following property holds

base ^ integerLogBase# base m <= m < base ^(integerLogBase# base m + 1)

for base > 1 and m > 0.

Note: Internally uses integerLog2# for base 2

integerLog2# :: Integer -> Int# #

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.

wordLog2# :: Word# -> Int# #

Compute base-2 log of Word#

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