A collection of static, low-level arithmetic functions that operate directly on
Vector<Int>
representations of large numbers.
Static methods
staticadd(result:Vector<Int>, operand1:Vector<Int>, operand2:Vector<Int>, length:Int):Int
Add big integer operand2
to big integer operand1
and put
the result into big integer result
.
Ok for result
, operand1
, and operand2
to be the same object.
Returns the "carry" value of either 0 or 1.
staticarithmeticShiftRight(result:Vector<Int>, input:Vector<Int>, length:Int, shift:Int):Void
Shift multiword integer input
right by shift
binary
places and store the result in result
, with the high bit
duplicated for bits inserted from the left.
shift
must meet the critera 0 <= shift
< 32.
result
and input
may be the same object.
staticcompareSigned(a:Vector<Int>, b:Vector<Int>, length:Int):Int
Compare two signed multiword integers.
Returns -1 if a < b
; otherwise
returns 1 if a > b
; otherwise
returns 0 (a == b
).
staticcompareUnsigned(a:Vector<Int>, b:Vector<Int>, length:Int):Int
Compare two unsigned multiword integers.
Returns -1 if a < b
; otherwise
returns 1 if a > b
; otherwise
returns 0 (a == b
).
staticcopy(dest:Vector<Int>, source:Vector<Int>, length:Int):Void
Copies words from one vector to another.
Parameters:
dest | The destination vector. |
---|---|
source | The source vector. |
length | The number of words to copy. |
staticdivideIntUnsigned(dividend:Vector<Int>, dividendLength:Int, divisor:Int, quotientOut:Vector<Int>, work:Vector<Int>):Int
Divide dividend
by divisor
, where both are unsigned.
The quotient of the division is put into quotientOut
;
the remainder is the return value.
quotientOut
must have length >= dividendLength
.
quotientOut
may refer to dividend
.
work
must not refer to any of the inputs, and must have
length >= dividendLength
+ 2.
dividend
is not modified, unless it refers to quotientOut
.
The results are unspecified if divisor
is negative.
staticdivideUnsigned(dividend:Vector<Int>, dividendLength:Int, divisor:Vector<Int>, divisorLength:Int, quotientOut:Vector<Int>, remainderOut:Vector<Int>, work:Vector<Int>):Void
Divide dividend
by divisor
, where both are unsigned.
The quotient of the division is put into quotientOut
;
the remainder is put into remainderOut
.
divisor
must not have any leading zeros.
quotientOut
must have length >= dividendLength
-
divisorLength
+ 1.
remainderOut
may be null
if the remainder value is not
needed. If supplied, it must be of length >= divisorLength
.
quotientOut
and remainderOut
must not refer to the same
object; but either may refer to the inputs.
dividend
and divisor
may refer to the same object.
work
must not refer to any of the inputs, and must have
length >= dividendLength
+ divisorLength
+ 1.
dividend
and divisor
are not modified, unless they
reference one of the outputs.
staticextendUnsigned(result:Vector<Int>, resultLength:Int, input:Vector<Int>, inputLength:Int):Void
Perform unsigned (zero) extension of input
into result
.
input
and result
may refer to the same object.
Parameters:
result | The destination vector. |
---|---|
resultLength | The desired length of the result. |
input | The source vector. |
inputLength | The length of the input. |
staticgetBitSigned(value:Vector<Int>, length:Int, index:Int):Int
Gets the value of a single bit from a signed multi-word integer.
Parameters:
value | The source vector. |
---|---|
length | The number of words. |
index | The index of the bit to get. |
Returns:
1 if the bit is set, 0 otherwise.
staticinlinegetDivisionQuotientLengthUnsigned(dividendLength:Int, divisorLength:Int):Int
Calculates the required length for the quotient of an unsigned division.
Parameters:
dividendLength | The length of the dividend. |
---|---|
divisorLength | The length of the divisor. |
Returns:
The length of the quotient.
staticgetLengthUnsigned(value:Vector<Int>, length:Int):Int
Gets the effective length of an unsigned multi-word integer, ignoring leading zeros.
Parameters:
value | The vector of integer words. |
---|---|
length | The number of words in the value. |
Returns:
The minimal number of words needed to represent the value.
staticinlineisNegative(value:Vector<Int>, length:Int):Bool
Checks if a multi-word integer is negative.
Parameters:
value | The vector of integer words. |
---|---|
length | The number of words in the value. |
Returns:
true
if the most significant bit is set.
staticisZero(value:Vector<Int>, length:Int):Bool
Checks if a multi-word integer is zero.
Parameters:
value | The vector of integer words. |
---|---|
length | The number of words in the value. |
Returns:
true
if the value is zero.
staticlogicalShiftRight(result:Vector<Int>, input:Vector<Int>, length:Int, shift:Int):Void
Shift multiword integer input
right by shift
binary
places and store the result in result
, with zeros inserted
from the left.
shift
must meet the critera 0 <= shift
< 32.
result
and input
may be the same object.
staticmultiplyIntUnsigned(result:Vector<Int>, operand1:Vector<Int>, operand1Length:Int, operand2:Int):Void
Multiply operand1
by operand2
, where both are unsigned,
and put the result into result
.
result
must have length >= operand1Length
+ 1.
result
may not refer the same object as either operand1
or operand2
; however, operand1
and operand2
may be the
same object.
staticmultiplyUnsigned(result:Vector<Int>, operand1:Vector<Int>, operand1Length:Int, operand2:Vector<Int>, operand2Length:Int):Void
Multiply operand1
by operand2
, where both are unsigned,
and put the result into result
.
result
must have length >= operand1Length
+
operand2Length
.
result
may not refer the same object as either operand1
or operand2
; however, operand1
and operand2
may be the
same object.
staticnegate(result:Vector<Int>, operand:Vector<Int>, length:Int):Bool
Perform the unary negation of big integer operand
and put
the result into big integer result
.
Parameters:
result | The vector to store the result. |
---|---|
operand | The vector to negate. |
length | The number of words. |
Returns:
staticsetFromHexUnsigned(dest:Vector<Int>, length:Int, value:String):Bool
Sets a multi-word integer from an unsigned hexadecimal string.
Parameters:
dest | The destination vector. |
---|---|
length | The length of the destination. |
value | The hexadecimal string. |
Returns:
true
on success.
staticsetFromIntUnsigned(dest:Vector<Int>, length:Int, value:Int):Void
Sets a multi-word integer from a single unsigned Int
.
Parameters:
dest | The destination vector. |
---|---|
length | The total length of the destination. |
value | The integer value to set. |
staticsetZero(dest:Vector<Int>, length:Int):Void
Fills a vector with zeros.
Parameters:
dest | The destination vector. |
---|---|
length | The number of words to zero out. |
staticshiftLeft(result:Vector<Int>, input:Vector<Int>, length:Int, shift:Int):Void
Shift multiword integer input
left by shift
binary
places and store the result in result
, with zeros inserted
from the right.
shift
must meet the critera 0 <= shift
< 32.
result
and input
may be the same object.
staticsubtract(result:Vector<Int>, operand1:Vector<Int>, operand2:Vector<Int>, length:Int):Int
Subtract big integer operand2
from big integer operand1
and put the result into big integer result
.
Ok for result
, operand1
, and operand2
to be the same object.
Returns the "borrow" value of either 0 or 1.