An Elm library for computing with the natural numbers, ℕ = { 0, 1, 2, ... }.
zeroonetwothreefourfivesixseveneightninetenInt valuesfromIntfromSafeIntString valuesfromBinaryStringfromOctalStringfromHexStringfromString (supports binary, octal, hexadecimal, and decimal input formats)fromSafeStringfromBaseBString==compareisLessThanisLessThanOrEqualisGreaterThanisGreaterThanOrEqualmaxminisZeroisOneisPositiveisEvenisOddaddsub (saturating subtraction)muldivModBy (Euclidean division)divBymodByexpInttoInt (use with caution)String representationtoBinaryStringtoOctalStringtoHexStringtoString (decimal representation)toBaseBStringAs a simple example we can implement the factorial function.
import Natural as N exposing (Natural)
fact : Natural -> Natural
fact n =
if N.isZero n then
N.one
else
N.mul n <| fact (N.sub n N.one)And then we can use it to compute 100!.
N.toString (fact (N.fromSafeInt 100)) == "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"Many more examples can be found in the examples/src directory.
Fibonacci.elm - Computes up to the 1000th Fibonacci number.Pi.elm - Computes the first 100 digits of π.E.elm - Computes the first 100 digits of e.BaseConversion.elm - Converts decimal numbers to their binary, octal, and hexadecimal representations.