OOGmp
in package
implements
HashSerializable
OOGmp is a utility class that wraps PHP's GMP library for working with arbitrary-size integers.
It provides an easy-to-use, object-oriented API for Ethereum-related operations and offers a chainable arithmetic operations API.
Arithmetic Functions:
The class provides basic arithmetic operations like addition (add
), subtraction (sub
), multiplication (mul
), and division (div
).
These methods support automatic type normalization, allowing you to pass in OOGmp|int|GMP
as arguments.
Comparison Functions:
Standard comparison operations are included, such as eq
(equals), lt
(less than), gt
(greater than), etc.
Aliases are also available, like eq
- equal
. These functions also support automatic type normalization.
Tags
Table of Contents
Interfaces
- HashSerializable
- Hash serializable is interface to mark classes that can serialize themselves into blob of max size of hash (ie. fit abi single slot that's 32 bytes)
Properties
- $gmp : GMP
Methods
- __construct() : mixed
- Initializes a new OOGmp object.
- __toString() : string
- add() : static
- div() : static
- eq() : bool
- equal() : bool
- fromBin() : OOGmp
- Static alias to constructor to fulfil HashSerializable interface
- fromHex() : OOGmp
- Static alias to constructor to fulfil HashSerializable interface
- ge() : bool
- greaterOrEqual() : bool
- greaterThan() : bool
- gt() : bool
- le() : bool
- lessOrEqual() : bool
- lessThan() : bool
- lt() : bool
- max() : static
- min() : static
- mod() : static
- mul() : static
- raw() : GMP
- Returns the raw GMP object.
- sub() : static
- toBin() : string
- Converts the internal GMP number to a binary string.
- toHex() : string
- Alias to toString() to fulfil HashSerializable interface
- toInt() : int
- Converts the internal GMP number to an integer.
- toString() : string
- Converts the internal GMP number to a string.
- wrap() : OOGmp
- Wraps a raw GMP object into an OOGmp instance.
- inNormalize() : OOGmp
Properties
$gmp
private
GMP
$gmp
Methods
__construct()
Initializes a new OOGmp object.
public
__construct([null|string|GMP $number = null ][, int|null $base = null ]) : mixed
Parameters
- $number : null|string|GMP = null
-
The initial number value as null, string, or GMP object.
- $base : int|null = null
-
The base for string input. Defaults attempts to guess, if $number has 0x prefix, it defaults to 16, otherwise if it has any of a-f characters, it defaults to 16, otherwise it defaults to 10. Be very cautions when relying on that detection as non-0x-prefixed hex that happens to not have any a-f will be mistreated as base = 10.
__toString()
public
__toString() : string
Return values
stringadd()
public
add(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
staticdiv()
public
div(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
staticeq()
public
eq(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolequal()
public
equal(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolfromBin()
Static alias to constructor to fulfil HashSerializable interface
public
static fromBin(string $bin) : OOGmp
Parameters
- $bin : string
Return values
OOGmpfromHex()
Static alias to constructor to fulfil HashSerializable interface
public
static fromHex(string $hex) : OOGmp
Parameters
- $hex : string
Return values
OOGmpge()
public
ge(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolgreaterOrEqual()
public
greaterOrEqual(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolgreaterThan()
public
greaterThan(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolgt()
public
gt(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolle()
public
le(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boollessOrEqual()
public
lessOrEqual(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boollessThan()
public
lessThan(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boollt()
public
lt(OOGmp|int|GMP $b) : bool
Parameters
- $b : OOGmp|int|GMP
Return values
boolmax()
public
max(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
staticmin()
public
min(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
staticmod()
public
mod(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
staticmul()
public
mul(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
staticraw()
Returns the raw GMP object.
public
raw() : GMP
Return values
GMP —The internal GMP object.
sub()
public
sub(OOGmp|int|GMP $b) : static
Parameters
- $b : OOGmp|int|GMP
Return values
statictoBin()
Converts the internal GMP number to a binary string.
public
toBin([int|null $lpad0 = null ]) : string
Parameters
- $lpad0 : int|null = null
-
Number of zeros to pad on the left.
Tags
Return values
string —The binary string representation of the GMP number.
toHex()
Alias to toString() to fulfil HashSerializable interface
public
toHex() : string
Return values
stringtoInt()
Converts the internal GMP number to an integer.
public
toInt() : int
Tags
Return values
int —The integer representation of the GMP number.
toString()
Converts the internal GMP number to a string.
public
toString([bool $hex = false ][, bool $no0xHex = false ][, int|null $lpad0 = null ]) : string
Parameters
- $hex : bool = false
-
If true, returns a hexadecimal string. Otherwise, returns a decimal string.
- $no0xHex : bool = false
-
If true and $hex is true, omits the "0x" prefix.
- $lpad0 : int|null = null
-
Number of zeros to pad on the left.
Return values
string —The string representation of the GMP number.
wrap()
Wraps a raw GMP object into an OOGmp instance.
public
static wrap(GMP $raw) : OOGmp
Parameters
- $raw : GMP
-
The GMP object to be wrapped.
Return values
OOGmp —The new OOGmp instance wrapping the given GMP object.
inNormalize()
private
inNormalize(OOGmp|int|GMP $b) : OOGmp
Parameters
- $b : OOGmp|int|GMP