Module

Data.BigInt

Package
purescript-bigints
Repository
sharkdp/purescript-bigints

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

#fromInt Source

fromInt :: Int -> BigInt

Convert an integer to a BigInt.

#toNumber Source

toNumber :: BigInt -> Number

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

#pow Source

pow :: BigInt -> BigInt -> BigInt

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

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

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

#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"

#toString Source

toString :: BigInt -> String

A decimal representation of the BigInt as a String.

Modules
Data.BigInt