dreamworkAPI
Ctrl K
GitHub
classDocs / BigInteger

BigInteger

classsharedmenusource
Object → BigInteger

Represents an arbitrary-precision signed integer.

A BigInteger object can represent any integer value that fits in available memory. It supports arithmetic, comparison, conversion, and bitwise operations while preserving exact integer precision.

Constructor

BigInteger(value: ( BigInteger | string | integer | nil ), base: ( integer | nil )): BigInteger

Fields

NameTypeDescription
limbsinteger[]The magnitude as little-endian 16-bit limbs, limbs[ 0 ] is the limb count.
signboolean

Operators

OperatorOperandResult
add any BigInteger
sub any BigInteger
mul any BigInteger
div any BigInteger
idiv any BigInteger
pow integer BigInteger
unmBigInteger
bnotBigInteger
band any BigInteger
bor any BigInteger
bxor any BigInteger
shl integer BigInteger
shr integer BigInteger
leninteger
concat any string

Static functions

#BigInteger.fromBytes

sharedmenunodiscardsource
function BigInteger.fromBytes(signed: boolean, ...: integer): BigInteger

Creates a new BigInteger from the given bytes.

The bytes are interpreted in big-endian order (most significant byte first). If signed is true, the resulting value is interpreted as a signed two's-complement integer.

Parameters
NameTypeDescription
signedbooleanWhether the byte sequence represents a signed integer.
...integerThe bytes of the integer, each in the range 0–255.
Returns
TypeNameDescription
BigIntegernew_obj

Methods

absMakes a big integer object absolute (simply removes the sign).
addSummarizes the current BigInteger with the specified value.
bandPerforms a bitwise AND operation between two big integer objects.
bnotPerforms a bitwise NOT operation on a big integer object.
borPerforms a bitwise OR operation between two big integer objects.
bxorPerforms a bitwise XOR operation between two big integer objects.
compareCompares the BigInteger with the given value.
copyMakes a copy of the BigInteger object.
divDivides the current BigInteger with the specified value.
fromBytesReplaces the contents of this BigInteger with the given bytes.
fromIntegerSets a BigInteger object from Lua integer.
fromStringSets a BigInteger object from a decimal string.
isEvenChecks if a big integer object is even.
isOddChecks if a big integer object is odd.
isPowerOfTwoChecks if BigInteger is a power of two.
isZeroChecks if a big integer object is zero/empty.
log2Returns the log2 of a big integer object.
lshiftShifts a big integer object to the left by a given number of bits (positive or negative).
modCalculates modulus (remainder after division);
mulMultiplies the current BigInteger by the specified value.
negateNegates a big integer object.
powRaises a big integer object to a power.
rshiftShifts a big integer object to the right by a given number of bits (positive or negative).
subSubtract the current BigInteger by the specified value.
toBinaryStringConverts the big integer to a binary [01] string.
toHexStringConverts the big integer into a hex string.
toIntegerConverts a big integer object to a lua_number (always an integer).
toSignedConverts unsigned BigInteger to signed one.
toStringConverts the big integer to a string in the specified (or not) base.
toUnsignedConverts signed BigInteger to unsigned one.

#BigInteger:abs

sharedmenusource
function BigInteger:abs(): BigInteger

Makes a big integer object absolute (simply removes the sign).

Returns
TypeNameDescription
BigIntegerselfThe absolute big integer object.

#BigInteger:add

sharedmenusource
function BigInteger:add(value: any): BigInteger

Summarizes the current BigInteger with the specified value.

Parameters
NameTypeDescription
valueanyThe second value to be converted into BigInteger.
Returns
TypeNameDescription
BigIntegerobjectThe result of the operation.

#BigInteger:band

sharedmenusource
function BigInteger:band(value: any): BigInteger

Performs a bitwise AND operation between two big integer objects.

Parameters
NameTypeDescription
valueanyThe value to perform the operation on.
Returns
TypeNameDescription
BigIntegernew_objectThe result of the operation.

#BigInteger:bnot

sharedmenusource
function BigInteger:bnot(): BigInteger

Performs a bitwise NOT operation on a big integer object.

Returns
TypeNameDescription
BigIntegerobjectThe result of the operation.

#BigInteger:bor

sharedmenusource
function BigInteger:bor(value: any): BigInteger

Performs a bitwise OR operation between two big integer objects.

Parameters
NameTypeDescription
valueanyThe value to perform the operation on.
Returns
TypeNameDescription
BigIntegerobjectThe result of the operation.

#BigInteger:bxor

sharedmenusource
function BigInteger:bxor(value: any): BigInteger

Performs a bitwise XOR operation between two big integer objects.

Parameters
NameTypeDescription
valueanyThe value to perform the operation on.
Returns
TypeNameDescription
BigIntegerobjectThe result of the operation.

#BigInteger:compare

sharedmenunodiscardsource
function BigInteger:compare(value: any): `-1` | `0` | `1`

Compares the BigInteger with the given value.

Unlike the ==, < and <= operators, this also works with plain Lua numbers and strings.

Parameters
NameTypeDescription
valueanyThe value to compare with (will be converted into BigInteger).
Returns
TypeNameDescription
`-1` | `0` | `1`result-1 if self < value, 0 if equal, 1 if self > value.

#BigInteger:copy

sharedmenunodiscardsource
function BigInteger:copy(): BigInteger

Makes a copy of the BigInteger object.

Returns
TypeNameDescription
BigIntegernew_obj

#BigInteger:div

sharedmenusource
function BigInteger:div(value: any): BigInteger, BigInteger

Divides the current BigInteger with the specified value.

Parameters
NameTypeDescription
valueanyThe second value to divide by (will be converted into BigInteger).
Returns
TypeNameDescription
BigIntegerquotientThe quotient.
BigIntegerremainderThe remainder.

#BigInteger:fromBytes

sharedmenusource
function BigInteger:fromBytes(signed: boolean, ...: integer): BigInteger

Replaces the contents of this BigInteger with the given bytes.

The bytes are interpreted in big-endian order (most significant byte first). If signed is true, the resulting value is interpreted as a signed two's-complement integer.

Parameters
NameTypeDescription
signedbooleanWhether the byte sequence represents a signed integer.
...integerThe bytes to store, each in the range 0–255.
Returns
TypeNameDescription
BigIntegerself

#BigInteger:fromInteger

sharedmenusource
function BigInteger:fromInteger(value: integer): BigInteger

Sets a BigInteger object from Lua integer.

Parameters
NameTypeDescription
valueintegerThe number to convert.
Returns
TypeNameDescription
BigIntegerself

#BigInteger:fromString

sharedmenusource
function BigInteger:fromString(str: string, base?: integer, start_position?: integer, end_position?: integer): BigInteger

Sets a BigInteger object from a decimal string.

Parameters
NameTypeDescription
strstringThe string representation of the big integer.
baseoptionalintegerThe numerical base of the digits in the input value. Can be any integer between 2 and 36, inclusive. By default: 10
start_positionoptionalintegerThe start position to read from.
end_positionoptionalintegerThe end position to read to.
Returns
TypeNameDescription
BigIntegerself

#BigInteger:isEven

sharedmenunodiscardsource
function BigInteger:isEven(): boolean

Checks if a big integer object is even.

Returns
TypeNameDescription
booleanresulttrue if the big integer object is even, false otherwise.

#BigInteger:isOdd

sharedmenunodiscardsource
function BigInteger:isOdd(): boolean

Checks if a big integer object is odd.

Returns
TypeNameDescription
booleantrue if the big integer object is odd, false otherwise.

#BigInteger:isPowerOfTwo

sharedmenunodiscardsource
function BigInteger:isPowerOfTwo(): boolean

Checks if BigInteger is a power of two.

Returns
TypeNameDescription
booleanis_pottrue if a number is a valid power-of-two, otherwise false.

#BigInteger:isZero

sharedmenunodiscardsource
function BigInteger:isZero(): boolean

Checks if a big integer object is zero/empty.

Returns
TypeNameDescription
booleanis_zerotrue if the big integer object is zero/empty, false otherwise.

#BigInteger:log2

sharedmenunodiscardsource
function BigInteger:log2(): number

Returns the log2 of a big integer object.

Returns
TypeNameDescription
numberresultThe base-2 logarithm of the big integer object. NaN for negative values, -inf for zero.

#BigInteger:lshift

sharedmenusource
function BigInteger:lshift(shift: integer): BigInteger

Shifts a big integer object to the left by a given number of bits (positive or negative).

Parameters
NameTypeDescription
shiftintegerThe number of bits to shift by.
Returns
TypeNameDescription
BigIntegerobjectThe shifted big integer object.

#BigInteger:mod

sharedmenunodiscardsource
function BigInteger:mod(value: any): BigInteger

Calculates modulus (remainder after division);

Handles Lua-to-BigInteger conversions and non-positive cases correctly.

Parameters
NameTypeDescription
valueanyThe value to divide by.
Returns
TypeNameDescription
BigIntegerremainderThe remainder (same sign as self, or zero).

#BigInteger:mul

sharedmenusource
function BigInteger:mul(value: any): BigInteger

Multiplies the current BigInteger by the specified value.

Parameters
NameTypeDescription
valueanyThe second value to be converted into BigInteger.
Returns
TypeNameDescription
BigIntegerobjectThe result of the operation.

#BigInteger:negate

sharedmenusource
function BigInteger:negate(): BigInteger

Negates a big integer object.

Returns
TypeNameDescription
BigIntegerselfThe negated big integer object.

#BigInteger:pow

sharedmenusource
function BigInteger:pow(value: integer): BigInteger

Raises a big integer object to a power.

Parameters
NameTypeDescription
valueintegerThe value to raise to.
Returns
TypeNameDescription
BigIntegerselfThe result of the operation.

#BigInteger:rshift

sharedmenusource
function BigInteger:rshift(shift: integer): BigInteger

Shifts a big integer object to the right by a given number of bits (positive or negative).

Parameters
NameTypeDescription
shiftintegerThe number of bits to shift by.
Returns
TypeNameDescription
BigIntegerobjectThe shifted big integer object.

#BigInteger:sub

sharedmenusource
function BigInteger:sub(value: any): BigInteger

Subtract the current BigInteger by the specified value.

Parameters
NameTypeDescription
valueanyThe second value to be converted into BigInteger.
Returns
TypeNameDescription
BigIntegerobjectThe result of the operation.

#BigInteger:toBinaryString

sharedmenunodiscardsource
function BigInteger:toBinaryString(): string

Converts the big integer to a binary [01] string.

The output is zero-padded to a whole number of bytes.

Returns
TypeNameDescription
stringstrThe binary string representation of the big integer.

#BigInteger:toHexString

sharedmenunodiscardsource
function BigInteger:toHexString(): string

Converts the big integer into a hex string.

Returns
TypeNameDescription
stringhex_strThe hex string representation of the big integer.

#BigInteger:toInteger

sharedmenunodiscardsource
function BigInteger:toInteger(): integer

Converts a big integer object to a lua_number (always an integer).

Returns
TypeNameDescription
integervalueThe number that the big integer object represents.

#BigInteger:toSigned

sharedmenusource
function BigInteger:toSigned(byte_width: integer): BigInteger

Converts unsigned BigInteger to signed one.

Parameters
NameTypeDescription
byte_widthintegerThe byte width to interpret the raw magnitude at (e.g. 1 for int8, 4 for int32).
Returns
TypeNameDescription
BigIntegerobjectSelf, reinterpreted as a signed integer of the given byte width.

#BigInteger:toString

sharedmenunodiscardsource
function BigInteger:toString(base?: integer): string

Converts the big integer to a string in the specified (or not) base.

Parameters
NameTypeDescription
baseoptionalintegerThe numerical base of the digits in the input value. Can be any integer between 2 and 36, inclusive. By default: 10
Returns
TypeNameDescription
stringstrThe string representation of the big integer.

#BigInteger:toUnsigned

sharedmenusource
function BigInteger:toUnsigned(byte_width: integer): BigInteger

Converts signed BigInteger to unsigned one.

Parameters
NameTypeDescription
byte_widthintegerThe byte width to encode as (e.g. 1 for uint8, 4 for uint32).
Returns
TypeNameDescription
BigIntegerself
Generated from the dreamwork meta branch.