Documentation

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
author

DubbaThony

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

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
string

add()

public add(OOGmp|int|GMP $b) : static
Parameters
$b : OOGmp|int|GMP
Return values
static

div()

public div(OOGmp|int|GMP $b) : static
Parameters
$b : OOGmp|int|GMP
Return values
static

eq()

public eq(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

equal()

public equal(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

fromBin()

Static alias to constructor to fulfil HashSerializable interface

public static fromBin(string $bin) : OOGmp
Parameters
$bin : string
Return values
OOGmp

fromHex()

Static alias to constructor to fulfil HashSerializable interface

public static fromHex(string $hex) : OOGmp
Parameters
$hex : string
Return values
OOGmp

ge()

public ge(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

greaterOrEqual()

public greaterOrEqual(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

greaterThan()

public greaterThan(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

gt()

public gt(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

le()

public le(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

lessOrEqual()

public lessOrEqual(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

lessThan()

public lessThan(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

lt()

public lt(OOGmp|int|GMP $b) : bool
Parameters
$b : OOGmp|int|GMP
Return values
bool

max()

public max(OOGmp|int|GMP $b) : static
Parameters
$b : OOGmp|int|GMP
Return values
static

min()

public min(OOGmp|int|GMP $b) : static
Parameters
$b : OOGmp|int|GMP
Return values
static

mod()

public mod(OOGmp|int|GMP $b) : static
Parameters
$b : OOGmp|int|GMP
Return values
static

mul()

public mul(OOGmp|int|GMP $b) : static
Parameters
$b : OOGmp|int|GMP
Return values
static

raw()

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
static

toBin()

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
throws
InvalidHexException
Return values
string

The binary string representation of the GMP number.

toHex()

Alias to toString() to fulfil HashSerializable interface

public toHex() : string
Return values
string

toInt()

Converts the internal GMP number to an integer.

public toInt() : int
Tags
throws
EthBinderRuntimeException

If the GMP number is larger than PHP_INT_MAX.

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.


        
On this page

Search results