BigInt

GitHub   Edit on GitHub

Utilities for working with the BigInt type.

Added in 0.5.0 No other changes yet.
1
from "bigint" include Bigint
1
9223372036854775809t
1
0t
1
-9223372036854775809t

Values

Functions and constants included in the BigInt module.

BigInt.fromNumber

Added in 0.5.0 No other changes yet.
1
fromNumber : (number: 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 : (num: 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

BigInt.incr

Added in 0.5.0 No other changes yet.
1
incr : (num: BigInt) => BigInt

Increments the value by one.

Parameters:

param type description
num BigInt The value to increment

Returns:

type description
BigInt The incremented value

Examples:

1
BigInt.incr(1t) == 2t
1
BigInt.incr(-2t) == -1t

BigInt.decr

Added in 0.5.0 No other changes yet.
1
decr : (num: BigInt) => BigInt

Decrements the value by one.

Parameters:

param type description
num BigInt The value to decrement

Returns:

type description
BigInt The decremented value

Examples:

1
BigInt.decr(2t) == 1t
1
BigInt.decr(-2t) == -3t

BigInt.neg

Added in 0.5.0 No other changes yet.
1
neg : (num: BigInt) => BigInt

Negates the given operand.

Parameters:

param type description
num BigInt The operand

Returns:

type description
BigInt The negated operand

Examples:

1
BigInt.neg(1t) == -1t
1
BigInt.neg(-1t) == 1t

BigInt.abs

Added in 0.5.0 No other changes yet.
1
abs : (num: 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

Examples:

1
BigInt.abs(1t) == 1t
1
BigInt.abs(-1t) == 1t

BigInt.(+)

Added in 0.6.0
versionchanges
0.5.0Originally named `add`
1
(+) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (+) }
assert 1t + 1t == 2t

BigInt.(-)

Added in 0.6.0
versionchanges
0.5.0Originally named `sub`
1
(-) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (-) }
assert 3t - 1t == 2t

BigInt.(*)

Added in 0.6.0
versionchanges
0.5.0Originally named `mul`
1
(*) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (*) }
assert 3t * 3t == 9t

BigInt.(/)

Added in 0.6.0
versionchanges
0.5.0Originally named `div`
1
(/) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (/) }
assert 9t / 3t == 3t

BigInt.rem

Added in 0.5.0 No other changes yet.
1
rem : (num1: BigInt, num2: 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

Examples:

1
BigInt.rem(3t, 2t) == 1t

BigInt.quotRem

Added in 0.5.0 No other changes yet.
1
quotRem : (num1: BigInt, num2: 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

Examples:

1
BigInt.quotRem(7t, 2t) == (3t, 1t))

BigInt.gcd

Added in 0.5.0 No other changes yet.
1
gcd : (num1: BigInt, num2: 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

Examples:

1
BigInt.gcd(36t, 24t) == 12t

BigInt.(<<)

Added in 0.6.0
versionchanges
0.5.0Originally named `shl`
1
(<<) : (num: BigInt, places: 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

Examples:

1
2
use BigInt.{ (<<) }
assert (10t << 2l) == 40t

BigInt.(>>)

Added in 0.6.0
versionchanges
0.5.0Originally named `shr`
1
(>>) : (num: BigInt, places: 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

Examples:

1
2
use BigInt.{ (>>) }
assert (9999t >> 2l) == 2499t

BigInt.eqz

Added in 0.5.0 No other changes yet.
1
eqz : (num: 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

Examples:

1
assert BigInt.eqz(0t) == true
1
assert BigInt.eqz(1t) == false

BigInt.(==)

Added in 0.6.0
versionchanges
0.5.0Originally named `eq`
1
(==) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (==) }
assert 1t == 1t
1
2
use BigInt.{ (==) }
assert -10t == -10t

BigInt.(!=)

Added in 0.6.0
versionchanges
0.5.0Originally named `ne`
1
(!=) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (!=) }
assert 1t != 2t
1
2
use BigInt.{ (!=) }
assert -10t != -20t

BigInt.(<)

Added in 0.6.0
versionchanges
0.5.0Originally named `lt`
1
(<) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (<) }
assert 1t < 2t
1
2
use BigInt.{ (<) }
assert -10t < 0t

BigInt.(<=)

Added in 0.6.0
versionchanges
0.5.0Originally named `lte`
1
(<=) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (<=) }
assert 1t <= 1t
1
2
use BigInt.{ (<=) }
assert -10t <= 0t
1
2
use BigInt.{ (<=) }
assert 2t <= 3t

BigInt.(>)

Added in 0.6.0
versionchanges
0.5.0Originally named `gt`
1
(>) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (>) }
assert 2t > 1t
1
2
use BigInt.{ (>) }
assert 0t > -10t

BigInt.(>=)

Added in 0.6.0
versionchanges
0.5.0Originally named `gte`
1
(>=) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (>=) }
assert 1t >= 1t
1
2
use BigInt.{ (>=) }
assert 0t >= -10t
1
2
use BigInt.{ (>=) }
assert 3t >= 2t

BigInt.lnot

Added in 0.5.0 No other changes yet.
1
lnot : (num: 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

Examples:

1
BigInt.lnot(91234t) == -91235t

BigInt.(&)

Added in 0.6.0
versionchanges
0.5.0Originally named `land`
1
(&) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (&) }
assert (4t & 3t) == 0t

BigInt.(|)

Added in 0.6.0
versionchanges
0.5.0Originally named `lor`
1
(|) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (|) }
assert (5t | 3t) == 7t

BigInt.(^)

Added in 0.6.0
versionchanges
0.5.0Originally named `lxor`
1
(^) : (num1: BigInt, num2: 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

Examples:

1
2
use BigInt.{ (^) }
assert (5t ^ 3t) == 6t

BigInt.clz

Added in 0.5.0 No other changes yet.
1
clz : (num: 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

Examples:

1
BigInt.clz(5t) == 2147483647t

BigInt.ctz

Added in 0.5.0 No other changes yet.
1
ctz : (num: 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

Examples:

1
BigInt.ctz(14t) == 1t

BigInt.popcnt

Added in 0.5.0 No other changes yet.
1
popcnt : (num: 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

Examples:

1
BigInt.popcnt(14t) == 1t

BigInt.toString

Added in 0.5.0 No other changes yet.
1
toString : (num: 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

Examples:

1
BigInt.toString(1t) == "1"
1
BigInt.toString(-1t) == "-1"
This is a notification!