CooperInteger
in package
implements
Stringable
A CASC integer (CASC.md §6.3) too large for PHP's 64-bit `int` -- `12345678901234567890`, or `!int("...")` of one -- kept exactly, as the Elixir original's arbitrary-precision integers are.
Only ever constructed for a magnitude outside PHP_INT_MIN.. PHP_INT_MAX (see represent(), the one entry point the pipeline
uses): an integer that fits stays a native int, so port = 8080
never needs unwrapping. This is php-dextrin's own hybrid rule, backed
by bcmath the same way. Rendering, comparison, and the digits are
all a config value needs; arithmetic is left to the caller (bcadd()
and friends take $digits directly).
Table of Contents
Interfaces
- Stringable
Properties
- $digits : numeric-string
- Canonical decimal digits: no leading zeros, `-` only when negative.
Methods
- __construct() : mixed
- __toString() : string
- The decimal digits -- also valid CASC if fed back in, and what the value reads as inside a string (§7).
- equals() : bool
- fitsInInt() : bool
- represent() : int|self
- The value of `$digits` as CASC holds it: a native `int` when it fits in one, a `CooperInteger` otherwise.
- toFloat() : float
Properties
$digits read-only
Canonical decimal digits: no leading zeros, `-` only when negative.
public
numeric-string
$digits
Methods
__construct()
public
__construct(string $digits) : mixed
Parameters
- $digits : string
-
decimal digits, optionally signed with
-
Tags
__toString()
The decimal digits -- also valid CASC if fed back in, and what the value reads as inside a string (§7).
public
__toString() : string
Return values
string —the digits
equals()
public
equals(mixed $other) : bool
Parameters
- $other : mixed
-
the value to compare against
Return values
bool —true for a CooperInteger with the same value -- never
for an int or a float, which strict CASC equality
(§8.4) keeps apart
fitsInInt()
public
fitsInInt() : bool
Return values
bool —whether the value lies within PHP_INT_MIN..PHP_INT_MAX
represent()
The value of `$digits` as CASC holds it: a native `int` when it fits in one, a `CooperInteger` otherwise.
public
static represent(string $digits) : int|self
Parameters
- $digits : string
-
decimal digits, optionally signed with
-
Return values
int|self —the integer
toFloat()
public
toFloat() : float
Return values
float —the nearest float, as !float(...) converts it