Module

Data.BigInt

Package
purescript-bigints
Repository
sharkdp/purescript-bigints

This module defines a BigInt data type for arbitrary length integers.

#BaseDigits Source

type BaseDigits = { isNegative :: Boolean, value :: NonEmptyArray Int }

#fromString Source

fromString :: String -> Maybe BigInt

Parse a string into a BigInt, assuming a decimal representation. Returns Nothing if the parse fails.

Examples:

fromString "42"
fromString "857981209301293808359384092830482"
fromString "1e100"

#fromBase Source

fromBase :: Int -> String -> Maybe BigInt

Parse a string into a BigInt, assuming a representation in the given base. The letters "a-z" and "A-Z" will be interpreted as the digits 10 to 36. Returns Nothing if the parse fails.

fromBase 2 "100" == fromString "4"
fromBase 16 "ff" == fromString "255"

#fromInt Source

fromInt :: Int -> BigInt

Convert an integer to a BigInt.

#fromNumber Source

fromNumber :: Number -> Maybe BigInt

Convert a Number to a BigInt. The fractional part is truncated.

#toString Source

toString :: BigInt -> String

A decimal representation of the BigInt as a String.

#toNonEmptyString Source

toNonEmptyString :: BigInt -> NonEmptyString

A decimal representation of the BigInt as a NonEmptyString.

#toBase Source

toBase :: Int -> BigInt -> String

A base N representation of the BigInt as a String.

#toBase' Source

toBase' :: Int -> BigInt -> NonEmptyString

A base N representation of the BigInt as a NonEmptyString.

#digitsInBase Source

digitsInBase :: Int -> BigInt -> BaseDigits

A base N representation of the BigInt as an array of digits.

#abs Source

abs :: BigInt -> BigInt

The absolute value.

#even Source

even :: BigInt -> Boolean

Returns true if the number is even, false otherwise.

#odd Source

odd :: BigInt -> Boolean

Returns true if the number is odd, false otherwise.

#prime Source

prime :: BigInt -> Boolean

Returns true if the number is prime, false otherwise.

#pow Source

pow :: BigInt -> BigInt -> BigInt

Exponentiation for BigInt. If the exponent is less than 0, pow returns 0. Also, pow zero zero == one.

#not Source

not :: BigInt -> BigInt

Invert the bits.

#or Source

or :: BigInt -> BigInt -> BigInt

or the bits.

#xor Source

xor :: BigInt -> BigInt -> BigInt

Exlusive or the bits.

#and Source

and :: BigInt -> BigInt -> BigInt

and the bits.

#shl Source

shl :: BigInt -> Number -> BigInt

shift the bits left and zero fill.

#shr Source

shr :: BigInt -> Number -> BigInt

Shift the bits right and maintain pos/neg.

#quot Source

quot :: BigInt -> BigInt -> BigInt

Truncating integer division

#rem Source

rem :: BigInt -> BigInt -> BigInt

The remainder after truncating integer division

#toNumber Source

toNumber :: BigInt -> Number

Converts a BigInt to a Number. Loses precision for numbers which are too large.

Modules
Data.BigInt