DXNInteger
in package
implements
DXNValueInterface
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
DXN_TYPE
private
mixed
DXN_TYPE
= 'integer'
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
stringcompareTo()
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
intdxnType()
The DXN type name this value represents, e.g. "symbol", "uuid".
public
dxnType() : string
Return values
stringequals()
Structural equality, recursing into nested DXN values as needed.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
Return values
boolfitsInInt()
public
fitsInInt() : bool
Return values
boolfromInt()
public
static fromInt(int $n) : self
Parameters
- $n : int
Return values
selffromString()
public
static fromString(string $numeric) : self
Parameters
- $numeric : string
Return values
selfminus()
public
minus(int|self $other) : self
Parameters
- $other : int|self
Return values
selfnegate()
public
negate() : self
Return values
selfplus()
public
plus(int|self $other) : self
Parameters
- $other : int|self
Return values
selfrepresent()
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|selftimes()
public
times(int|self $other) : self
Parameters
- $other : int|self
Return values
selftoInt()
public
toInt() : int
Return values
inttoString()
public
toString() : numeric-string
Return values
numeric-stringfitsInIntString()
private
static fitsInIntString(numeric-string $normalized) : bool
Parameters
- $normalized : numeric-string
Return values
boolnormalizeDigits()
private
static normalizeDigits(string $s) : numeric-string
Parameters
- $s : string
Return values
numeric-stringoperand()
private
static operand(int|self $other) : numeric-string
Parameters
- $other : int|self