BigInteger version 2.0.0
What has changed in version 1:
- More memory efficient as they’re now garbage collected when they’re not used
- < and > sign fixed for negative numbers
- Log slighty more accurate
- A little bit of optimisation
- Lowercased method name
About
BigInteger is a moudle that allows you to safely store integers above 2⁵³ (2 ** 53) without precision loss. It can thereotically store up to 2 ** 2 ** 53
Why you may ask?
Luau number’s uses the double precision floating point format as specified by IEEE
It’s meant to fix the precision loss for doubles above 9007 billion (9.007.199.254.740.992).
Constructor
BigInteger BigInteger.new(object value)
Create a BigInteger based off the value
Values
BigInteger BigInteger.zero
BigInteger BigInteger.one
BigInteger BigInteger.minusone
Should be self explainatory, BigInteger.zero = BigInteger.new(0)
, BigInteger.one = BigInteger.new(1)
, BigInteger.minusone = BigInteger.new(-1)
.
Class methods
BigInteger BigInteger.abs(BigInteger value)
Return the absolute value of the BigInteger.
BigInteger.new('-78259438907245387524387245378902543890752438907'):abs() --> 78259438907245387524387245378902543890752438907
BigInteger BigInteger.band(BigInteger left, BigInteger right)
Bitwise ‘and’ for the two BigInteger value
BigInteger BigInteger.bor(BigInteger left, BigInteger right)
Bitwise ‘or’ for the two BigInteger value
BigInteger BigInteger.bnot(BigInteger left, BigInteger right)
Bitwise ‘not’ for the two BigInteger value
BigInteger BigInteger.bxor(BigInteger left, BigInteger right)
Bitwise ‘xor’ for the two BigInteger value
BigInteger BigInteger.shl(BigInteger value, double disp)
Left shift fo the BigInteger value, basically doing value << disp
BigInteger BigInteger.shr(BigInteger value, double disp)
Right shift fo the BigInteger value, basically doing value >> disp
BigInteger BigInteger BigInteger.divrem(BigInteger left, BigInteger right)
Dividing and getting the remainder at the same time, basically
left / right, left % right
double BigInteger.log(BigInteger value, double base = 2.718281828459045)
Logarithm of the BigInteger value, the default for base is Euler’s number
double BigInteger.log2(BigInteger value)
Sugar syntax for BigInteger.log(value, 2)
double BigInteger.log8(BigInteger value)
Sugar syntax for BigInteger.log(value, 8)
double BigInteger.log10(BigInteger value)
Sugar syntax for BigInteger.log(value, 10)
double BigInteger.log12(BigInteger value)
Sugar syntax for BigInteger.log(value, 12)
double BigInteger.log16(BigInteger value)
Sugar syntax for BigInteger.log(value, 16)
boolean BigInteger.iseven(BigInteger value)
Reuturns a boolean that determines whether the BigInteger value is even or not.
boolean BigInteger.ispoweroftwo(BigInteger value)
Returns a boolean that determines whether the BigInteger value is power of 2 or not.
BigInteger BigInteger.max(BigInteger ···)
Gets the highest value out of all the arguments
BigInteger BigInteger.min(BigInteger ···)
Gets the lowest value out of all the arguments
BigInteger BigInteger.sum(BigInteger ···)
Returns the sum of the value when adding all the argument
BigInteger BigInteger.clamp(BigInteger start, BigInteger min, BigInteger max)
Clamps the number between and double
int BigInteger.sign(BigInteger value)
Get the sign of the BigInteger value
Value | Sign |
---|---|
< 0 | -1 |
= 0 | 0 |
0 | 1
BigInteger BigInteger.copysign(BigInteger value, BigInteger sign)
Return the BigInteger value argument but with the sign of the sign argument. (0 will be treated as positive)
BigInteger.copysign(BigInteger.new('8975267892567892458379879524387945289734523'), BigInteger.new('549420380923498023490834289034290834289043298098234')) --> 8975267892567892458379879524387945289734523
BigInteger.copysign(BigInteger.new('8359408903459083459084538909034580894359805'), BigInteger.new('-389052890459803954945803890453980543980')) --> -8359408903459083459084538909034580894359805
BigInteger.copysign(BigInteger.new('-2398408903429083428902348234243'), BigInteger.new('354898905348354904533459583489345908980534908453089543089453543345')) --> 2398408903429083428902348234243
int BigInteger.compare(BigInteger left, BigInteger right)
Compares the value of BigInteger, if left is greater than right return 1, if less than right return -1 otherwise return 0, basically
if left > right then
return 1
elseif left < right then
return -1
end
return 0
BigInteger BigInteger.factorial(BigInteger value)
Gets the factorial of the BigInteger value
BigInteger BigInteger.gcd(BigInteger value)
Gets the greatest common divisor of the BigItneger value
double BigInteger.todouble(BigInteger value)
Converts the BigItneger value to Luau number (double)
string BigInteger.tostring(BigInteger value, table options)
Basic number formatting, you never know if you might need it
Options
useGrouping
Determine whether to separate number or not.
decimalSymbol
The decimal symbol for scientfic and engineering notation, the default is ‘.’
groupSymbol
The group symbol for standard notation, the default is ’ ’ (U+2009)
minimumGroupingDigits
Suppress grouping below certain digits, the only valid value are from 1 to 4
minimumIntegerDigits
The minimum integer digits
notation
The formatting displayed for BigInteger.
-
"standard"
for plain decimal formatting -
"scientific"
for scientific notation -
"engineering"
for engineering notation
numberingSystem
The numbering system to use, the default is ‘latn’
string BigInteger.tolocalestring(BigInteger value, string locale, table options)
A built-in locale based number formatting (don’t ask why I added this).
Options
useGrouping
Determine whether to separate number or not. This only acccept booleans, so true is "auto"
(expect for compact and abbreviated notation which is "min2"
) and false is "never"
.
notation
The formatting displayed for BigInteger.
-
"standard"
for plain decimal formatting -
"scientific"
for scientific notation -
"engineering"
for engineering notation -
"compact"
for compact notation, can only go up to trillion -
"abbreviated"
for abbreviated value maximum of 3 significant digits, can only go up to trillion
minimumIntegerDigits
The minimum of integer digits to use. Only works for standard notation.
numberingSystem
The numbering system to use, the default is locale-dependant
string tostring(BigInteger)
Converts BigInteger to string.
boolean BigInteger.isbiginteger(value)
Check if the value is BigItneger or not, only available on the standalone version.
Operators
BigInteger + BigInteger
Adds the two BigInteger value
BigInteger - BigIntegers
Subtracts the two BigInteger value
BigInteger * BigInteger
Multiplies the BigInteger value
BigInteger / BigInteger
Divides the BigInteger value (floor division)
BigInteger % BigInteger
Get the remainder of these two BigInteger value (note that it’s NOT modulus, -4 % 3 returns -1 for BigInteger but 2 for Luau numbers)
BigInteger ^ BigIntger
Power of the biginteger value
BigInteger > BigInteger
BigInteger < BigInteger
BigInteger >= BigInteger
BigInteger <= BigInteger
BigInteger == BigInteger
BigInteger ~= BigInteger
Compare BigInteger value depending on the operator, > is greater than, < is less than, >= is greater than or equals to, <= is less than or equals to, == is equals to and ~= is not equals to.
Where do I get it?
You can get it from GitHub or from here:
2.0.1:
- BigIntegerStandalone.rbxm (23.1 KiB)
- 26 September 2020
2.0.0:
- BigInteger.rbxm (22·9 KB) (Standalone)
- 15 September 2020
1.0.0:
- BigInteger.lua (18·7 KiB) (No ToLocaleString)
- 21 May 2020, 20.13.56 (CET)