BigInt
Utilities for working with the BigInt type.
Edit on GitHubAdded in 0.5.0
No other changes yet.
from "bigint" include Bigint
9223372036854775809t
0t
-9223372036854775809t
Functions and constants included in the BigInt module.
Added in 0.5.0
No other changes yet.
fromNumber : (number: Number) => BigInt
Converts a Number to a BigInt.
Parameters:
| param | type | description |
|---|---|---|
number | Number | The value to convert |
number: The value to convertReturns:
| type | description |
|---|---|
BigInt | The Number represented as a BigInt |
BigInt: The Number represented as a BigIntAdded in 0.5.0
No other changes yet.
toNumber : (num: BigInt) => Number
Converts a BigInt to a Number.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The value to convert |
num: The value to convertReturns:
| type | description |
|---|---|
Number | The BigInt represented as a Number |
Number: The BigInt represented as a NumberAdded in 0.5.0
No other changes yet.
incr : (num: BigInt) => BigInt
Increments the value by one.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The value to increment |
num: The value to incrementReturns:
| type | description |
|---|---|
BigInt | The incremented value |
BigInt: The incremented valueExamples:
BigInt.incr(1t) == 2t
BigInt.incr(-2t) == -1t
Added in 0.5.0
No other changes yet.
decr : (num: BigInt) => BigInt
Decrements the value by one.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The value to decrement |
num: The value to decrementReturns:
| type | description |
|---|---|
BigInt | The decremented value |
BigInt: The decremented valueExamples:
BigInt.decr(2t) == 1t
BigInt.decr(-2t) == -3t
Added in 0.5.0
No other changes yet.
neg : (num: BigInt) => BigInt
Negates the given operand.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The operand |
num: The operandReturns:
| type | description |
|---|---|
BigInt | The negated operand |
BigInt: The negated operandExamples:
BigInt.neg(1t) == -1t
BigInt.neg(-1t) == 1t
Added in 0.5.0
No other changes yet.
abs : (num: BigInt) => BigInt
Returns the absolute value of the given operand.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The operand |
num: The operandReturns:
| type | description |
|---|---|
BigInt | The operand’s absolute value |
BigInt: The operand’s absolute valueExamples:
BigInt.abs(1t) == 1t
BigInt.abs(-1t) == 1t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `add` |
(+) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | The sum of the two operands |
BigInt: The sum of the two operandsExamples:
use BigInt.{ (+) }
assert 1t + 1t == 2t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `sub` |
(-) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | The difference of the two operands |
BigInt: The difference of the two operandsExamples:
use BigInt.{ (-) }
assert 3t - 1t == 2t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `mul` |
(*) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | The product of the two operands |
BigInt: The product of the two operandsExamples:
use BigInt.{ (*) }
assert 3t * 3t == 9t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `div` |
(/) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | The quotient of its operands |
BigInt: The quotient of its operandsExamples:
use BigInt.{ (/) }
assert 9t / 3t == 3t
Added in 0.5.0
No other changes yet.
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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | The remainder of its operands |
BigInt: The remainder of its operandsExamples:
BigInt.rem(3t, 2t) == 1t
Added in 0.5.0
No other changes yet.
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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
(BigInt, BigInt) | The quotient and remainder of its operands |
(BigInt, BigInt): The quotient and remainder of its operandsExamples:
BigInt.quotRem(7t, 2t) == (3t, 1t))
Added in 0.5.0
No other changes yet.
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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | The greatest common divisor of its operands |
BigInt: The greatest common divisor of its operandsExamples:
BigInt.gcd(36t, 24t) == 12t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `shl` |
(<<) : (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 |
num: The value to shiftplaces: The number of bits to shift byReturns:
| type | description |
|---|---|
BigInt | The shifted value |
BigInt: The shifted valueExamples:
use BigInt.{ (<<) }
assert (10t << 2l) == 40t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `shr` |
(>>) : (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 |
num: The value to shiftplaces: The amount to shift byReturns:
| type | description |
|---|---|
BigInt | The shifted value |
BigInt: The shifted valueExamples:
use BigInt.{ (>>) }
assert (9999t >> 2l) == 2499t
Added in 0.5.0
No other changes yet.
eqz : (num: BigInt) => Bool
Checks if the given value is equal to zero.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The value to inspect |
num: The value to inspectReturns:
| type | description |
|---|---|
Bool | true if the first value is equal to zero or false otherwise |
Bool: true if the first value is equal to zero or false otherwiseExamples:
assert BigInt.eqz(0t) == true
assert BigInt.eqz(1t) == false
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `eq` |
(==) : (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 |
num1: The first valuenum2: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is equal to the second value or false otherwise |
Bool: true if the first value is equal to the second value or false otherwiseExamples:
use BigInt.{ (==) }
assert 1t == 1t
use BigInt.{ (==) }
assert -10t == -10t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `ne` |
(!=) : (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 |
num1: The first valuenum2: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is not equal to the second value or false otherwise |
Bool: true if the first value is not equal to the second value or false otherwiseExamples:
use BigInt.{ (!=) }
assert 1t != 2t
use BigInt.{ (!=) }
assert -10t != -20t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `lt` |
(<) : (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 |
num1: The first valuenum2: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is less than the second value or false otherwise |
Bool: true if the first value is less than the second value or false otherwiseExamples:
use BigInt.{ (<) }
assert 1t < 2t
use BigInt.{ (<) }
assert -10t < 0t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `lte` |
(<=) : (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 |
num1: The first valuenum2: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is less than or equal to the second value or false otherwise |
Bool: true if the first value is less than or equal to the second value or false otherwiseExamples:
use BigInt.{ (<=) }
assert 1t <= 1t
use BigInt.{ (<=) }
assert -10t <= 0t
use BigInt.{ (<=) }
assert 2t <= 3t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `gt` |
(>) : (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 |
num1: The first valuenum2: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is greater than the second value or false otherwise |
Bool: true if the first value is greater than the second value or false otherwiseExamples:
use BigInt.{ (>) }
assert 2t > 1t
use BigInt.{ (>) }
assert 0t > -10t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `gte` |
(>=) : (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 |
num1: The first valuenum2: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is greater than or equal to the second value or false otherwise |
Bool: true if the first value is greater than or equal to the second value or false otherwiseExamples:
use BigInt.{ (>=) }
assert 1t >= 1t
use BigInt.{ (>=) }
assert 0t >= -10t
use BigInt.{ (>=) }
assert 3t >= 2t
Added in 0.5.0
No other changes yet.
lnot : (num: BigInt) => BigInt
Computes the bitwise NOT of the given value.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The given value |
num: The given valueReturns:
| type | description |
|---|---|
BigInt | Containing the inverted bits of the given value |
BigInt: Containing the inverted bits of the given valueExamples:
BigInt.lnot(91234t) == -91235t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `land` |
(&) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | Containing a 1 in each bit position for which the corresponding bits of both operands are 1 |
BigInt: Containing a 1 in each bit position for which the corresponding bits of both operands are 1Examples:
use BigInt.{ (&) }
assert (4t & 3t) == 0t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `lor` |
(|) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | Containing a 1 in each bit position for which the corresponding bits of either or both operands are 1 |
BigInt: Containing a 1 in each bit position for which the corresponding bits of either or both operands are 1Examples:
use BigInt.{ (|) }
assert (5t | 3t) == 7t
Added in 0.6.0
| version | changes |
|---|---|
0.5.0 | Originally named `lxor` |
(^) : (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 |
num1: The first operandnum2: The second operandReturns:
| type | description |
|---|---|
BigInt | Containing a 1 in each bit position for which the corresponding bits of either but not both operands are 1 |
BigInt: Containing a 1 in each bit position for which the corresponding bits of either but not both operands are 1Examples:
use BigInt.{ (^) }
assert (5t ^ 3t) == 6t
Added in 0.5.0
No other changes yet.
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 |
num: The value to inspectReturns:
| type | description |
|---|---|
Int32 | The amount of leading zeros |
Int32: The amount of leading zerosExamples:
BigInt.clz(5t) == 2147483647t
Added in 0.5.0
No other changes yet.
ctz : (num: BigInt) => Int64
Counts the number of trailing zero bits in the value.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The value to inspect |
num: The value to inspectReturns:
| type | description |
|---|---|
Int64 | The amount of trailing zeros |
Int64: The amount of trailing zerosExamples:
BigInt.ctz(14t) == 1t
Added in 0.5.0
No other changes yet.
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 |
num: The value to inspectReturns:
| type | description |
|---|---|
Option<Int64> | The amount of 1-bits in its operand |
Option<Int64>: The amount of 1-bits in its operandExamples:
BigInt.popcnt(14t) == 1t
Added in 0.5.0
No other changes yet.
toString : (num: BigInt) => String
Converts the given operand to a string.
Parameters:
| param | type | description |
|---|---|---|
num | BigInt | The operand |
num: The operandReturns:
| type | description |
|---|---|
String | The operand, as a string |
String: The operand, as a stringExamples:
BigInt.toString(1t) == "1"
BigInt.toString(-1t) == "-1"