Module

JS.BigInt

Package
purescript-js-bigints
Repository
sigma-andex/purescript-js-bigints

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

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

#fromTLInt Source

fromTLInt :: forall i sym. ToString i sym => Reflectable sym String => Proxy i -> BigInt

Converts a type-level integer into a BigInt:

import Type.Proxy (Proxy(..))
foo = fromTLInt (Proxy :: Proxy 857981209301293808359384092830482)

#asIntN Source

asIntN :: Int -> BigInt -> BigInt

Clamps a BigInt value to the given number of bits, and returns that value as a signed integer.

#asUintN Source

asUintN :: Int -> BigInt -> BigInt

Clamps a BigInt value to the given number of bits, and returns that value as an unsigned integer.

#toString Source

toString :: BigInt -> String

A decimal representation of the BigInt as a String.

#toStringAs Source

#not Source

not :: BigInt -> BigInt

Invert the bits.

#and Source

and :: BigInt -> BigInt -> BigInt

and the bits.

#or Source

or :: BigInt -> BigInt -> BigInt

or the bits.

#shl Source

shl :: BigInt -> BigInt -> BigInt

shift the bits left and zero fill.

#shr Source

shr :: BigInt -> BigInt -> BigInt

Shift the bits right and maintain pos/neg.

#xor Source

xor :: BigInt -> BigInt -> BigInt

Exlusive or the bits.

#even Source

even :: BigInt -> Boolean

Returns whether an BigInt is an even number.

even (fromInt 0) == true
even (fromInt 1) == false

#odd Source

odd :: BigInt -> Boolean

The negation of even.

odd (fromInt 0) == false
odd (fromInt 1) == true

#parity Source

parity :: BigInt -> Parity

Returns whether an BigInt is Even or Odd.

parity (fromInt 0) == Even
parity (fromInt 1) == Odd

Re-exports from Data.Int

#Radix Source

newtype Radix

The number of unique digits (including zero) used to represent integers in a specific base.

#Parity Source

data Parity

A type for describing whether an integer is even or odd.

The Ord instance considers Even to be less than Odd.

The Semiring instance allows you to ask about the parity of the results of arithmetical operations, given only the parities of the inputs. For example, the sum of an odd number and an even number is odd, so Odd + Even == Odd. This also works for multiplication, eg. the product of two odd numbers is odd, and therefore Odd * Odd == Odd.

More generally, we have that

parity x + parity y == parity (x + y)
parity x * parity y == parity (x * y)

for any integers x, y. (A mathematician would say that parity is a ring homomorphism.)

After defining addition and multiplication on Parity in this way, the Semiring laws now force us to choose zero = Even and one = Odd. This Semiring instance actually turns out to be a Field.

Constructors

Instances

#octal Source

octal :: Radix

The base-8 system.

#hexadecimal Source

hexadecimal :: Radix

The base-16 system.

#decimal Source

decimal :: Radix

The base-10 system.

#binary Source

binary :: Radix

The base-2 system.

Modules
JS.BigInt