integer-logarithms-1.0.4: Integer logarithms.

Copyright | (c) 2011 Daniel Fischer
License | MIT
Maintainer | Daniel Fischer <daniel.is.fischer@googlemail.com>
Stability | Provisional
Portability | Non-portable (GHC extensions)
Safe Haskell | Trustworthy
Language | Haskell2010

Math.NumberTheory.Logarithms

Contents

- Integer logarithms with input checks
- Integer logarithms without input checks

Description

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

Synopsis

- integerLogBase :: Integer -> Integer -> Int
- integerLog2 :: Integer -> Int
- integerLog10 :: Integer -> Int
- naturalLogBase :: Natural -> Natural -> Int
- naturalLog2 :: Natural -> Int
- naturalLog10 :: Natural -> Int
- intLog2 :: Int -> Int
- wordLog2 :: Word -> Int
- integerLogBase' :: Integer -> Integer -> Int
- integerLog2' :: Integer -> Int
- integerLog10' :: Integer -> Int
- intLog2' :: Int -> Int
- wordLog2' :: Word -> Int

# Integer logarithms with input checks

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

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 -> Int Source #

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

integerLog10 :: Integer -> Int Source #

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

naturalLogBase :: Natural -> Natural -> Int Source #

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`.

naturalLog2 :: Natural -> Int Source #

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

naturalLog10 :: Natural -> Int Source #

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

intLog2 :: Int -> Int Source #

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

wordLog2 :: Word -> Int Source #

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.

integerLogBase' :: Integer -> Integer -> Int Source #

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

integerLog2' :: Integer -> Int Source #

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

integerLog10' :: Integer -> Int Source #

Same as `integerLog10`, but without a check for a positive argument. Saves a little time when called often for known good input.

intLog2' :: Int -> Int Source #

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

wordLog2' :: Word -> Int Source #

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