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

Summary

Actions Summary Table

ActionsDescription
Add(Libraries.Compute.BigInteger value)This action adds two BigIntegers together and returns the result.
And(Libraries.Compute.BigInteger value)This action takes two BigIntegers and performs a bit-wise AND (&) operation on them.
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.
BitwiseNot()This action takes a BigInteger and finds the 2's complement of it.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
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.
Divide(Libraries.Compute.BigInteger value)This action divides a BigInteger by the given BigInteger value and returns the result.
Equals(Libraries.Compute.BigInteger value)This action checks if two BigIntegers are equal.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
ExclusiveOr(Libraries.Compute.BigInteger value)This action will find the bitwise exclusive-or value of two BigIntegers.
GetHashCode()This action gets the hash code for an object.
GetMaximumValue(Libraries.Compute.BigInteger value)This action compares two BigIntegers and returns the greater of the two.
GetMinimumValue(Libraries.Compute.BigInteger value)This action compares two BigInteger and returns the lesser of the two.
GetSignValue()This action returns the sign of a BigInteger, returning 1 for positive, -1 for negative, and 0 for 0.
GetText(integer base)This action returns the value stored in the BigInteger in text format.
GetText()This action returns the value stored in the BigInteger in text format.
GreatestCommonDivisor(Libraries.Compute.BigInteger value)This action will find the greatest common divisor between two BigIntegers.
Mod(Libraries.Compute.BigInteger value)This action takes a BigInteger, divides it by the BigInteger value, and returns the remainder as the result.
Multiply(Libraries.Compute.BigInteger value)This action multiples two BigIntegers together and returns the result.
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.
Or(Libraries.Compute.BigInteger value)This action takes two BigIntegers and performs a bitwise OR (|) operation on them.
RaiseToPower(integer power)This action raises a BigInteger to the given power and returns the result.
Remainder(Libraries.Compute.BigInteger value)This action divides a BigInteger by the BigInteger value and returns the remainder.
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).
SetValue(text value)This action sets the value of the BigInteger object to the numeric value of the text parameter.
ShiftLeft(integer positions)This action takes a BigInteger and shifts its bits to the left by the given amount of positions.
ShiftRight(integer positions)This action takes a BigInteger and shifts its bits to the right by the given amount of positions.
Subtract(Libraries.Compute.BigInteger value)This action subtracts the BigInteger value from the BigInteger on which this action was called and returns the result.
ToInteger()This action takes a BigInteger and converts it into an integer.
ToNumber()This action takes a BigInteger and converts it into a number.

Actions Documentation

Add(Libraries.Compute.BigInteger value)

This action adds two BigIntegers together and returns the result.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("3000000000")
    largeNumber = largeNumber:Add(largeNumber)

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of adding the two BigIntegers together.

And(Libraries.Compute.BigInteger value)

This action takes two BigIntegers and performs a bit-wise AND (&) operation on them.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("3000000000")
    largeNumber = largeNumber:And(largeNumber)

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of AND'ing together the two BigIntegers.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("3000000000")
    largeNumber = largeNumber:AndNot(largeNumber)

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of AND'ing together the complement of the value with the BigInteger.

BitwiseNot()

This action takes a BigInteger and finds the 2's complement of it. The calculation is: x = -x - 1.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("10")
    largeNumber = largeNumber:BitwiseNot()
    // Output will be -11
    output largeNumber:GetText()

Return

Libraries.Compute.BigInteger: Returns the 2's complement of a BigInteger.

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.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    BigInteger largerNumber
    largeNumber:SetValue("3000000000")
    largerNumber:SetValue("3000000001")
    integer result = largeNumber:CompareResult(largerNumber)
    output result

Parameters

Return

integer: Returns 1 if value < BigInteger, 0 if value = BigInteger, and -1 if value > BigInteger.

Divide(Libraries.Compute.BigInteger value)

This action divides a BigInteger by the given BigInteger value and returns the result.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    BigInteger smallNumber
    largeNumber:SetValue("3000000000")
    smallNumber:SetValue("2")
    largeNumber = largeNumber:Divide(smallNumber)
    output largeNumber:GetText()

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of BigInteger/value as a BigInteger.

Equals(Libraries.Compute.BigInteger value)

This action checks if two BigIntegers are equal. To be equal, the BigIntegers must have the same numeric values.

Example Code

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)

Parameters

Return

boolean: Returns the result of the comparison, either true if the BigIntegers are the same or false otherwise.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

ExclusiveOr(Libraries.Compute.BigInteger value)

This action will find the bitwise exclusive-or value of two BigIntegers.

Example Code

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()

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of exclusive-or'ing the two BigIntegers together.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetMaximumValue(Libraries.Compute.BigInteger value)

This action compares two BigIntegers and returns the greater of the two.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    BigInteger smallNumber
    largeNumber:SetValue("300")
    smallNumber:SetValue("1")
    largeNumber = largeNumber:GetMaximumValue(smallNumber)

Parameters

Return

Libraries.Compute.BigInteger: Returns the BigInteger that is the greater of the two BigIntegers.

GetMinimumValue(Libraries.Compute.BigInteger value)

This action compares two BigInteger and returns the lesser of the two.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    BigInteger smallNumber
    largeNumber:SetValue("300")
    smallNumber:SetValue("1")
    largeNumber = largeNumber:GetMinimumValue(smallNumber)

Parameters

Return

Libraries.Compute.BigInteger: Returns the BigInteger that is the lesser of the two BigIntegers.

GetSignValue()

This action returns the sign of a BigInteger, returning 1 for positive, -1 for negative, and 0 for 0.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("-10")
    integer result = largeNumber:GetSignValue()
    // Output will be -1
    output result

Return

integer: Returns an integer value, 1, 0, or -1, indicating the sign of the BigInteger.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("3000000000")
    output largeNumber:GetText(2)

Parameters

Return

text: Returns the value of the BigInteger in the given base in text format.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("3000000000")
    output largeNumber:GetText()

Return

text: Returns the value of the BigInteger in base 10 in text format.

GreatestCommonDivisor(Libraries.Compute.BigInteger value)

This action will find the greatest common divisor between two BigIntegers.

Example Code

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()

Parameters

Return

Libraries.Compute.BigInteger: Returns a BigInteger value that is the greatest common divisor of the two BigIntegers.

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.

Example Code

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()

Parameters

Return

Libraries.Compute.BigInteger: Returns the remainder of the division of the BigInteger on which this action was called by value.

Multiply(Libraries.Compute.BigInteger value)

This action multiples two BigIntegers together and returns the result.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    BigInteger smallNumber
    largeNumber:SetValue("398")
    smallNumber:SetValue("10")
    largeNumber = largeNumber:Multiply(smallNumber)
    output largeNumber:GetText()

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of the multiplication of these two BigIntegers as a BigInteger.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("-10")
    largeNumber = largeNumber:Negate()
    // Output will be 10
    output largeNumber:GetText()

Return

Libraries.Compute.BigInteger: Returns a BigInteger with the opposite sign than what it originally had.

Or(Libraries.Compute.BigInteger value)

This action takes two BigIntegers and performs a bitwise OR (|) operation on them.

Example Code

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()

Parameters

Return

Libraries.Compute.BigInteger: Returns a BigInteger that is the result of logically OR'ing the two BigIntegers together.

RaiseToPower(integer power)

This action raises a BigInteger to the given power and returns the result.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("9")
    largeNumber = largeNumber:RaiseToPower(2)
    output largeNumber:GetText()

Parameters

Return

Libraries.Compute.BigInteger: Returns a BigInteger which is the result of raising the BigInteger to the given power.

Remainder(Libraries.Compute.BigInteger value)

This action divides a BigInteger by the BigInteger value and returns the remainder. This remainder can be negative.

Example Code

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()

Parameters

Return

Libraries.Compute.BigInteger: Returns the remainder of the division operation as a BigInteger.

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).

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    text value = "3000000000"
    largeNumber:SetValue(value, 10)

Parameters

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    text value = "3000000000"
    largeNumber:SetValue(value)

Parameters

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("10")
    largeNumber = largeNumber:ShiftLeft(2)
    // Output will be 40
    output largeNumber:GetText()

Parameters

Return

Libraries.Compute.BigInteger: Returns a BigInteger that has been shifted to the left positions number of times.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("10")
    largeNumber = largeNumber:ShiftRight(2)
    // Output will be 2
    output largeNumber:GetText()

Parameters

Return

Libraries.Compute.BigInteger: Returns a BigInteger that has been shifted to the right positions number of times.

Subtract(Libraries.Compute.BigInteger value)

This action subtracts the BigInteger value from the BigInteger on which this action was called and returns the result.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    BigInteger smallNumber
    largeNumber:SetValue("10")
    smallNumber:SetValue("5")
    largeNumber = largeNumber:Subtract(smallNumber)
    output largeNumber:GetText()

Parameters

Return

Libraries.Compute.BigInteger: Returns the result of the BigInteger minus value as a BigInteger.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("30")
    integer value = largeNumber:ToInteger()

Return

integer: Returns the BigInteger value as an integer.

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.

Example Code

use Libraries.Compute.BigInteger
    BigInteger largeNumber
    largeNumber:SetValue("24")
    number value = largeNumber:ToNumber()

Return

number: Returns the BigInteger value as a number.