php-dextrin

DXNInteger
in package
implements DXNValueInterface

FinalYes

An arbitrary-precision integer, backed by `bcmath` (no `ext-gmp` assumed available) -- only ever constructed for a magnitude outside `PHP_INT_MIN..PHP_INT_MAX`. {@see DXNInteger::represent()} is the canonical entry point embodying the project's hybrid integer rule: a value that fits stays a native `int` everywhere (ordinary `+`, `-`, comparisons just work); only genuine overflow reaches this class, whose own arithmetic is method calls, not operators -- PHP has no operator overloading for arithmetic.

Table of Contents

Interfaces

DXNValueInterface
Implemented by every `DXN*` wrapper class -- the PHP analog of the `dxnType` string tag used for kind dispatch in the JS port, and of `Dextrin.Value`'s closed type union in the Elixir original. Native PHP values (`null`, `bool`, `int`, `float`, `string`, and `array` for `map`/`array`) never implement this; {@see Equality::kindOf()} handles those directly.

Constants

DXN_TYPE  : mixed = 'integer'

Properties

$value  : numeric-string
Canonical decimal digits, no leading zeros, "-" only if negative and nonzero.

Methods

__construct()  : mixed
__toString()  : string
compareTo()  : int
A total order against any other DXN value, not just another instance of this class -- backs {@see DXNSortedSet}. Cross-kind ordering is implementation-defined per DXN.md; within a kind, uses the kind's own natural order where one exists, or a deterministic structural fallback where it doesn't.
dxnType()  : string
The DXN type name this value represents, e.g. "symbol", "uuid".
equals()  : bool
Structural equality, recursing into nested DXN values as needed.
fitsInInt()  : bool
fromInt()  : self
fromString()  : self
minus()  : self
negate()  : self
plus()  : self
represent()  : int|self
The hybrid rule's entry point: returns a native `int` when `$numeric` fits in `PHP_INT_MIN..PHP_INT_MAX`, a `DXNInteger` otherwise. Callers (the lexer, the binary decoder) should use this rather than deciding the boundary themselves.
times()  : self
toInt()  : int
toString()  : numeric-string
fitsInIntString()  : bool
normalizeDigits()  : numeric-string
operand()  : numeric-string

Constants

Properties

$value read-only

Canonical decimal digits, no leading zeros, "-" only if negative and nonzero.

private numeric-string $value

Methods

__construct()

public __construct(string $value) : mixed
Parameters
$value : string

__toString()

public __toString() : string
Return values
string

compareTo()

A total order against any other DXN value, not just another instance of this class -- backs {@see DXNSortedSet}. Cross-kind ordering is implementation-defined per DXN.md; within a kind, uses the kind's own natural order where one exists, or a deterministic structural fallback where it doesn't.

public compareTo(mixed $other) : int
Parameters
$other : mixed
Return values
int

dxnType()

The DXN type name this value represents, e.g. "symbol", "uuid".

public dxnType() : string
Return values
string

equals()

Structural equality, recursing into nested DXN values as needed.

public equals(mixed $other) : bool
Parameters
$other : mixed
Return values
bool

fitsInInt()

public fitsInInt() : bool
Return values
bool

fromInt()

public static fromInt(int $n) : self
Parameters
$n : int
Return values
self

fromString()

public static fromString(string $numeric) : self
Parameters
$numeric : string
Return values
self

minus()

public minus(int|self $other) : self
Parameters
$other : int|self
Return values
self

negate()

public negate() : self
Return values
self

plus()

public plus(int|self $other) : self
Parameters
$other : int|self
Return values
self

represent()

The hybrid rule's entry point: returns a native `int` when `$numeric` fits in `PHP_INT_MIN..PHP_INT_MAX`, a `DXNInteger` otherwise. Callers (the lexer, the binary decoder) should use this rather than deciding the boundary themselves.

public static represent(string $numeric) : int|self
Parameters
$numeric : string
Return values
int|self

times()

public times(int|self $other) : self
Parameters
$other : int|self
Return values
self

toString()

public toString() : numeric-string
Return values
numeric-string

fitsInIntString()

private static fitsInIntString(numeric-string $normalized) : bool
Parameters
$normalized : numeric-string
Return values
bool

normalizeDigits()

private static normalizeDigits(string $s) : numeric-string
Parameters
$s : string
Return values
numeric-string

operand()

private static operand(int|self $other) : numeric-string
Parameters
$other : int|self
Return values
numeric-string
On this page

Search results