Menu

Reference / Manticore\Ds

IntTypedArray

abstractclass
abstract class IntTypedArray<T> extends TypedArray

The integer arrays: every element is an int inside the range of its width.

Assigning accepts an int, a bool (as 0 or 1), a float with a whole value and a numeric string with a whole value ('5', '5.0'). The value must fit the element type: a whole number outside the range throws ValueError and nothing is stored, so values never wrap or truncate. A float with a fraction, NaN, infinity, null, an array, an object or a non-numeric string throws TypeError. Reading always gives an int.

The concrete classes ({@see Int8Array}, {@see UInt8Array}, {@see Int16Array}, {@see UInt16Array}, {@see Int32Array}, {@see UInt32Array}, {@see Int64Array}, {@see UInt64Array}) differ only in width and signedness.

Type parameters

T
= int

Methods

offsetGet()Returns the element at $offset: $a[$offset].
offsetSet()Stores $value at $offset: $a[$offset] = $value; $a[] = $value appends.
sum()The sum of the elements (wraps past the int range, as native ints do).
min()Returns the smallest element.
max()Returns the largest element.

offsetGet()#source

function offsetGet(mixed $offset): int

Returns the element at $offset: $a[$offset].

Parameters

$offset mixed
the index

Returns

T — the element

Throws

\OutOfBoundsException
when the position is outside 0..count-1
\TypeError
when $offset is of the wrong kind

offsetSet()#source

function offsetSet(mixed $offset, mixed $value): void

Stores $value at $offset: $a[$offset] = $value; $a[] = $value appends.

Parameters

$offset mixed
the index, or null to append
$value mixed
the element

Throws

\OutOfBoundsException
when the position is outside 0..count-1
\ValueError
when $value is out of range for the element type
\TypeError
when $value or $offset is of the wrong kind

sum()#source

function sum(): int

The sum of the elements (wraps past the int range, as native ints do).

Returns

int — the sum; 0 for an empty array

min()#source

function min(): int

Returns the smallest element.

Returns

int — the minimum

Throws

\ValueError
when the array is empty

max()#source

function max(): int

Returns the largest element.

Returns

int — the maximum

Throws

\ValueError
when the array is empty

View source