BigInt

GitHub   Edit on GitHub

Utilities for working with the BigInt type.

Added in 0.5.0 No other changes yet.
1
import BigInt from "bigint"

Conversions

Functions for converting between Numbers and the BigInt type.

Bigint.fromNumber

Added in 0.5.0 No other changes yet.
1
fromNumber : Number -> BigInt

Converts a Number to a BigInt.

Parameters:

param type description
number Number The value to convert

Returns:

type description
BigInt The Number represented as a BigInt

Bigint.toNumber

Added in 0.5.0 No other changes yet.
1
toNumber : BigInt -> Number

Converts a BigInt to a Number.

Parameters:

param type description
num BigInt The value to convert

Returns:

type description
Number The BigInt represented as a Number

Operations

Mathematical operations for BigInt values.

Bigint.incr

Added in 0.5.0 No other changes yet.
1
incr : BigInt -> BigInt

Increments the value by one.

Parameters:

param type description
num BigInt The value to increment

Returns:

type description
BigInt The incremented value

Bigint.decr

Added in 0.5.0 No other changes yet.
1
decr : BigInt -> BigInt

Decrements the value by one.

Parameters:

param type description
num BigInt The value to decrement

Returns:

type description
BigInt The decremented value

Bigint.neg

Added in 0.5.0 No other changes yet.
1
neg : BigInt -> BigInt

Negates the given operand.

Parameters:

param type description
num BigInt The operand

Returns:

type description
BigInt The negated operand

Bigint.abs

Added in 0.5.0 No other changes yet.
1
abs : BigInt -> BigInt

Returns the absolute value of the given operand.

Parameters:

param type description
num BigInt The operand

Returns:

type description
BigInt The operand’s absolute value

Bigint.add

Added in 0.5.0 No other changes yet.
1
add : (BigInt, BigInt) -> BigInt

Computes the sum of its operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt The sum of the two operands

Bigint.sub

Added in 0.5.0 No other changes yet.
1
sub : (BigInt, BigInt) -> BigInt

Computes the difference of its operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt The difference of the two operands

Bigint.mul

Added in 0.5.0 No other changes yet.
1
mul : (BigInt, BigInt) -> BigInt

Computes the product of its operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt The product of the two operands

Bigint.div

Added in 0.5.0 No other changes yet.
1
div : (BigInt, BigInt) -> BigInt

Computes the quotient of its operands using signed (truncated) division
(in which the quotient is always rounded towards zero).

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt The quotient of its operands

Bigint.rem

Added in 0.5.0 No other changes yet.
1
rem : (BigInt, BigInt) -> BigInt

Computes the remainder of the division of its operands using signed (truncated) division
(in which the quotient is always rounded towards zero).

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt The remainder of its operands

Bigint.quotRem

Added in 0.5.0 No other changes yet.
1
quotRem : (BigInt, BigInt) -> (BigInt, BigInt)

Computes the quotient and remainder of its operands using signed (truncated) division.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
(BigInt, BigInt) The quotient and remainder of its operands

Bigint.gcd

Added in 0.5.0 No other changes yet.
1
gcd : (BigInt, BigInt) -> BigInt

Computes the greatest common divisior of the two operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt The greatest common divisor of its operands

Bitwise operations

Functions for operating on bits of BigInt values.

Bigint.shl

Added in 0.5.0 No other changes yet.
1
shl : (BigInt, Int32) -> BigInt

Shifts the bits of the value left by the given number of bits.

Parameters:

param type description
num BigInt The value to shift
places Int32 The number of bits to shift by

Returns:

type description
BigInt The shifted value

Bigint.shr

Added in 0.5.0 No other changes yet.
1
shr : (BigInt, Int32) -> BigInt

Shifts the bits of the value right by the given number of bits, preserving the sign bit.

Parameters:

param type description
num BigInt The value to shift
places Int32 The amount to shift by

Returns:

type description
BigInt The shifted value

Comparisons

Functions for comparing BigInt values.

Bigint.eqz

Added in 0.5.0 No other changes yet.
1
eqz : BigInt -> Bool

Checks if the given value is equal to zero.

Parameters:

param type description
num BigInt The value to inspect

Returns:

type description
Bool true if the first value is equal to zero or false otherwise

Bigint.eq

Added in 0.5.0 No other changes yet.
1
eq : (BigInt, BigInt) -> Bool

Checks if the first value is equal to the second value.

Parameters:

param type description
num1 BigInt The first value
num2 BigInt The second value

Returns:

type description
Bool true if the first value is equal to the second value or false otherwise

Bigint.ne

Added in 0.5.0 No other changes yet.
1
ne : (BigInt, BigInt) -> Bool

Checks if the first value is not equal to the second value.

Parameters:

param type description
num1 BigInt The first value
num2 BigInt The second value

Returns:

type description
Bool true if the first value is not equal to the second value or false otherwise

Bigint.lt

Added in 0.5.0 No other changes yet.
1
lt : (BigInt, BigInt) -> Bool

Checks if the first value is less than the second value.

Parameters:

param type description
num1 BigInt The first value
num2 BigInt The second value

Returns:

type description
Bool true if the first value is less than the second value or false otherwise

Bigint.lte

Added in 0.5.0 No other changes yet.
1
lte : (BigInt, BigInt) -> Bool

Checks if the first value is less than or equal to the second value.

Parameters:

param type description
num1 BigInt The first value
num2 BigInt The second value

Returns:

type description
Bool true if the first value is less than or equal to the second value or false otherwise

Bigint.gt

Added in 0.5.0 No other changes yet.
1
gt : (BigInt, BigInt) -> Bool

Checks if the first value is greater than the second value.

Parameters:

param type description
num1 BigInt The first value
num2 BigInt The second value

Returns:

type description
Bool true if the first value is greater than the second value or false otherwise

Bigint.gte

Added in 0.5.0 No other changes yet.
1
gte : (BigInt, BigInt) -> Bool

Checks if the first value is greater than or equal to the second value.

Parameters:

param type description
num1 BigInt The first value
num2 BigInt The second value

Returns:

type description
Bool true if the first value is greater than or equal to the second value or false otherwise

Bitwise logic

Boolean operations on the bits of BigInt values.

Bigint.lnot

Added in 0.5.0 No other changes yet.
1
lnot : BigInt -> BigInt

Computes the bitwise NOT of the given value.

Parameters:

param type description
num BigInt The given value

Returns:

type description
BigInt Containing the inverted bits of the given value

Bigint.land

Added in 0.5.0 No other changes yet.
1
land : (BigInt, BigInt) -> BigInt

Computes the bitwise AND (&) on the given operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt Containing a 1 in each bit position for which the corresponding bits of both operands are 1

Bigint.lor

Added in 0.5.0 No other changes yet.
1
lor : (BigInt, BigInt) -> BigInt

Computes the bitwise OR (|) on the given operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt Containing a 1 in each bit position for which the corresponding bits of either or both operands are 1

Bigint.lxor

Added in 0.5.0 No other changes yet.
1
lxor : (BigInt, BigInt) -> BigInt

Computes the bitwise XOR (^) on the given operands.

Parameters:

param type description
num1 BigInt The first operand
num2 BigInt The second operand

Returns:

type description
BigInt Containing a 1 in each bit position for which the corresponding bits of either but not both operands are 1

Bigint.clz

Added in 0.5.0 No other changes yet.
1
clz : BigInt -> Int32

Counts the number of leading zero bits in the value.
Will return the maximum integer for negative numbers.

Parameters:

param type description
num BigInt The value to inspect

Returns:

type description
Int32 The amount of leading zeros

Bigint.ctz

Added in 0.5.0 No other changes yet.
1
ctz : BigInt -> Int64

Counts the number of trailing zero bits in the value.

Parameters:

param type description
num BigInt The value to inspect

Returns:

type description
Int64 The amount of trailing zeros

Bigint.popcnt

Added in 0.5.0 No other changes yet.
1
popcnt : BigInt -> Option<Int64>

Counts the number of bits set to 1 in the value, also known as a population count.
Will return the None if given a negative integer

Parameters:

param type description
num BigInt The value to inspect

Returns:

type description
Option<Int64> The amount of 1-bits in its operand

Other

Other functions on BigInts.

Bigint.toString

Added in 0.5.0 No other changes yet.
1
toString : BigInt -> String

Converts the given operand to a string.

Parameters:

param type description
num BigInt The operand

Returns:

type description
String The operand, as a string
This is a notification!