DXNDecimal
in package
implements
DXNValueInterface
DXN `decimal` (`19.99M`) -- an exact fixed-point number, `sign * unscaledValue * 10^exponent`. `unscaledValue` is always a numeric string (bcmath-formatted), independent of the top-level integer hybrid rule ({@see DXNInteger}) -- exact decimal arithmetic needs bcmath regardless of magnitude, so there's no native-`int` fast path to preserve here the way there is for a bare `integer`.
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 = 'decimal'
Properties
- $exponent : int
- $sign : int
- $unscaledValue : numeric-string
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.
- fromFloat() : self
- fromString() : self
- Parses a decimal *literal* (`digits(.digits)?`, no trailing `M`, no sign handling beyond a leading `-`) exactly -- unlike {@see self::fromFloat()}, this never goes through a binary `float` at all, so it can't introduce the representation noise a literal like `19.99` would pick up by round-tripping through IEEE 754 first.
- toFloat() : float
- toString() : numeric-string
Constants
DXN_TYPE
private
mixed
DXN_TYPE
= 'decimal'
Properties
$exponent read-only
public
int
$exponent
$sign read-only
public
int
$sign
$unscaledValue read-only
public
numeric-string
$unscaledValue
Methods
__construct()
public
__construct(int $sign, string $unscaledValue, int $exponent) : mixed
Parameters
- $sign : int
- $unscaledValue : string
- $exponent : int
__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
boolfromFloat()
public
static fromFloat(float $n) : self
Parameters
- $n : float
Return values
selffromString()
Parses a decimal *literal* (`digits(.digits)?`, no trailing `M`, no sign handling beyond a leading `-`) exactly -- unlike {@see self::fromFloat()}, this never goes through a binary `float` at all, so it can't introduce the representation noise a literal like `19.99` would pick up by round-tripping through IEEE 754 first.
public
static fromString(string $text) : self
Parameters
- $text : string
Return values
selftoFloat()
public
toFloat() : float
Return values
floattoString()
public
toString() : numeric-string