Portability | Non-portable (GHC extensions) |
---|---|

Stability | Provisional |

Maintainer | Daniel Fischer <daniel.is.fischer@googlemail.com> |

Integer Logarithms. For efficiency, the internal representation of `Integer`

s
from integer-gmp is used.

# Integer logarithms with input checks

integerLogBase :: Integer -> Integer -> IntSource

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`

.

integerLog2 :: Integer -> IntSource

Calculate the integer logarithm of an `Integer`

to base 2.
The argument must be positive, otherwise an error is thrown.

Calculate the integer logarithm of an `Int`

to base 2.
The argument must be positive, otherwise an error is thrown.

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

integerLogBase' :: Integer -> Integer -> IntSource

Same as `integerLogBase`

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

integerLog2' :: Integer -> IntSource

Same as `integerLog2`

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

Same as `intLog2`

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