Libraries.Compute.BigInteger Documentation
The BigInteger class is used to represent integer values that are too large to be stored in an integer variable. Additionally, it contains actions to perform expected operations on these BigIntegers, such as addition, division, comparison, and so on.
Example Code
use Libraries.Compute.BigInteger
class Main
action main
text value = "2147483648"
BigInteger largeNumber
largeNumber:SetValue(value)
largeNumber = largeNumber:RaiseToPower(2)
output largeNumber:GetText()
end
end
Inherits from: Libraries.Language.Object
Actions Documentation
Add(Libraries.Compute.BigInteger value)
This action adds two BigIntegers together and returns the result.
Parameters
- Libraries.Compute.BigInteger: The value to add to the BigInteger.
Return
Libraries.Compute.BigInteger: Returns the result of adding the two BigIntegers together.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("3000000000")
largeNumber = largeNumber:Add(largeNumber)
And(Libraries.Compute.BigInteger value)
This action takes two BigIntegers and performs a bit-wise AND (&) operation on them.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to AND with the BigInteger.
Return
Libraries.Compute.BigInteger: Returns the result of AND'ing together the two BigIntegers.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("3000000000")
largeNumber = largeNumber:And(largeNumber)
AndNot(Libraries.Compute.BigInteger value)
This action takes a BigInteger, gets the complement of it, and then ANDs it with the BigInteger this action was called on.
Parameters
- Libraries.Compute.BigInteger: The BigInteger that will be complemented and then AND'ed together with the BigInteger.
Return
Libraries.Compute.BigInteger: Returns the result of AND'ing together the complement of the value with the BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("3000000000")
largeNumber = largeNumber:AndNot(largeNumber)
BitwiseNot()
This action takes a BigInteger and finds the 2's complement of it. The calculation is: x = -x - 1.
Return
Libraries.Compute.BigInteger: Returns the 2's complement of a BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("10")
largeNumber = largeNumber:BitwiseNot()
// Output will be -11
output largeNumber:GetText()
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
CompareResult(Libraries.Compute.BigInteger value)
This action compares two BigIntegers and returns whether or not the BigInteger that this action was called on is >, =, or < the value passed in, represented by 1, 0, and -1 respectively.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to compare against.
Return
integer: Returns 1 if value < BigInteger, 0 if value = BigInteger, and -1 if value > BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger largerNumber
largeNumber:SetValue("3000000000")
largerNumber:SetValue("3000000001")
integer result = largeNumber:CompareResult(largerNumber)
output result
Divide(Libraries.Compute.BigInteger value)
This action divides a BigInteger by the given BigInteger value and returns the result.
Parameters
- Libraries.Compute.BigInteger: The value to divide the BigInteger by.
Return
Libraries.Compute.BigInteger: Returns the result of BigInteger/value as a BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("3000000000")
smallNumber:SetValue("2")
largeNumber = largeNumber:Divide(smallNumber)
output largeNumber:GetText()
Equals(Libraries.Compute.BigInteger value)
This action checks if two BigIntegers are equal. To be equal, the BigIntegers must have the same numeric values.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to compare against.
Return
boolean: Returns the result of the comparison, either true if the BigIntegers are the same or false otherwise.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger sameNumber
BigInteger differentNumber
largeNumber:SetValue("3000000000")
sameNumber:SetValue("3000000000")
differentNumber:SetValue("1")
output largeNumber:Equals(sameNumber)
output largeNumber:Equals(differentNumber)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
ExclusiveOr(Libraries.Compute.BigInteger value)
This action will find the bitwise exclusive-or value of two BigIntegers.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to exclusive-or with the BigInteger on which this action was called.
Return
Libraries.Compute.BigInteger: Returns the result of exclusive-or'ing the two BigIntegers together.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("6")
smallNumber:SetValue("4")
largeNumber = largeNumber:ExclusiveOr(smallNumber)
// Output will be 2
output largeNumber:GetText()
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetMaximumValue(Libraries.Compute.BigInteger value)
This action compares two BigIntegers and returns the greater of the two.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to compare against.
Return
Libraries.Compute.BigInteger: Returns the BigInteger that is the greater of the two BigIntegers.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("300")
smallNumber:SetValue("1")
largeNumber = largeNumber:GetMaximumValue(smallNumber)
GetMinimumValue(Libraries.Compute.BigInteger value)
This action compares two BigInteger and returns the lesser of the two.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to compare against.
Return
Libraries.Compute.BigInteger: Returns the BigInteger that is the lesser of the two BigIntegers.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("300")
smallNumber:SetValue("1")
largeNumber = largeNumber:GetMinimumValue(smallNumber)
GetSignValue()
This action returns the sign of a BigInteger, returning 1 for positive, -1 for negative, and 0 for 0.
Return
integer: Returns an integer value, 1, 0, or -1, indicating the sign of the BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("-10")
integer result = largeNumber:GetSignValue()
// Output will be -1
output result
GetText(integer base)
This action returns the value stored in the BigInteger in text format. Returns the value in whatever base you use as the parameter, such as 2, 10, 16, and so on.
Parameters
- integer base: The base (2, 8, 10, 16, etc.) to convert the value to.
Return
text: Returns the value of the BigInteger in the given base in text format.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("3000000000")
output largeNumber:GetText(2)
GetText()
This action returns the value stored in the BigInteger in text format. Returns the value in base 10 by default. If you want the number in a different base then use the GetText(integer) action instead.
Return
text: Returns the value of the BigInteger in base 10 in text format.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("3000000000")
output largeNumber:GetText()
GreatestCommonDivisor(Libraries.Compute.BigInteger value)
This action will find the greatest common divisor between two BigIntegers.
Parameters
- Libraries.Compute.BigInteger: The BigInteger to check against for the greatest common divisor.
Return
Libraries.Compute.BigInteger: Returns a BigInteger value that is the greatest common divisor of the two BigIntegers.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("24")
smallNumber:SetValue("12")
largeNumber = largeNumber:GreatestCommonDivisor(smallNumber)
// Output will be 12
output largeNumber:GetText()
Mod(Libraries.Compute.BigInteger value)
This action takes a BigInteger, divides it by the BigInteger value, and returns the remainder as the result. The remainder is always positive. Use the Remainder(BigInteger) action if you want negative remainder results.
Parameters
- Libraries.Compute.BigInteger: The value to divide the BigInteger by.
Return
Libraries.Compute.BigInteger: Returns the remainder of the division of the BigInteger on which this action was called by value.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("10")
smallNumber:SetValue("6")
largeNumber = largeNumber:Mod(smallNumber)
// Output will be 4
output largeNumber:GetText()
Multiply(Libraries.Compute.BigInteger value)
This action multiples two BigIntegers together and returns the result.
Parameters
- Libraries.Compute.BigInteger: The value to multiply the BigInteger by.
Return
Libraries.Compute.BigInteger: Returns the result of the multiplication of these two BigIntegers as a BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("398")
smallNumber:SetValue("10")
largeNumber = largeNumber:Multiply(smallNumber)
output largeNumber:GetText()
Negate()
This action negates the value of a BigInteger, turning a positive number to a negative number and a negative number to a positive number.
Return
Libraries.Compute.BigInteger: Returns a BigInteger with the opposite sign than what it originally had.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("-10")
largeNumber = largeNumber:Negate()
// Output will be 10
output largeNumber:GetText()
Or(Libraries.Compute.BigInteger value)
This action takes two BigIntegers and performs a bitwise OR (|) operation on them.
Parameters
- Libraries.Compute.BigInteger: The BigInteger value that will be logically OR'ed with the BigInteger on which this action was called.
Return
Libraries.Compute.BigInteger: Returns a BigInteger that is the result of logically OR'ing the two BigIntegers together.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("2")
smallNumber:SetValue("1")
largeNumber = largeNumber:Or(smallNumber)
// Output will be 3
output largeNumber:GetText()
RaiseToPower(integer power)
This action raises a BigInteger to the given power and returns the result.
Parameters
- integer power: The power to raise the BigInteger to.
Return
Libraries.Compute.BigInteger: Returns a BigInteger which is the result of raising the BigInteger to the given power.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("9")
largeNumber = largeNumber:RaiseToPower(2)
output largeNumber:GetText()
Remainder(Libraries.Compute.BigInteger value)
This action divides a BigInteger by the BigInteger value and returns the remainder. This remainder can be negative.
Parameters
- Libraries.Compute.BigInteger: The value to divide the BigInteger by.
Return
Libraries.Compute.BigInteger: Returns the remainder of the division operation as a BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("-10")
smallNumber:SetValue("6")
largeNumber = largeNumber:Remainder(smallNumber)
// Output will be -4
output largeNumber:GetText()
SetValue(text value, integer base)
This action sets the value of the BigInteger object to the numeric value of the text parameter, in the base of the base parameter (base 2 for binary, 10 for decimal, and so on).
Parameters
- text value: The text to convert into a numeric value.
- integer base: The base (2, 8, 10, 16, etc.) to convert the value to.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
text value = "3000000000"
largeNumber:SetValue(value, 10)
SetValue(text value)
This action sets the value of the BigInteger object to the numeric value of the text parameter. Uses base 10 by default. If you want the number in a different base then use the SetValue(text, integer) action instead.
Parameters
- text value: The text to convert into a numeric value.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
text value = "3000000000"
largeNumber:SetValue(value)
ShiftLeft(integer positions)
This action takes a BigInteger and shifts its bits to the left by the given amount of positions. This is equivalent to multiplying by 2 for each position shifted. So if you shift by 2 positions, you multiply the original number by 4.
Parameters
- integer positions: The number of positions to shift the BigInteger to the left.
Return
Libraries.Compute.BigInteger: Returns a BigInteger that has been shifted to the left positions number of times.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("10")
largeNumber = largeNumber:ShiftLeft(2)
// Output will be 40
output largeNumber:GetText()
ShiftRight(integer positions)
This action takes a BigInteger and shifts its bits to the right by the given amount of positions. This is equivalent to dividing by 2 for each position shifted. So if you shift by 2 positions, you divide the original number by 4.
Parameters
- integer positions: The number of positions to shift the BigInteger to the right.
Return
Libraries.Compute.BigInteger: Returns a BigInteger that has been shifted to the right positions number of times.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("10")
largeNumber = largeNumber:ShiftRight(2)
// Output will be 2
output largeNumber:GetText()
Subtract(Libraries.Compute.BigInteger value)
This action subtracts the BigInteger value from the BigInteger on which this action was called and returns the result.
Parameters
- Libraries.Compute.BigInteger: The value to subtract from the BigInteger.
Return
Libraries.Compute.BigInteger: Returns the result of the BigInteger minus value as a BigInteger.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
BigInteger smallNumber
largeNumber:SetValue("10")
smallNumber:SetValue("5")
largeNumber = largeNumber:Subtract(smallNumber)
output largeNumber:GetText()
ToInteger()
This action takes a BigInteger and converts it into an integer. If the BigInteger is too large to be stored in an integer, it takes the low-order bits (i.e. 102 would return 02 if 102 was too large to fit in a number) and gets rid of all other values. This loss of precision can result in incorrect values, as well as incorrect signs.
Return
integer: Returns the BigInteger value as an integer.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("30")
integer value = largeNumber:ToInteger()
ToNumber()
This action takes a BigInteger and converts it into a number. If the BigInteger is too large to be stored in a number, it takes the low-order bits (i.e. 102 would return 02 if 102 was too large to fit in a number) and gets rid of all other values. This loss of precision can result in incorrect values, as well as incorrect signs.
Return
number: Returns the BigInteger value as a number.
Example
use Libraries.Compute.BigInteger
BigInteger largeNumber
largeNumber:SetValue("24")
number value = largeNumber:ToNumber()