fast-digits-0.3.0.0: Integer-to-digits conversion.

Copyright (c) Andrew Lelechenko 2015-2020 GPL-3 andrew.lelechenko@gmail.com experimental None Haskell2010

Data.FastDigits

Description

Convert an integer to digits and back. This library is both asymptotically (O(n^1.4) vs. O(n^2)) and practically (2x-40x for typical inputs) faster than Data.Digits.

Synopsis

# Documentation

Arguments

 :: Int The base to use -> Integer The number to convert -> [Int] Digits in reverse order

Return digits of a non-negative number in reverse order. Throw an error if number is negative or base is below 2.

digits 10 123 = [3, 2, 1]
digits 10 0   = []

Arguments

 :: (Integral a, Integral b) => a The base to use -> [b] The list of digits to convert -> Integer

Return an integer, built from given digits in reverse order. Condition 0 ≤ digit < base is not checked.

Arguments

 :: Word Precondition that base is ≥2 is not checked -> Natural -> [Word]

Return digits of a non-negative number in reverse order.