HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Moduleinteger-logarithms-1.0.5Haskell2010

Math.NumberTheory.Logarithms

Integer Logarithms. For efficiency, the internal representation of Integers from integer-gmp is used.

Contents
  1. Integer logarithms with input checks
  2. Integer logarithms without input checks
Synopsis

Integer logarithms with input checks

Calculate the integer logarithm for an arbitrary base. The base must be greater than 1, the second argument, the number whose logarithm is sought, must be positive, otherwise an error is thrown. If base == 2, the specialised version is called, which is more efficient than the general algorithm.

Satisfies:

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

for base > 1 and m > 0.

Cacluate the integer logarithm for an arbitrary base. The base must be greater than 1, the second argument, the number whose logarithm is sought, must be positive, otherwise an error is thrown. If base == 2, the specialised version is called, which is more efficient than the general algorithm.

Satisfies:

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

for base > 1 and m > 0.

valueintLog2 :: Int -> Int

Calculate the integer logarithm of an Int to base 2. The argument must be positive, otherwise an error is thrown.

valuewordLog2 :: Word -> Int

Calculate the integer logarithm of a Word to base 2. The argument must be positive, otherwise an error is thrown.

Integer logarithms without input checks

These functions are total, however, don't rely on the values with out-of-domain arguments.