HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleinteger-logarithms-1.0.4Haskell2010

Math.NumberTheory.Logarithms

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

  • 13 values

Integer logarithms with input checks

8 declarations
valueintegerLogBase :: 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, 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.

valueintegerLog2 :: Integer -> Int
#

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

valueintegerLog10 :: Integer -> Int
#

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

valuenaturalLogBase :: Natural -> Natural -> Int
#

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.

valuenaturalLog2 :: Natural -> Int
#

Calculate the natural logarithm of an Natural to base 2. The argument must be non-zero, otherwise an error is thrown.

valuenaturalLog10 :: Natural -> Int
#

Calculate the integer logarithm of an Integer to base 10. The argument must be not zero, otherwise an error is thrown.

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

5 declarations

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

valueintLog2' :: Int -> Int
#

Same as intLog2, but without checks, saves a little time when called often for known good input.

valuewordLog2' :: Word -> Int
#

Same as wordLog2, but without checks, saves a little time when called often for known good input.