FixUtil Documentation
Back to summary
import "util/bigint";
BigInteger class
This class allows to work easilly with arbitrary big integers.
Supported operators:
+
,
-
,
*
,
/
,
%
,
<<
,
>>
,
<
,
>
,
<=
,
>=
with BigInteger and Integer types.
A short variant of the constructors is available: BigInteger(...)
Note: the non-class functions are using a shorter bigint
prefix for functions.
Initialization
static function create(): BigInteger
static function create(value: Integer): BigInteger
-
Creates a new big integer with given value (or zero).
static function from_uint(value: Integer): BigInteger
-
Creates a new big integer with given unsigned integer value.
static function from_string(s: String): BigInteger
-
Creates a new big integer from string representation, throwing an error on improper format.
static function from_hex_string(s: String): BigInteger
-
Creates a new big integer from hexadecimal string representation (can be negative and
can contain an optional
0x
prefix), throwing an error on improper format.
static function from_bytes_BE(bytes: Byte[]): BigInteger
static function from_bytes_BE(bytes: Byte[], off: Integer, len: Integer): BigInteger
static function from_bytes_LE(bytes: Byte[]): BigInteger
static function from_bytes_LE(bytes: Byte[], off: Integer, len: Integer): BigInteger
-
Creates a new big positive integer from bytes representing the number. The
bytes can be in either Big Endian (BE) or Little Endian (LE) ordering and
optionally you can pass an offset and length within the provided array.
Operations
function add(other: BigInteger): BigInteger
-
Adds two big integers and returns the result.
function sub(other: BigInteger): BigInteger
-
Subtracts two big integers and returns the result.
function mul(other: BigInteger): BigInteger
-
Multiplies two big integers and returns the result.
function div(other: BigInteger): BigInteger
-
Divides two big integers and returns the quotient.
function rem(other: BigInteger): BigInteger
-
Divides two big integers and returns the remainder.
function divrem(other: BigInteger): BigInteger
-
Divides two big integers and returns the result as two values (first
is the quotient and the second is the remainder). You need to explicitly
check for errors by comparing the first value to
null
.
function mod(other: BigInteger): BigInteger
-
Divides two big integers and returns the modulus.
function abs(): BigInteger
-
Returns the absolute value.
function shl(amount: Integer): BigInteger
-
Shifts the bits left (towards high order part) and returns the result.
function shr(amount: Integer): BigInteger
-
Shifts the bits right (towards low order part) and returns the result.
function modpow(exponent: BigInteger, modulus: BigInteger): BigInteger
-
Computes modular exponentiation and returns the result.
function modinverse(modulus: BigInteger): BigInteger
-
Computes modular multiplicative inverse and returns the result.
Properties
function is_zero(): Boolean
-
Returns true when the value is zero.
function cmp_lt(other: Integer): Boolean
function cmp_le(other: Integer): Boolean
function cmp_gt(other: Integer): Boolean
function cmp_ge(other: Integer): Boolean
-
Returns the result of comparison. There are 4 variants:
lt - less than
le - less than or equal
gt - greater than
ge - greater than or equal
function get_bit_size(): Integer
-
Returns the number of bits used to represent the value.
function is_bit_set(pos: Integer): Boolean
-
Returns whether a bit on given position is set.
function to_int(): Integer
-
Returns the value as a 32-bit signed integer, throwing an error in case it can't fit.
function to_uint(): Integer
-
Returns the value as a 32-bit unsigned integer, throwing an error in case it can't fit.
function to_string(): String
-
Returns the string representation of the value.
function to_hex_string(): String
function to_hex_string(use_prefix: Boolean): String
-
Returns the hex string representation of the value. Optionally
you can disable prepending of the
0x
prefix.
function to_bytes_BE(): Byte[]
function to_bytes_LE(): Byte[]
-
Returns the byte representation of the value. Negative numbers
are not supported. The bytes can be in either Big Endian (BE) or
Little Endian (LE) ordering.