cmditch/elm-bigint/2.1.1

NOTE: the latest version is 2.1.2

BigInt

Infinite digits integers

type BigInt

A number with arbitrary size.

From/To

fromInt : Int -> BigInt

Makes a BigInt from an Int

fromIntString : String -> Maybe BigInt

Makes a BigInt from an integer string, positive or negative

fromIntString "123" == Just (BigInt.Pos ...)
fromIntString "-123" == Just (BigInt.Neg ...)
fromIntString "" == Nothing
fromIntString "this is not a number :P" == Nothing
fromHexString : String -> Maybe BigInt

Makes a BigInt from a base16 hex string, positive or negative.

fromHexString "4b6" == Just (BigInt.Pos ...)
fromHexString "-13d" == Just (BigInt.Neg ...)


fromHexString "0x456" == Just (BigInt.Pos ...)
fromHexString "-0x123" == Just (BigInt.Neg ...)


fromHexString "R2D2" == Nothing
fromHexString "0xC3P0" == Nothing
fromHexString "0x" == Nothing
fromHexString "" == Nothing

Note: String can be prepended with or without any combination of "0x", and "+" or "-".

toString : BigInt -> String

Convert the BigInt to an integer string

toHexString : BigInt -> String

Convert the BigInt to a hex string.

toHexString (BigInt.fromInt 255) == "ff"

Note: "0x" will NOT be prepended to the output.

Operations

Adds two BigInts

Substracts the second BigInt from the first

Multiplies two BigInts

BigInt division. Produces 0 when dividing by 0 (like (//)).

modBy : BigInt -> BigInt -> Maybe BigInt

Modulus.

modBy (BigInt.fromInt 3) (BigInt.fromInt 3)

Note: This function returns negative values when the second argument is negative, unlike Basics.modBy.

divmod : BigInt -> BigInt -> Maybe ( BigInt, BigInt )

Division and modulus

Power/Exponentiation.

Compute the Greatest Common Divisors of two numbers.

Sign

Absolute value

Changes the sign of an BigInt

Comparison

compare : BigInt -> BigInt -> Order

Compares two BigInts

gt : BigInt -> BigInt -> Bool

Greater than

gte : BigInt -> BigInt -> Bool

Greater than or equals

lt : BigInt -> BigInt -> Bool

Less than

lte : BigInt -> BigInt -> Bool

Less than or equals

Returns the largest of two BigInts

Returns the smallest of two BigInts

Misc

isEven : BigInt -> Bool

Parity Check - Even.

isOdd : BigInt -> Bool

Parity Check - Odd.