RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya docs · Core libraries

Typed data and SIMD

Typed lists and byte buffers, ByteData views, and the SIMD types Float32x4, Int32x4 and Float64x2.

import 'raya:typed_data';
23 classes224 functions and methods498 of 776 documented207 runnable examples

Overview

Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types.

To use this library in your code:

import 'raya:typed_data';

Classes

abstract final class ByteBuffer

A sequence of bytes underlying a typed data object.

Used to process large quantities of binary or numerical data more efficiently using a typed view.

It is a compile-time error for a class to attempt to extend or implement ByteBuffer.

Properties

int get lengthInBytes

The length of this byte buffer, in bytes.

Methods

Uint8List asUint8List([int offsetInBytes = 0, int? length])

Creates a Uint8List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Uint8List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.

The start index and length must describe a valid range of the buffer:

  • offsetInBytes must not be negative,
  • length must not be negative, and
  • offsetInBytes + length must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final words = Uint32List.fromList([0x04030201, 0x08070605]);
  final buf = words.buffer;
  print('all bytes:      ${buf.asUint8List()}');
  print('from offset 4:  ${buf.asUint8List(4)}');
  print('2 bytes at 2:   ${buf.asUint8List(2, 2)}');
  // A view shares memory: writing a byte changes the word.
  buf.asUint8List()[0] = 0xFF;
  print('word 0 now:     0x${words[0].toRadixString(16)}');
}
Output
all bytes:      [1, 2, 3, 4, 5, 6, 7, 8]
from offset 4:  [5, 6, 7, 8]
2 bytes at 2:   [3, 4]
word 0 now:     0x40302ff
Int8List asInt8List([int offsetInBytes = 0, int? length])

Creates a Int8List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Int8List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.

The start index and length must describe a valid range of the buffer:

  • offsetInBytes must not be negative,
  • length must not be negative, and
  • offsetInBytes + length must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([0, 1, 127, 128, 200, 255]);
  final signed = bytes.buffer.asInt8List();
  print('unsigned: $bytes');
  print('signed:   $signed');
  print('middle 2: ${bytes.buffer.asInt8List(2, 2)}');
}
Output
unsigned: [0, 1, 127, 128, 200, 255]
signed:   [0, 1, 127, -128, -56, -1]
middle 2: [127, -128]
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length])

Creates a Uint8ClampedList view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Uint8ClampedList will also change the buffer, and vice versa.

The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.

The start index and length must describe a valid range of the buffer:

  • offsetInBytes must not be negative,
  • length must not be negative, and
  • offsetInBytes + length must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final buf = Uint8List(4).buffer;
  final clamped = buf.asUint8ClampedList();
  clamped[0] = 300; // clamps to 255
  clamped[1] = -5;  // clamps to 0
  clamped[2] = 128;
  print('clamped view: $clamped');
  print('same bytes:   ${buf.asUint8List()}');
}
Output
clamped view: [255, 0, 128, 0]
same bytes:   [255, 0, 128, 0]
Uint16List asUint16List([int offsetInBytes = 0, int? length])

Creates a Uint16List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Uint16List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 16-bit aligned, and contains length 16-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not even, the last byte can't be part of the view.

The start index and length must describe a valid 16-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by two,
  • length must not be negative, and
  • offsetInBytes + length * 2 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([0x01, 0x00, 0xFF, 0xFF, 0x34, 0x12]);
  final halves = bytes.buffer.asUint16List();
  // Host byte order (little-endian on common machines).
  print('uint16 lanes: ${halves.map((v) => '0x${v.toRadixString(16)}').toList()}');
  print('from byte 2:  ${bytes.buffer.asUint16List(2, 1)}');
}
Output
uint16 lanes: [0x1, 0xffff, 0x1234]
from byte 2:  [65535]
Int16List asInt16List([int offsetInBytes = 0, int? length])

Creates a Int16List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Int16List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 16-bit aligned, and contains length 16-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not even, the last byte can't be part of the view.

The start index and length must describe a valid 16-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by two,
  • length must not be negative, and
  • offsetInBytes + length * 2 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final raw = Uint16List.fromList([1, 32767, 32768, 65535]);
  final signed = raw.buffer.asInt16List();
  print('unsigned: $raw');
  print('signed:   $signed');
}
Output
unsigned: [1, 32767, 32768, 65535]
signed:   [1, 32767, -32768, -1]
Uint32List asUint32List([int offsetInBytes = 0, int? length])

Creates a Uint32List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Uint32List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 32-bit aligned, and contains length 32-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by four, the last bytes can't be part of the view.

The start index and length must describe a valid 32-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by four,
  • length must not be negative, and
  • offsetInBytes + length * 4 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final f = Float32List.fromList([1.0, -2.0, 0.5]);
  final bits = f.buffer.asUint32List();
  for (var i = 0; i < f.length; i++) {
    print('${f[i]} -> bits 0x${bits[i].toRadixString(16).padLeft(8, '0')}');
  }
}
Output
1.0 -> bits 0x3f800000
-2.0 -> bits 0xc0000000
0.5 -> bits 0x3f000000
Int32List asInt32List([int offsetInBytes = 0, int? length])

Creates a Int32List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Int32List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 32-bit aligned, and contains length 32-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by four, the last bytes can't be part of the view.

The start index and length must describe a valid 32-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by four,
  • length must not be negative, and
  • offsetInBytes + length * 4 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final buf = Uint8List(12).buffer;
  final ints = buf.asInt32List();
  ints[0] = -1;
  ints[2] = 1 << 30;
  print('int32 view: $ints');
  print('bytes:      ${buf.asUint8List()}');
  print('last word:  ${buf.asInt32List(8)}');
}
Output
int32 view: [-1, 0, 1073741824]
bytes:      [255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 64]
last word:  [1073741824]
Uint64List asUint64List([int offsetInBytes = 0, int? length])

Creates a Uint64List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Uint64List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 64-bit aligned, and contains length 64-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by eight, the last bytes can't be part of the view.

The start index and length must describe a valid 64-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by eight,
  • length must not be negative, and
  • offsetInBytes + length * 8 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
  final words = bytes.buffer.asUint64List();
  print('length: ${words.length}');
  print('word 0: ${words[0]}');
  print('word 1: 0x${words[1].toRadixString(16)}');
}
Output
length: 2
word 0: 1
word 1: 0x100000000000000
Int64List asInt64List([int offsetInBytes = 0, int? length])

Creates a Int64List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Int64List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 64-bit aligned, and contains length 64-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by eight, the last bytes can't be part of the view.

The start index and length must describe a valid 64-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by eight,
  • length must not be negative, and
  • offsetInBytes + length * 8 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final buf = Uint8List(16).buffer;
  final longs = buf.asInt64List();
  longs[0] = -2;
  longs[1] = 1 << 40;
  print('int64 view: $longs');
  print('first 8 bytes: ${buf.asUint8List(0, 8)}');
}
Output
int64 view: [-2, 1099511627776]
first 8 bytes: [254, 255, 255, 255, 255, 255, 255, 255]
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length])

Creates a Int32x4List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Int32x4List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 128-bit aligned, and contains length 128-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by 16, the last bytes can't be part of the view.

The start index and length must describe a valid 128-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by sixteen,
  • length must not be negative, and
  • offsetInBytes + length * 16 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final ints = Int32List.fromList([1, 2, 3, 4, 5, 6, 7, 8]);
  final lanes = ints.buffer.asInt32x4List();
  print('vectors: ${lanes.length}');
  for (final v in lanes) {
    print('x=${v.x} y=${v.y} z=${v.z} w=${v.w}');
  }
}
Output
vectors: 2
x=1 y=2 z=3 w=4
x=5 y=6 z=7 w=8
Float32List asFloat32List([int offsetInBytes = 0, int? length])

Creates a Float32List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Float32List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 32-bit aligned, and contains length 32-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by four, the last bytes can't be part of the view.

The start index and length must describe a valid 32-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by four,
  • length must not be negative, and
  • offsetInBytes + length * 4 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final bits = Uint32List.fromList([0x3F800000, 0x40490FDB, 0x7F800000]);
  final floats = bits.buffer.asFloat32List();
  print('1.0 bits     -> ${floats[0]}');
  print('pi bits      -> ${floats[1]}');
  print('infinity bits-> ${floats[2]}');
}
Output
1.0 bits     -> 1.0
pi bits      -> 3.1415927410125732
infinity bits-> Infinity
Float64List asFloat64List([int offsetInBytes = 0, int? length])

Creates a Float64List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Float64List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 64-bit aligned, and contains length 64-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by eight, the last bytes can't be part of the view.

The start index and length must describe a valid 64-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by eight,
  • length must not be negative, and
  • offsetInBytes + length * 8 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final buf = Uint8List(24).buffer;
  final d = buf.asFloat64List();
  d[0] = 0.1;
  d[1] = 1e300;
  print('values: ${d.sublist(0, 2)}');
  print('second double from offset 8: ${buf.asFloat64List(8, 1)}');
  print('bytes of 0.1: ${buf.asUint8List(0, 8)}');
}
Output
values: [0.1, 1e+300]
second double from offset 8: [1e+300]
bytes of 0.1: [154, 153, 153, 153, 153, 153, 185, 63]
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length])

Creates a Float32x4List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Float32x4List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 128-bit aligned, and contains length 128-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by 16, the last bytes can't be part of the view.

The start index and length must describe a valid 128-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by sixteen,
  • length must not be negative, and
  • offsetInBytes + length * 16 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final f = Float32List.fromList([1, 2, 3, 4, 10, 20, 30, 40]);
  final v = f.buffer.asFloat32x4List();
  final sum = v[0] + v[1];
  print('vectors: ${v.length}');
  print('sum lanes: ${sum.x} ${sum.y} ${sum.z} ${sum.w}');
}
Output
vectors: 2
sum lanes: 11.0 22.0 33.0 44.0
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length])

Creates a Float64x2List view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the Float64x2List will also change the buffer, and vice versa.

The viewed region start at offsetInBytes, which must be 128-bit aligned, and contains length 128-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by 16, the last bytes can't be part of the view.

The start index and length must describe a valid 128-bit aligned range of the buffer:

  • offsetInBytes must not be negative,
  • offsetInBytes must be divisible by sixteen,
  • length must not be negative, and
  • offsetInBytes + length * 16 must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final d = Float64List.fromList([1.5, 2.5, 3.0, 4.0]);
  final pairs = d.buffer.asFloat64x2List();
  for (var i = 0; i < pairs.length; i++) {
    print('pair $i: (${pairs[i].x}, ${pairs[i].y})');
  }
}
Output
pair 0: (1.5, 2.5)
pair 1: (3.0, 4.0)
ByteData asByteData([int offsetInBytes = 0, int? length])

Creates a ByteData view of a region of this byte buffer.

The view is backed by the bytes of this byte buffer. Any changes made to the ByteData will also change the buffer, and vice versa.

The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.

The start index and length must describe a valid range of the buffer:

  • offsetInBytes must not be negative,
  • length must not be negative, and
  • offsetInBytes + length must not be greater than lengthInBytes.
Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([0x12, 0x34, 0x56, 0x78]);
  final view = bytes.buffer.asByteData();
  print('big-endian u32:    0x${view.getUint32(0).toRadixString(16)}');
  print('little-endian u32: 0x${view.getUint32(0, Endian.little).toRadixString(16)}');
  print('u16 at 2 (big):    0x${bytes.buffer.asByteData(2).getUint16(0).toRadixString(16)}');
}
Output
big-endian u32:    0x12345678
little-endian u32: 0x78563412
u16 at 2 (big):    0x5678
abstract final class TypedData

A typed view of a sequence of bytes.

It is a compile-time error for a class to attempt to extend or implement TypedData.

Properties

int get elementSizeInBytes

The number of bytes in the representation of each element in this list.

int get offsetInBytes

The offset of this view into the underlying byte buffer, in bytes.

int get lengthInBytes

The length of this view, in bytes.

buffergetter
ByteBuffer get buffer

The byte buffer associated with this object.

abstract final class TypedDataList<E> implements TypedData, List<E>

A TypedData fixed-length List-view on the bytes of buffer.

class

Endian

final class Endian

Endianness of number representation.

The order of bytes in memory of a number representation, with little endian having the least significant byte first, and big endian (aka. Network byte order) having the most significant byte first.

The host endian is the native endianness of the underlying platform, and the default endianness used by typed-data lists, like Uint16List, on this platform. Always one of little or big endian.

Can be specified when accessing or updating a sequence of bytes using a ByteData view. The host endianness can be used if accessing larger numbers by their bytes, for example through a Uint8List view on a buffer written using an Int64List view of the same buffer..

It is a compile-time error for a class to attempt to extend or implement Endian.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(4)..setInt32(0, 1, Endian.little);
  print('1 little-endian: ${b.buffer.asUint8List()}');
  b.setInt32(0, 1, Endian.big);
  print('1 big-endian:    ${b.buffer.asUint8List()}');
}
Output
1 little-endian: [1, 0, 0, 0]
1 big-endian:    [0, 0, 0, 1]

Static

bigconstant
static const Endian big = Endian._(false)
littleconstant
static const Endian little = Endian._(true)
hoststaticfield
static final Endian host
abstract final class ByteData implements TypedData

A fixed-length, random-access sequence of bytes that also provides random and unaligned access to the fixed-width integers and floating point numbers represented by those bytes.

ByteData may be used to pack and unpack data from external sources (such as networks or files systems), and to process large quantities of numerical data more efficiently than would be possible with ordinary List implementations. ByteData can save space, by eliminating the need for object headers, and time, by eliminating the need for data copies.

If data comes in as bytes, they can be converted to ByteData by sharing the same buffer.

Uint8List bytes = ...;
var blob = ByteData.sublistView(bytes);
if (blob.getUint32(0, Endian.little) == 0x04034b50) { // Zip file marker
  ...
}

Finally, ByteData may be used to intentionally reinterpret the bytes representing one arithmetic type as another. For example this code fragment determine what 32-bit signed integer is represented by the bytes of a 32-bit floating point number (both stored as big endian):

var bdata = ByteData(8);
bdata.setFloat32(0, 3.04);
int huh = bdata.getInt32(0); // 0x40428f5c

It is a compile-time error for a class to attempt to extend or implement ByteData.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setUint16(0, 0xCAFE, Endian.big);
  b.setUint16(2, 0xCAFE, Endian.little);
  b.setFloat32(4, 1.5);
  final bytes = b.buffer.asUint8List();
  print('bytes: ${bytes.map((x) => x.toRadixString(16).padLeft(2, '0')).join(' ')}');
  print('read big-endian:    0x${b.getUint16(0).toRadixString(16)}');
  print('read little-endian: 0x${b.getUint16(2, Endian.little).toRadixString(16)}');
  print('float32 back:       ${b.getFloat32(4)}');
}
Output
bytes: ca fe fe ca 3f c0 00 00
read big-endian:    0xcafe
read little-endian: 0xcafe
float32 back:       1.5

Constructors

ByteDatafactory
external factory ByteData(int length)

Creates a ByteData of the specified length (in elements), all of whose bytes are initially zero.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(6);
  print('lengthInBytes: ${b.lengthInBytes}');
  b.setUint8(0, 7);
  b.setUint16(1, 0x0102);
  print('bytes: ${b.buffer.asUint8List()}');
}
Output
lengthInBytes: 6
bytes: [7, 1, 2, 0, 0, 0]
factory ByteData.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates an ByteData view of the specified region in buffer.

Changes in the ByteData will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + length must be less than or equal to the length of buffer.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing ByteData.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

ByteData.view(other.buffer, other.offsetInBytes, count)

Alternatively, use ByteData.sublistView which includes this computation:

ByteData.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([0, 0, 0x01, 0x00, 0, 0]);
  final mid = ByteData.view(bytes.buffer, 2, 2);
  print('view length: ${mid.lengthInBytes}');
  print('u16 big:     ${mid.getUint16(0)}');
  mid.setUint8(1, 0xFF);
  print('backing:     $bytes');
}
Output
view length: 2
u16 big:     256
backing:     [0, 0, 1, 255, 0, 0]
factory ByteData.sublistView(TypedData data, [int start = 0, int? end])

Creates a ByteData view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

Example
import 'raya:typed_data';

void main() {
  final samples = Int16List.fromList([100, -200, 300]);
  // Elements 1..3 of an Int16List = bytes 2..6.
  final view = ByteData.sublistView(samples, 1);
  print('view bytes:  ${view.lengthInBytes}');
  print('sample 1 LE: ${view.getInt16(0, Endian.little)}');
  print('sample 2 LE: ${view.getInt16(2, Endian.little)}');
}
Output
view bytes:  4
sample 1 LE: -200
sample 2 LE: 300

Methods

ByteData asUnmodifiableView()

A read-only view of this ByteData.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(2)..setUint16(0, 513);
  final ro = b.asUnmodifiableView();
  print('read: ${ro.getUint16(0)}');
  try {
    ro.setUint8(0, 1);
  } on UnsupportedError catch (e) {
    print('write refused: ${e.runtimeType}');
  }
  b.setUint16(0, 7);
  print('sees owner change: ${ro.getUint16(0)}');
}
Output
read: 513
write refused: UnsupportedError
sees owner change: 7
getInt8method
int getInt8(int byteOffset)

The (possibly negative) integer represented by the byte at the specified byteOffset in this object, in two's complement binary representation.

The return value will be between -128 and 127, inclusive.

The byteOffset must be non-negative, and less than the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData.view(Uint8List.fromList([5, 127, 128, 255]).buffer);
  for (var i = 0; i < 4; i++) {
    print('byte $i: uint8 ${b.getUint8(i)}  int8 ${b.getInt8(i)}');
  }
}
Output
byte 0: uint8 5  int8 5
byte 1: uint8 127  int8 127
byte 2: uint8 128  int8 -128
byte 3: uint8 255  int8 -1
setInt8method
void setInt8(int byteOffset, int value)

Sets the byte at the specified byteOffset in this object to the two's complement binary representation of the specified value, which must fit in a single byte.

In other words, value must be between -128 and 127, inclusive.

The byteOffset must be non-negative, and less than the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(3);
  b.setInt8(0, -1);
  b.setInt8(1, -128);
  b.setInt8(2, 130); // only the low 8 bits are kept
  print('bytes:   ${b.buffer.asUint8List()}');
  print('as int8: ${[b.getInt8(0), b.getInt8(1), b.getInt8(2)]}');
}
Output
bytes:   [255, 128, 130]
as int8: [-1, -128, -126]
getUint8method
int getUint8(int byteOffset)

The positive integer represented by the byte at the specified byteOffset in this object, in unsigned binary form.

The return value will be between 0 and 255, inclusive.

The byteOffset must be non-negative, and less than the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(4)..setInt32(0, -2);
  print('bytes of -2 (big-endian): ${[for (var i = 0; i < 4; i++) b.getUint8(i)]}');
  print('checksum: ${[for (var i = 0; i < 4; i++) b.getUint8(i)].reduce((a, c) => a ^ c)}');
}
Output
bytes of -2 (big-endian): [255, 255, 255, 254]
checksum: 1
setUint8method
void setUint8(int byteOffset, int value)

Sets the byte at the specified byteOffset in this object to the unsigned binary representation of the specified value, which must fit in a single byte.

In other words, value must be between 0 and 255, inclusive.

The byteOffset must be non-negative, and less than the length of this object.

Example
import 'raya:typed_data';

void main() {
  final header = ByteData(4);
  header.setUint8(0, 0x89);
  header.setUint8(1, 0x50); // 'P'
  header.setUint8(2, 0x4E); // 'N'
  header.setUint8(3, 0x47 + 256); // wraps to 0x47 'G'
  print('header: ${header.buffer.asUint8List().map((x) => x.toRadixString(16)).join(' ')}');
  print('text:   ${String.fromCharCodes(header.buffer.asUint8List(1))}');
}
Output
header: 89 50 4e 47
text:   PNG
getInt16method
int getInt16(int byteOffset, [Endian endian = Endian.big])

The (possibly negative) integer represented by the two bytes at the specified byteOffset in this object, in two's complement binary form.

The return value will be between -2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 2 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData.view(Uint8List.fromList([0xFF, 0xFE, 0x00, 0x80]).buffer);
  print('big    @0: ${b.getInt16(0)}');
  print('little @0: ${b.getInt16(0, Endian.little)}');
  print('big    @2: ${b.getInt16(2)}');
  print('little @2: ${b.getInt16(2, Endian.little)}');
}
Output
big    @0: -2
little @0: -257
big    @2: 128
little @2: -32768
setInt16method
void setInt16(int byteOffset, int value, [Endian endian = Endian.big])

Sets the two bytes starting at the specified byteOffset in this object to the two's complement binary representation of the specified value, which must fit in two bytes.

In other words, value must lie between -2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 2 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(4);
  b.setInt16(0, -300);
  b.setInt16(2, -300, Endian.little);
  print('bytes: ${b.buffer.asUint8List()}');
  print('read back: ${b.getInt16(0)}, ${b.getInt16(2, Endian.little)}');
}
Output
bytes: [254, 212, 212, 254]
read back: -300, -300
getUint16method
int getUint16(int byteOffset, [Endian endian = Endian.big])

The positive integer represented by the two bytes starting at the specified byteOffset in this object, in unsigned binary form.

The return value will be between 0 and 2<sup>16</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 2 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  // A 4-byte record: port (big-endian) then a little-endian counter.
  final b = ByteData.view(Uint8List.fromList([0x1F, 0x90, 0x2A, 0x00]).buffer);
  print('port:    ${b.getUint16(0)}');
  print('counter: ${b.getUint16(2, Endian.little)}');
}
Output
port:    8080
counter: 42
setUint16method
void setUint16(int byteOffset, int value, [Endian endian = Endian.big])

Sets the two bytes starting at the specified byteOffset in this object to the unsigned binary representation of the specified value, which must fit in two bytes.

In other words, value must be between 0 and 2<sup>16</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 2 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(4);
  b.setUint16(0, 8080);
  b.setUint16(2, 70000); // keeps the low 16 bits
  print('bytes: ${b.buffer.asUint8List()}');
  print('70000 stored as ${b.getUint16(2)} (= 70000 - 65536)');
}
Output
bytes: [31, 144, 17, 112]
70000 stored as 4464 (= 70000 - 65536)
getInt32method
int getInt32(int byteOffset, [Endian endian = Endian.big])

The (possibly negative) integer represented by the four bytes at the specified byteOffset in this object, in two's complement binary form.

The return value will be between -2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 4 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  // Parse a little binary header: magic, version, count.
  final data = Uint8List.fromList([0x52, 0x41, 0x59, 0x41, 2, 0, 0xE8, 0x03, 0, 0]);
  final b = ByteData.sublistView(data);
  final magic = String.fromCharCodes(data.sublist(0, 4));
  print('magic:   $magic');
  print('version: ${b.getUint16(4, Endian.little)}');
  print('count:   ${b.getInt32(6, Endian.little)}');
}
Output
magic:   RAYA
version: 2
count:   1000
setInt32method
void setInt32(int byteOffset, int value, [Endian endian = Endian.big])

Sets the four bytes starting at the specified byteOffset in this object to the two's complement binary representation of the specified value, which must fit in four bytes.

In other words, value must lie between -2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 4 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setInt32(0, -123456);
  b.setInt32(4, -123456, Endian.little);
  print('big:    ${b.buffer.asUint8List(0, 4)}');
  print('little: ${b.buffer.asUint8List(4, 4)}');
  print('back:   ${b.getInt32(0)} ${b.getInt32(4, Endian.little)}');
}
Output
big:    [255, 254, 29, 192]
little: [192, 29, 254, 255]
back:   -123456 -123456
getUint32method
int getUint32(int byteOffset, [Endian endian = Endian.big])

The positive integer represented by the four bytes starting at the specified byteOffset in this object, in unsigned binary form.

The return value will be between 0 and 2<sup>32</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 4 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(4)..setInt32(0, -1);
  print('as int32:  ${b.getInt32(0)}');
  print('as uint32: ${b.getUint32(0)}');
  final magic = ByteData.view(Uint8List.fromList([0xCA, 0xFE, 0xBA, 0xBE]).buffer);
  print('magic:     0x${magic.getUint32(0).toRadixString(16)}');
}
Output
as int32:  -1
as uint32: 4294967295
magic:     0xcafebabe
setUint32method
void setUint32(int byteOffset, int value, [Endian endian = Endian.big])

Sets the four bytes starting at the specified byteOffset in this object to the unsigned binary representation of the specified value, which must fit in four bytes.

In other words, value must be between 0 and 2<sup>32</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 4 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setUint32(0, 0xDEADBEEF);
  b.setUint32(4, 0xDEADBEEF, Endian.little);
  String hex(int x) => x.toRadixString(16).padLeft(2, '0');
  print('big:    ${b.buffer.asUint8List(0, 4).map(hex).join(' ')}');
  print('little: ${b.buffer.asUint8List(4, 4).map(hex).join(' ')}');
}
Output
big:    de ad be ef
little: ef be ad de
getInt64method
int getInt64(int byteOffset, [Endian endian = Endian.big])

The (possibly negative) integer represented by the eight bytes at the specified byteOffset in this object, in two's complement binary form.

The return value will be between -2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 8 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setUint32(0, 0xFFFFFFFF);
  b.setUint32(4, 0xFFFFFFFE);
  print('int64 big-endian: ${b.getInt64(0)}');
  print('as two uint32:    ${b.getUint32(0)}, ${b.getUint32(4)}');
}
Output
int64 big-endian: -2
as two uint32:    4294967295, 4294967294
setInt64method
void setInt64(int byteOffset, int value, [Endian endian = Endian.big])

Sets the eight bytes starting at the specified byteOffset in this object to the two's complement binary representation of the specified value, which must fit in eight bytes.

In other words, value must lie between -2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 8 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(16);
  b.setInt64(0, 1 << 40);
  b.setInt64(8, -5, Endian.little);
  print('1<<40 big:  ${b.buffer.asUint8List(0, 8)}');
  print('-5 little:  ${b.buffer.asUint8List(8, 8)}');
  print('read back:  ${b.getInt64(0)}, ${b.getInt64(8, Endian.little)}');
}
Output
1<<40 big:  [0, 0, 1, 0, 0, 0, 0, 0]
-5 little:  [251, 255, 255, 255, 255, 255, 255, 255]
read back:  1099511627776, -5
getUint64method
int getUint64(int byteOffset, [Endian endian = Endian.big])

The positive integer represented by the eight bytes starting at the specified byteOffset in this object, in unsigned binary form.

The return value will be between 0 and 2<sup>64</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 8 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8)..setUint64(0, 0x0102030405060708);
  print('big-endian read:    0x${b.getUint64(0).toRadixString(16)}');
  print('little-endian read: 0x${b.getUint64(0, Endian.little).toRadixString(16)}');
}
Output
big-endian read:    0x102030405060708
little-endian read: 0x807060504030201
setUint64method
void setUint64(int byteOffset, int value, [Endian endian = Endian.big])

Sets the eight bytes starting at the specified byteOffset in this object to the unsigned binary representation of the specified value, which must fit in eight bytes.

In other words, value must be between 0 and 2<sup>64</sup> - 1, inclusive.

The byteOffset must be non-negative, and byteOffset + 8 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setUint64(0, 0x0102030405060708);
  print('big-endian bytes: ${b.buffer.asUint8List()}');
  b.setUint64(0, 0x0102030405060708, Endian.little);
  print('little-endian:    ${b.buffer.asUint8List()}');
}
Output
big-endian bytes: [1, 2, 3, 4, 5, 6, 7, 8]
little-endian:    [8, 7, 6, 5, 4, 3, 2, 1]
double getFloat32(int byteOffset, [Endian endian = Endian.big])

The floating point number represented by the four bytes at the specified byteOffset in this object, in IEEE 754 single-precision binary floating-point format (binary32).

The byteOffset must be non-negative, and byteOffset + 4 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(4)..setUint32(0, 0x40490FDB);
  print('float32 from bits 0x40490fdb: ${b.getFloat32(0)}');
  b.setFloat32(0, 0.1);
  print('0.1 stored as float32 reads:  ${b.getFloat32(0)}');
}
Output
float32 from bits 0x40490fdb: 3.1415927410125732
0.1 stored as float32 reads:  0.10000000149011612
void setFloat32(int byteOffset, double value, [Endian endian = Endian.big])

Sets the four bytes starting at the specified byteOffset in this object to the IEEE 754 single-precision binary floating-point (binary32) representation of the specified value.

Note that this method can lose precision. The input value is a 64-bit floating point value, which will be converted to 32-bit floating point value by IEEE 754 rounding rules before it is stored. If value cannot be represented exactly as a binary32, it will be converted to the nearest binary32 value. If two binary32 values are equally close, the one whose least significant bit is zero will be used. Note that finite (but large) values can be converted to infinity, and small non-zero values can be converted to zero.

The byteOffset must be non-negative, and byteOffset + 4 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setFloat32(0, 1.0);
  b.setFloat32(4, -2.5, Endian.little);
  print('1.0 big:     0x${b.getUint32(0).toRadixString(16)}');
  print('-2.5 little: ${b.buffer.asUint8List(4, 4)}');
  print('back:        ${b.getFloat32(0)} ${b.getFloat32(4, Endian.little)}');
}
Output
1.0 big:     0x3f800000
-2.5 little: [0, 0, 32, 192]
back:        1.0 -2.5
double getFloat64(int byteOffset, [Endian endian = Endian.big])

The floating point number represented by the eight bytes at the specified byteOffset in this object, in IEEE 754 double-precision binary floating-point format (binary64).

The byteOffset must be non-negative, and byteOffset + 8 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8);
  b.setUint32(0, 0x3FF00000); // high word of 1.0
  print('1.0 from bits: ${b.getFloat64(0)}');
  b.setFloat64(0, 0.1, Endian.little);
  print('little read:   ${b.getFloat64(0, Endian.little)}');
  print('wrong order:   ${b.getFloat64(0)}');
}
Output
1.0 from bits: 1.0
little read:   0.1
wrong order:   -1.5423487136675799e-180
void setFloat64(int byteOffset, double value, [Endian endian = Endian.big])

Sets the eight bytes starting at the specified byteOffset in this object to the IEEE 754 double-precision binary floating-point (binary64) representation of the specified value.

The byteOffset must be non-negative, and byteOffset + 8 must be less than or equal to the length of this object.

Example
import 'raya:typed_data';

void main() {
  final b = ByteData(8)..setFloat64(0, 1.0);
  print('1.0 as IEEE-754 bits: ${b.buffer.asUint8List().map((x) => x.toRadixString(16).padLeft(2, '0')).join()}');
  b.setFloat64(0, -0.5);
  print('-0.5:                 ${b.buffer.asUint8List().map((x) => x.toRadixString(16).padLeft(2, '0')).join()}');
}
Output
1.0 as IEEE-754 bits: 3ff0000000000000
-0.5:                 bfe0000000000000
abstract final class Int8List implements _TypedIntList

A fixed-length list of 8-bit signed integers.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low eight bits, interpreted as a signed 8-bit two's complement integer with values in the range -128 to +127.

It is a compile-time error for a class to attempt to extend or implement Int8List.

Constructors

Int8Listfactory
external factory Int8List(int length)

Creates an Int8List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length bytes.

Example
import 'raya:typed_data';

void main() {
  final a = Int8List(4);
  a[0] = 100;
  a[1] = 127 + 1;  // wraps to -128
  a[2] = 200;      // 200 - 256 = -56
  a[3] = -129;     // wraps to 127
  print('Int8List: $a');
  print('range: -128..127, ${a.elementSizeInBytes} byte per element');
}
Output
Int8List: [100, -128, -56, 127]
range: -128..127, 1 byte per element
external factory Int8List.fromList(List<int> elements)

Creates a Int8List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length bytes.

Example
import 'raya:typed_data';

void main() {
  final deltas = Int8List.fromList([5, -3, 0, 250, -7]);
  print('stored:  $deltas');
  var level = 0;
  final levels = [for (final d in deltas) level += d];
  print('running: $levels');
}
Output
stored:  [5, -3, 0, -6, -7]
running: [5, 2, 2, -4, -11]
factory Int8List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates an Int8List view of the specified region in buffer.

Changes in the Int8List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Int8List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Int8List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Int8List.sublistView which includes this computation:

Int8List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([10, 246, 128, 1]);
  final signed = Int8List.view(bytes.buffer);
  print('unsigned: $bytes');
  print('signed:   $signed');
  print('last two: ${Int8List.view(bytes.buffer, 2, 2)}');
}
Output
unsigned: [10, 246, 128, 1]
signed:   [10, -10, -128, 1]
last two: [-128, 1]
factory Int8List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Int8List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

Example
import 'raya:typed_data';

void main() {
  final pcm = Int16List.fromList([0x0102, -2]);
  // Look at the 16-bit samples as signed bytes (host order).
  final bytes = Int8List.sublistView(pcm);
  print('bytes of both samples: $bytes');
  print('bytes of sample 1:     ${Int8List.sublistView(pcm, 1, 2)}');
}
Output
bytes of both samples: [2, 1, -2, -1]
bytes of sample 1:     [-2, -1]

Static

static const int bytesPerElement = 1

Methods

Int8List asUnmodifiableView()

A read-only view of this Int8List;

Example
import 'raya:typed_data';

void main() {
  final a = Int8List.fromList([1, -1]);
  final ro = a.asUnmodifiableView();
  try {
    ro[0] = 5;
  } on UnsupportedError {
    print('cannot write through the view');
  }
  a[0] = -100;
  print('view follows owner: $ro');
}
Output
cannot write through the view
view follows owner: [-100, -1]
sublistmethod
Int8List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is an Int8List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Int8List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Int8List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final a = Int8List.fromList([-3, -2, -1, 0, 1, 2, 3]);
  final neg = a.sublist(0, 3);
  neg[0] = 99;
  print('negatives (copy): $neg');
  print('original intact:  $a');
  print('from index 4:     ${a.sublist(4)}');
}
Output
negatives (copy): [99, -2, -1]
original intact:  [-3, -2, -1, 0, 1, 2, 3]
from index 4:     [1, 2, 3]
abstract final class Uint8List implements _TypedIntList

A fixed-length list of 8-bit unsigned integers.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low eight bits, interpreted as an unsigned 8-bit integer with values in the range 0 to 255.

It is a compile-time error for a class to attempt to extend or implement Uint8List.

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List(4);
  bytes[0] = 255;
  bytes[1] = 256; // wraps: only the low 8 bits are kept
  bytes[2] = -1;
  print('bytes: $bytes');
  final copy = Uint8List.fromList([1, 2, 3, 4, 5]);
  print('sublist: ${copy.sublist(1, 4)}');
  print('lengthInBytes: ${copy.lengthInBytes}');
}
Output
bytes: [255, 0, 255, 0]
sublist: [2, 3, 4]
lengthInBytes: 5

Constructors

Uint8Listfactory
external factory Uint8List(int length)

Creates a Uint8List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length bytes.

Example
import 'raya:typed_data';

void main() {
  final pixel = Uint8List(3);
  pixel[0] = 255;
  pixel[1] = 128;
  pixel[2] = 300; // 300 & 0xFF = 44
  print('rgb: $pixel');
  print('hex: #${pixel.map((c) => c.toRadixString(16).padLeft(2, '0')).join()}');
}
Output
rgb: [255, 128, 44]
hex: #ff802c
external factory Uint8List.fromList(List<int> elements)

Creates a Uint8List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length bytes.

Example
import 'raya:typed_data';

void main() {
  final ascii = Uint8List.fromList('Raya!'.codeUnits);
  print('bytes: $ascii');
  print('sum mod 256: ${ascii.fold<int>(0, (s, b) => (s + b) & 0xFF)}');
  print('negative wraps: ${Uint8List.fromList([-1, -2])}');
}
Output
bytes: [82, 97, 121, 97, 33]
sum mod 256: 174
negative wraps: [255, 254]
factory Uint8List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Uint8List view of the specified region in buffer.

Changes in the Uint8List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Uint8List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Uint8List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Uint8List.sublistView which includes this computation:

Uint8List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final words = Uint32List.fromList([0x04030201, 0x08070605]);
  final bytes = Uint8List.view(words.buffer);
  print('the same memory as bytes: $bytes');
  bytes[0] = 0xFF;
  print('first word now: 0x${words[0].toRadixString(16)}');
}
Output
the same memory as bytes: [1, 2, 3, 4, 5, 6, 7, 8]
first word now: 0x40302ff
factory Uint8List.sublistView(TypedData data, [int start = 0, int? end])

Creates a Uint8List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

Example
import 'raya:typed_data';

void main() {
  final words = Uint32List.fromList([0x11223344]);
  final bytes = Uint8List.sublistView(words);
  print('bytes of the word (host order): ${bytes.map((b) => b.toRadixString(16)).toList()}');
  final packet = Uint8List.fromList([9, 8, 7, 6, 5]);
  final payload = Uint8List.sublistView(packet, 1, 4);
  payload[0] = 0;
  print('payload: $payload, packet: $packet');
}
Output
bytes of the word (host order): [44, 33, 22, 11]
payload: [0, 7, 6], packet: [9, 0, 7, 6, 5]

Static

static const int bytesPerElement = 1

Methods

Uint8List asUnmodifiableView()

A read-only view of this Uint8List.

Example
import 'raya:typed_data';

void main() {
  final key = Uint8List.fromList([1, 2, 3, 4]);
  final shared = key.asUnmodifiableView();
  try {
    shared.fillRange(0, 4, 0);
  } on UnsupportedError {
    print('readers cannot wipe the key');
  }
  print('key: $shared');
}
Output
readers cannot wipe the key
key: [1, 2, 3, 4]
sublistmethod
Uint8List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Uint8List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Uint8List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Uint8List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final frame = Uint8List.fromList([0x7E, 3, 0x41, 0x42, 0x43, 0x7E]);
  final len = frame[1];
  final body = frame.sublist(2, 2 + len);
  print('body: ${String.fromCharCodes(body)}');
  print('type: ${body.runtimeType}');
}
Output
body: ABC
type: Uint8List

Operators

operator +operator
List<int> operator +(List<int> other)

Returns a concatenation of this list and other.

If other is also a typed-data list, then the return list will be a typed data list capable of holding both unsigned 8-bit integers and the elements of other, otherwise it'll be a normal list of integers.

Example
import 'raya:typed_data';

void main() {
  final a = Uint8List.fromList([1, 2]);
  final b = Uint8List.fromList([3, 4]);
  final joined = a + b;
  print('a + b: $joined');
  print('is Uint8List: ${joined is Uint8List}');
  print('as bytes again: ${Uint8List.fromList(joined)}');
}
Output
a + b: [1, 2, 3, 4]
is Uint8List: false
as bytes again: [1, 2, 3, 4]
abstract final class Uint8ClampedList implements _TypedIntList

A fixed-length list of 8-bit unsigned integers.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are clamped to an unsigned eight bit value. That is, all values below zero are stored as zero and all values above 255 are stored as 255.

It is a compile-time error for a class to attempt to extend or implement Uint8ClampedList.

Constructors

external factory Uint8ClampedList(int length)

Creates a Uint8ClampedList of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length bytes.

Example
import 'raya:typed_data';

void main() {
  final c = Uint8ClampedList(4);
  c[0] = 300;  // clamps to 255
  c[1] = -40;  // clamps to 0
  c[2] = 100;
  final w = Uint8List(4);
  w[0] = 300;
  w[1] = -40;
  print('clamped: $c');
  print('wrapped: $w');
}
Output
clamped: [255, 0, 100, 0]
wrapped: [44, 216, 0, 0]
external factory Uint8ClampedList.fromList(List<int> elements)

Creates a Uint8ClampedList of the same size as the elements list and copies over the values clamping when needed.

Values are clamped to fit in the list when they are copied, the same way storing values clamps them.

The list is backed by a ByteBuffer containing precisely elements.length bytes.

Example
import 'raya:typed_data';

void main() {
  final brightened = Uint8ClampedList.fromList([for (final v in [10, 120, 200, 250]) v + 60]);
  print('brightened pixels: $brightened');
  print('rounding 127.5 -> ${Uint8ClampedList.fromList([127, 128])}');
}
Output
brightened pixels: [70, 180, 255, 255]
rounding 127.5 -> [127, 128]
factory Uint8ClampedList.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Uint8ClampedList view of the specified region in the specified byte buffer.

Changes in the Uint8List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Uint8ClampedList.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Uint8ClampedList.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Uint8ClampedList.sublistView which includes this computation:

Uint8ClampedList.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final buf = Uint8List(3).buffer;
  final safe = Uint8ClampedList.view(buf);
  for (var i = 0; i < 3; i++) {
    safe[i] = 100 * i + 100; // 100, 200, 300
  }
  print('clamped writes: $safe');
  print('raw bytes:      ${buf.asUint8List()}');
}
Output
clamped writes: [100, 200, 255]
raw bytes:      [100, 200, 255]
factory Uint8ClampedList.sublistView(TypedData data, [int start = 0, int? end])

Creates a Uint8ClampedList view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

Example
import 'raya:typed_data';

void main() {
  final image = Uint8ClampedList.fromList([10, 20, 30, 40, 50, 60]); // 2 RGB pixels
  final second = Uint8ClampedList.sublistView(image, 3, 6);
  for (var i = 0; i < 3; i++) {
    second[i] = second[i] * 6;
  }
  print('pixel 2 x6: $second');
  print('image:      $image');
}
Output
pixel 2 x6: [240, 255, 255]
image:      [10, 20, 30, 240, 255, 255]

Static

static const int bytesPerElement = 1

Methods

Uint8ClampedList asUnmodifiableView()

A read-only view of this Uint8ClampedList.

Example
import 'raya:typed_data';

void main() {
  final px = Uint8ClampedList.fromList([255, 0, 0]);
  final ro = px.asUnmodifiableView();
  try {
    ro[1] = 255;
  } on UnsupportedError {
    print('read-only view');
  }
  print('red pixel: $ro');
}
Output
read-only view
red pixel: [255, 0, 0]
sublistmethod
Uint8ClampedList sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Uint8ClampedList containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Uint8ClampedList.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Uint8ClampedList

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final px = Uint8ClampedList.fromList([10, 20, 30, 40]);
  final copy = px.sublist(1, 3);
  copy[0] = 1000;
  print('copy (clamps too): $copy, ${copy.runtimeType}');
  print('original:          $px');
}
Output
copy (clamps too): [255, 30], Uint8ClampedList
original:          [10, 20, 30, 40]
abstract final class Int16List implements _TypedIntList

A fixed-length list of 16-bit signed integers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low 16 bits, interpreted as a signed 16-bit two's complement integer with values in the range -32768 to +32767.

It is a compile-time error for a class to attempt to extend or implement Int16List.

Constructors

Int16Listfactory
external factory Int16List(int length)

Creates an Int16List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 2 bytes.

Example
import 'raya:typed_data';

void main() {
  final samples = Int16List(4);
  samples[0] = 32767;
  samples[1] = 32768;   // wraps to -32768
  samples[2] = -1;
  samples[3] = 70000;   // 70000 - 65536 = 4464
  print('samples: $samples');
  print('${samples.lengthInBytes} bytes for ${samples.length} samples');
}
Output
samples: [32767, -32768, -1, 4464]
8 bytes for 4 samples
external factory Int16List.fromList(List<int> elements)

Creates a Int16List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 2 bytes.

Example
import 'raya:typed_data';

void main() {
  // 8 samples of a square wave at full scale.
  final wave = Int16List.fromList([for (var i = 0; i < 8; i++) i < 4 ? 32767 : -32768]);
  print('wave: $wave');
  final halved = Int16List.fromList([for (final s in wave) s ~/ 2]);
  print('-6 dB: $halved');
}
Output
wave: [32767, 32767, 32767, 32767, -32768, -32768, -32768, -32768]
-6 dB: [16383, 16383, 16383, 16383, -16384, -16384, -16384, -16384]
factory Int16List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates an Int16List view of the specified region in buffer.

Changes in the Int16List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Int16List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Int16List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Int16List.sublistView which includes this computation:

Int16List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final le = Uint8List.fromList([0x00, 0x80, 0xFF, 0x7F]); // little-endian samples
  final samples = Int16List.view(le.buffer);
  print('samples (host order): $samples');
  print('second only: ${Int16List.view(le.buffer, 2, 1)}');
}
Output
samples (host order): [-32768, 32767]
second only: [32767]
factory Int16List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Int16List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of two.

Example
import 'raya:typed_data';

void main() {
  final stereo = Int16List.fromList([1, -1, 2, -2, 3, -3]);
  final firstTwoFrames = Int16List.sublistView(stereo, 0, 4);
  print('frames 0-1: $firstTwoFrames');
  firstTwoFrames[0] = 100;
  print('shares memory: ${stereo[0]}');
}
Output
frames 0-1: [1, -1, 2, -2]
shares memory: 100

Static

static const int bytesPerElement = 2

Methods

Int16List asUnmodifiableView()

A read-only view of this Int16List.

Example
import 'raya:typed_data';

void main() {
  final table = Int16List.fromList([0, 12539, 23170, 30273, 32767]);
  final sine = table.asUnmodifiableView();
  print('quarter-wave table: $sine');
  try {
    sine[0] = 1;
  } on UnsupportedError {
    print('table is read-only');
  }
}
Output
quarter-wave table: [0, 12539, 23170, 30273, 32767]
table is read-only
sublistmethod
Int16List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is an Int16List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Int16List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Int16List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final s = Int16List.fromList([-300, -200, -100, 0, 100]);
  final tail = s.sublist(3);
  print('tail: $tail (${tail.runtimeType})');
  print('peak of first three: ${s.sublist(0, 3).reduce((a, b) => a.abs() > b.abs() ? a : b)}');
}
Output
tail: [0, 100] (Int16List)
peak of first three: -300
abstract final class Uint16List implements _TypedIntList

A fixed-length list of 16-bit unsigned integers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low 16 bits, interpreted as an unsigned 16-bit integer with values in the range 0 to 65535.

It is a compile-time error for a class to attempt to extend or implement Uint16List.

Constructors

Uint16Listfactory
external factory Uint16List(int length)

Creates a Uint16List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 2 bytes.

Example
import 'raya:typed_data';

void main() {
  final units = Uint16List(3);
  units[0] = 0x48;     // 'H'
  units[1] = 0x20AC;   // euro sign
  units[2] = 0x10041;  // keeps low 16 bits: 0x41 'A'
  print('code units: $units');
  print('string: ${String.fromCharCodes(units)}');
}
Output
code units: [72, 8364, 65]
string: H€A
external factory Uint16List.fromList(List<int> elements)

Creates a Uint16List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 2 bytes.

Example
import 'raya:typed_data';

void main() {
  final s = 'héllo €';
  final units = Uint16List.fromList(s.codeUnits);
  print('UTF-16 units: $units');
  print('round trip:   ${String.fromCharCodes(units)}');
  print('-1 stored as: ${Uint16List.fromList([-1])}');
}
Output
UTF-16 units: [104, 233, 108, 108, 111, 32, 8364]
round trip:   héllo €
-1 stored as: [65535]
factory Uint16List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Uint16List view of the specified region in the specified byte buffer.

Changes in the Uint16List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Uint16List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Uint16List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Uint16List.sublistView which includes this computation:

Uint16List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([0xFF, 0xFF, 0x01, 0x00]);
  final u16 = Uint16List.view(bytes.buffer);
  print('uint16 (host order): $u16');
  print('from byte 2:         ${Uint16List.view(bytes.buffer, 2)}');
}
Output
uint16 (host order): [65535, 1]
from byte 2:         [1]
factory Uint16List.sublistView(TypedData data, [int start = 0, int? end])

Creates a Uint16List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of two.

Example
import 'raya:typed_data';

void main() {
  final text = Uint16List.fromList('Hello, Raya'.codeUnits);
  final word = Uint16List.sublistView(text, 7);
  print('word: ${String.fromCharCodes(word)}');
  word[0] = 'K'.codeUnitAt(0);
  print('text now: ${String.fromCharCodes(text)}');
}
Output
word: Raya
text now: Hello, Kaya

Static

static const int bytesPerElement = 2

Methods

Uint16List asUnmodifiableView()

A read-only view of this Uint16List.

Example
import 'raya:typed_data';

void main() {
  final ports = Uint16List.fromList([22, 80, 443]);
  final ro = ports.asUnmodifiableView();
  try {
    ro.add(8080);
  } on UnsupportedError {
    print('fixed length and read-only');
  }
  print('ports: $ro');
}
Output
fixed length and read-only
ports: [22, 80, 443]
sublistmethod
Uint16List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Uint16List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Uint16List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Uint16List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final u = Uint16List.fromList([10, 20, 30, 40]);
  final mid = u.sublist(1, 3)..[0] = 65535;
  print('copy: $mid');
  print('orig: $u');
}
Output
copy: [65535, 30]
orig: [10, 20, 30, 40]
abstract final class Int32List implements _TypedIntList

A fixed-length list of 32-bit signed integers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low 32 bits, interpreted as a signed 32-bit two's complement integer with values in the range -2147483648 to 2147483647.

It is a compile-time error for a class to attempt to extend or implement Int32List.

Constructors

Int32Listfactory
external factory Int32List(int length)

Creates an Int32List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 4 bytes.

Example
import 'raya:typed_data';

void main() {
  final a = Int32List(3);
  a[0] = 2147483647;
  a[1] = 2147483647 + 1; // wraps to -2147483648
  a[2] = 1 << 33;        // high bits dropped: 0
  print('int32: $a');
}
Output
int32: [2147483647, -2147483648, 0]
external factory Int32List.fromList(List<int> elements)

Creates a Int32List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 4 bytes.

Example
import 'raya:typed_data';

void main() {
  final scores = Int32List.fromList([1200, -50, 980, 3000000000]);
  print('stored: $scores');
  print('3000000000 wrapped to ${scores[3]} (= 3000000000 - 2^32)');
}
Output
stored: [1200, -50, 980, -1294967296]
3000000000 wrapped to -1294967296 (= 3000000000 - 2^32)
factory Int32List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates an Int32List view of the specified region in buffer.

Changes in the Int32List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Int32List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Int32List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Int32List.sublistView which includes this computation:

Int32List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List(8);
  final ints = Int32List.view(bytes.buffer);
  ints[0] = -1;
  ints[1] = 256;
  print('ints:  $ints');
  print('bytes: $bytes');
}
Output
ints:  [-1, 256]
bytes: [255, 255, 255, 255, 0, 1, 0, 0]
factory Int32List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Int32List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of four.

Example
import 'raya:typed_data';

void main() {
  final f = Float32List.fromList([1.0, -0.0]);
  // Reinterpret floats as their raw bits.
  final bits = Int32List.sublistView(f);
  print('1.0 bits:  0x${bits[0].toRadixString(16)}');
  print('-0.0 bits: ${bits[1]} (sign bit only)');
}
Output
1.0 bits:  0x3f800000
-0.0 bits: -2147483648 (sign bit only)

Static

static const int bytesPerElement = 4

Methods

Int32List asUnmodifiableView()

A read-only view of this Int16List.

Example
import 'raya:typed_data';

void main() {
  final counts = Int32List.fromList([3, 1, 4]);
  final ro = counts.asUnmodifiableView();
  try {
    ro.sort();
  } on UnsupportedError {
    print('sort refused on read-only view');
  }
  counts.sort();
  print('owner sorted, view sees: $ro');
}
Output
sort refused on read-only view
owner sorted, view sees: [1, 3, 4]
sublistmethod
Int32List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is an Int32List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Int32List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Int32List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final a = Int32List.fromList([5, 10, 15, 20, 25]);
  final window = a.sublist(1, 4);
  print('window: $window, sum ${window.reduce((x, y) => x + y)}');
  print('end defaults to length: ${a.sublist(3)}');
}
Output
window: [10, 15, 20], sum 45
end defaults to length: [20, 25]
abstract final class Uint32List implements _TypedIntList

A fixed-length list of 32-bit unsigned integers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low 32 bits, interpreted as an unsigned 32-bit integer with values in the range 0 to 4294967295.

It is a compile-time error for a class to attempt to extend or implement Uint32List.

Constructors

Uint32Listfactory
external factory Uint32List(int length)

Creates a Uint32List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 4 bytes.

Example
import 'raya:typed_data';

void main() {
  final u = Uint32List(3);
  u[0] = 0xFFFFFFFF;
  u[1] = -1;          // same bits: 4294967295
  u[2] = 0x1FFFFFFFF; // high bit dropped
  print('uint32: $u');
}
Output
uint32: [4294967295, 4294967295, 4294967295]
external factory Uint32List.fromList(List<int> elements)

Creates a Uint32List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 4 bytes.

Example
import 'raya:typed_data';

void main() {
  final colors = Uint32List.fromList([0xFF0000FF, 0x00FF00FF, 0x0000FFFF]);
  for (final c in colors) {
    print('rgba ${c.toRadixString(16).padLeft(8, '0')}: r=${c >> 24} g=${(c >> 16) & 0xFF} b=${(c >> 8) & 0xFF}');
  }
}
Output
rgba ff0000ff: r=255 g=0 b=0
rgba 00ff00ff: r=0 g=255 b=0
rgba 0000ffff: r=0 g=0 b=255
factory Uint32List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Uint32List view of the specified region in the specified byte buffer.

Changes in the Uint32List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Uint32List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Uint32List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Uint32List.sublistView which includes this computation:

Uint32List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([1, 0, 0, 0, 0, 0, 0, 128]);
  final u = Uint32List.view(bytes.buffer);
  print('uint32 (host order): $u');
  print('second word only:    ${Uint32List.view(bytes.buffer, 4, 1)}');
}
Output
uint32 (host order): [1, 2147483648]
second word only:    [2147483648]
factory Uint32List.sublistView(TypedData data, [int start = 0, int? end])

Creates a Uint32List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of four.

Example
import 'raya:typed_data';

void main() {
  final f = Float32List.fromList([0.1, 0.2, 0.3]);
  final bits = Uint32List.sublistView(f, 1);
  print('bits of 0.2, 0.3: ${bits.map((b) => '0x${b.toRadixString(16)}').toList()}');
}
Output
bits of 0.2, 0.3: [0x3e4ccccd, 0x3e99999a]

Static

static const int bytesPerElement = 4

Methods

Uint32List asUnmodifiableView()

A read-only view of this Uint32List.

Example
import 'raya:typed_data';

void main() {
  final crcTable = Uint32List.fromList([for (var n = 0; n < 4; n++) n * 0x77073096 & 0xFFFFFFFF]);
  final ro = crcTable.asUnmodifiableView();
  print('table: ${ro.map((v) => v.toRadixString(16)).toList()}');
  try {
    ro[0] = 1;
  } on UnsupportedError {
    print('read-only');
  }
}
Output
table: [0, 77073096, ee0e612c, 651591c2]
read-only
sublistmethod
Uint32List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Uint32List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Uint32List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Uint32List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final u = Uint32List.fromList([1, 2, 3, 4]);
  final s = u.sublist(2);
  s[0] = 0xFFFFFFFF;
  print('copy: $s');
  print('orig: $u');
}
Output
copy: [4294967295, 4]
orig: [1, 2, 3, 4]
abstract final class Int64List implements _TypedIntList

A fixed-length list of 64-bit signed integers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low 64 bits, interpreted as a signed 64-bit two's complement integer with values in the range -9223372036854775808 to +9223372036854775807.

It is a compile-time error for a class to attempt to extend or implement Int64List.

Constructors

Int64Listfactory
external factory Int64List(int length)

Creates an Int64List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 8 bytes.

Example
import 'raya:typed_data';

void main() {
  final a = Int64List(3);
  a[0] = 9223372036854775807;  // max int64
  a[1] = -9223372036854775808; // min int64
  a[2] = 1 << 62;
  print('int64: $a');
  print('${a.elementSizeInBytes} bytes per element');
}
Output
int64: [9223372036854775807, -9223372036854775808, 4611686018427387904]
8 bytes per element
external factory Int64List.fromList(List<int> elements)

Creates a Int64List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 8 bytes.

Example
import 'raya:typed_data';

void main() {
  final ns = Int64List.fromList([1000000000000, -1, 1 << 50]);
  print('values: $ns');
  print('sum:    ${ns.reduce((a, b) => a + b)}');
}
Output
values: [1000000000000, -1, 1125899906842624]
sum:    1126899906842623
factory Int64List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates an Int64List view of the specified region in buffer.

Changes in the Int64List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Int64List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Int64List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Int64List.sublistView which includes this computation:

Int64List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List(16);
  final longs = Int64List.view(bytes.buffer);
  longs[1] = -1;
  print('longs: $longs');
  print('bytes: $bytes');
}
Output
longs: [0, -1]
bytes: [0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255]
factory Int64List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Int64List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of eight.

Example
import 'raya:typed_data';

void main() {
  final d = Float64List.fromList([1.0, -2.0]);
  final bits = Int64List.sublistView(d);
  print('1.0 bits:  0x${bits[0].toRadixString(16)}');
  print('-2.0 bits: ${bits[1]} (negative: sign bit set)');
}
Output
1.0 bits:  0x3ff0000000000000
-2.0 bits: -4611686018427387904 (negative: sign bit set)

Static

static const int bytesPerElement = 8

Methods

Int64List asUnmodifiableView()

A read-only view of this Int64List.

Example
import 'raya:typed_data';

void main() {
  final ids = Int64List.fromList([90071992547409930, 2]);
  final ro = ids.asUnmodifiableView();
  try {
    ro[1] = 3;
  } on UnsupportedError {
    print('read-only');
  }
  print('ids: $ro');
}
Output
read-only
ids: [90071992547409930, 2]
sublistmethod
Int64List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is an Int64List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Int64List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Int64List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final a = Int64List.fromList([1 << 40, 1 << 41, 1 << 42]);
  print('sublist(1): ${a.sublist(1)}');
  print('type:       ${a.sublist(1).runtimeType}');
}
Output
sublist(1): [2199023255552, 4398046511104]
type:       Int64List
abstract final class Uint64List implements _TypedIntList

A fixed-length list of 64-bit unsigned integers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Integers stored in the list are truncated to their low 64 bits, interpreted as an unsigned 64-bit integer with values in the range 0 to 18446744073709551615.

It is a compile-time error for a class to attempt to extend or implement Uint64List.

Constructors

Uint64Listfactory
external factory Uint64List(int length)

Creates a Uint64List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 8 bytes.

Example
import 'raya:typed_data';

void main() {
  final u = Uint64List(2);
  u[0] = 1 << 63; // top bit set
  u[1] = 12345;
  // Values are read back as 64-bit ints; the top bit shows as the sign.
  print('word 0 hex: 0x${u[0].toUnsigned(64).toRadixString(16)}');
  print('word 1:     ${u[1]}');
}
Output
word 0 hex: 0x-8000000000000000
word 1:     12345
external factory Uint64List.fromList(List<int> elements)

Creates a Uint64List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 8 bytes.

Example
import 'raya:typed_data';

void main() {
  final masks = Uint64List.fromList([for (var i = 0; i < 4; i++) (1 << (16 * i)) - 1]);
  for (final m in masks) {
    print('mask: 0x${m.toRadixString(16)}');
  }
}
Output
mask: 0x0
mask: 0xffff
mask: 0xffffffff
mask: 0xffffffffffff
factory Uint64List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates an Uint64List view of the specified region in the specified byte buffer.

Changes in the Uint64List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Uint64List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Uint64List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Uint64List.sublistView which includes this computation:

Uint64List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([for (var i = 1; i <= 16; i++) i]);
  final words = Uint64List.view(bytes.buffer);
  print('words: ${words.length}');
  print('second word only: 0x${Uint64List.view(bytes.buffer, 8, 1)[0].toRadixString(16)}');
}
Output
words: 2
second word only: 0x100f0e0d0c0b0a09
factory Uint64List.sublistView(TypedData data, [int start = 0, int? end])

Creates a Uint64List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of eight.

Example
import 'raya:typed_data';

void main() {
  final u32 = Uint32List.fromList([1, 0, 2, 0]);
  final u64 = Uint64List.sublistView(u32);
  // Two 32-bit halves make one 64-bit word (little-endian host).
  print('as uint64: $u64');
}
Output
as uint64: [1, 2]

Static

static const int bytesPerElement = 8

Methods

Uint64List asUnmodifiableView()

A read-only view of this Uint64List.

Example
import 'raya:typed_data';

void main() {
  final bitset = Uint64List(1)..[0] = 0x5;
  final ro = bitset.asUnmodifiableView();
  print('bit 0 set: ${ro[0] & 1 == 1}, bit 1 set: ${ro[0] & 2 == 2}');
  try {
    ro[0] = 0;
  } on UnsupportedError {
    print('read-only');
  }
}
Output
bit 0 set: true, bit 1 set: false
read-only
sublistmethod
Uint64List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Uint64List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Uint64List.fromList([0, 1, 2, 3, 4]);
print(numbers.sublist(1, 3)); // [1, 2]
print(numbers.sublist(1, 3).runtimeType); // Uint64List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1, 2, 3, 4]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final u = Uint64List.fromList([10, 20, 30]);
  final c = u.sublist(0, 2)..[0] = 99;
  print('copy: $c, original: $u');
}
Output
copy: [99, 20], original: [10, 20, 30]
abstract final class Float32List implements _TypedFloatList

A fixed-length list of IEEE 754 single-precision binary floating-point numbers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

Double values stored in the list are converted to the nearest single-precision value. Values read are converted to a double value with the same value.

It is a compile-time error for a class to attempt to extend or implement Float32List.

Constructors

external factory Float32List(int length)

Creates a Float32List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 4 bytes.

Example
import 'raya:typed_data';

void main() {
  final f = Float32List(3);
  f[0] = 0.1;
  f[1] = 16777217; // 2^24 + 1 is not representable in float32
  f[2] = 1e40;     // too large: infinity
  print('0.1      -> ${f[0]}');
  print('16777217 -> ${f[1]}');
  print('1e40     -> ${f[2]}');
}
Output
0.1      -> 0.10000000149011612
16777217 -> 16777216.0
1e40     -> Infinity
external factory Float32List.fromList(List<double> elements)

Creates a Float32List with the same length as the elements list and copies over the elements.

Values are truncated to fit in the list when they are copied, the same way storing values truncates them.

The list is backed by a ByteBuffer containing precisely elements.length times 4 bytes.

Example
import 'raya:typed_data';

void main() {
  final values = [1 / 3, 3.14159265358979, 0.5];
  final f = Float32List.fromList(values);
  for (var i = 0; i < values.length; i++) {
    print('${values[i]} -> ${f[i]}  error ${(f[i] - values[i]).abs()}');
  }
}
Output
0.3333333333333333 -> 0.3333333432674408  error 9.934107481068821e-9
3.14159265358979 -> 3.1415927410125732  error 8.7422783234814e-8
0.5 -> 0.5  error 0.0
factory Float32List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Float32List view of the specified region in buffer.

Changes in the Float32List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Float32List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Float32List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Float32List.sublistView which includes this computation:

Float32List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List.fromList([0, 0, 0x80, 0x3F, 0, 0, 0, 0x40]);
  final f = Float32List.view(bytes.buffer);
  print('floats (little-endian host): $f');
}
Output
floats (little-endian host): [1.0, 2.0]
factory Float32List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Float32List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of four.

Example
import 'raya:typed_data';

void main() {
  final xyz = Float32List.fromList([1, 2, 3, 4, 5, 6]); // two 3D points
  final p1 = Float32List.sublistView(xyz, 3, 6);
  for (var i = 0; i < 3; i++) {
    p1[i] *= 10;
  }
  print('point 1: $p1');
  print('all:     $xyz');
}
Output
point 1: [40.0, 50.0, 60.0]
all:     [1.0, 2.0, 3.0, 40.0, 50.0, 60.0]

Static

static const int bytesPerElement = 4

Methods

Float32List asUnmodifiableView()

A read-only view of this Float32List.

Example
import 'raya:typed_data';

void main() {
  final weights = Float32List.fromList([0.25, 0.5, 0.25]);
  final ro = weights.asUnmodifiableView();
  print('kernel: $ro, sum ${ro.reduce((a, b) => a + b)}');
  try {
    ro[1] = 1;
  } on UnsupportedError {
    print('read-only');
  }
}
Output
kernel: [0.25, 0.5, 0.25], sum 1.0
read-only
sublistmethod
Float32List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Float32List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Float32List.fromList([0.0, 1.0, 2.0, 3.0, 4.0]);
print(numbers.sublist(1, 3)); // [1.0, 2.0]
print(numbers.sublist(1, 3).runtimeType); // Float32List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1.0, 2.0, 3.0, 4.0]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final f = Float32List.fromList([0.1, 0.2, 0.3, 0.4]);
  final s = f.sublist(1, 3);
  print('sublist: $s (${s.runtimeType})');
  print('0.2 + 0.3 in float32 = ${s[0] + s[1]}');
}
Output
sublist: [0.20000000298023224, 0.30000001192092896] (Float32List)
0.2 + 0.3 in float32 = 0.5000000149011612
abstract final class Float64List implements _TypedFloatList

A fixed-length list of IEEE 754 double-precision binary floating-point numbers that is viewable as a TypedData.

For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.

It is a compile-time error for a class to attempt to extend or implement Float64List.

Example
import 'raya:typed_data';

void main() {
  final xs = Float64List.fromList([0.5, 1.5, 2.5]);
  print(xs);
  final f32 = Float32List.fromList([0.1]);
  print('0.1 stored as float32 reads back as ${f32[0]}');
}
Output
[0.5, 1.5, 2.5]
0.1 stored as float32 reads back as 0.10000000149011612

Constructors

external factory Float64List(int length)

Creates a Float64List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 8 bytes.

Example
import 'raya:typed_data';

void main() {
  final f = Float64List(3);
  f[0] = 0.1;
  f[1] = 16777217; // exact in float64
  f[2] = 1e300;
  print('values: $f');
  print('${f.lengthInBytes} bytes');
}
Output
values: [0.1, 16777217.0, 1e+300]
24 bytes
external factory Float64List.fromList(List<double> elements)

Creates a Float64List with the same length as the elements list and copies over the elements.

The list is backed by a ByteBuffer containing precisely elements.length times 8 bytes.

Example
import 'raya:typed_data';

void main() {
  final xs = Float64List.fromList([for (var i = 0; i <= 4; i++) i / 4]);
  final ys = Float64List.fromList([for (final x in xs) x * x]);
  print('x:   $xs');
  print('x^2: $ys');
}
Output
x:   [0.0, 0.25, 0.5, 0.75, 1.0]
x^2: [0.0, 0.0625, 0.25, 0.5625, 1.0]
factory Float64List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Float64List view of the specified region in buffer.

Changes in the Float64List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Float64List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Float64List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Float64List.sublistView which includes this computation:

Float64List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final bytes = Uint8List(16);
  final d = Float64List.view(bytes.buffer);
  d[0] = 1.0;
  d[1] = -0.0;
  print('doubles: $d');
  print('bytes:   $bytes');
}
Output
doubles: [1.0, -0.0]
bytes:   [0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 128]
factory Float64List.sublistView(TypedData data, [int start = 0, int? end])

Creates a Float64List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of eight.

Example
import 'raya:typed_data';

void main() {
  final matrix = Float64List.fromList([1, 2, 3, 4, 5, 6]); // 2 x 3, row-major
  final row1 = Float64List.sublistView(matrix, 3, 6);
  print('row 1: $row1');
  row1[0] = 40;
  print('matrix: $matrix');
}
Output
row 1: [4.0, 5.0, 6.0]
matrix: [1.0, 2.0, 3.0, 40.0, 5.0, 6.0]

Static

static const int bytesPerElement = 8

Methods

Float64List asUnmodifiableView()

A read-only view of this Float64List.

Example
import 'raya:typed_data';

void main() {
  final constants = Float64List.fromList([3.141592653589793, 2.718281828459045]);
  final ro = constants.asUnmodifiableView();
  print('pi, e: $ro');
  try {
    ro[0] = 3;
  } on UnsupportedError {
    print('read-only');
  }
}
Output
pi, e: [3.141592653589793, 2.718281828459045]
read-only
sublistmethod
Float64List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Float64List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Float64List.fromList([0.0, 1.0, 2.0, 3.0, 4.0]);
print(numbers.sublist(1, 3)); // [1.0, 2.0]
print(numbers.sublist(1, 3).runtimeType); // Float64List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(1)); // [1.0, 2.0, 3.0, 4.0]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final d = Float64List.fromList([1.5, 2.5, 3.5, 4.5]);
  final last2 = d.sublist(2);
  print('last two: $last2, mean ${(last2[0] + last2[1]) / 2}');
}
Output
last two: [3.5, 4.5], mean 4.0
abstract final class Float32x4List implements TypedDataList<Float32x4>, TypedData

A fixed-length list of Float32x4 numbers that is viewable as a TypedData.

For long lists, this implementation will be considerably more space- and time-efficient than the default List implementation.

It is a compile-time error for a class to attempt to extend or implement Float32x4List.

Example
import 'raya:typed_data';

void main() {
  // Sum 8 floats, 4 lanes at a time.
  final data = Float32List.fromList([1, 2, 3, 4, 5, 6, 7, 8]);
  final v = Float32x4List.view(data.buffer);
  var acc = Float32x4.zero();
  for (var i = 0; i < v.length; i++) {
    acc += v[i];
  }
  print('lane sums: $acc');
  print('total: ${acc.x + acc.y + acc.z + acc.w}');
}
Output
lane sums: [6.000000, 8.000000, 10.000000, 12.000000]
total: 36.0

Constructors

external factory Float32x4List(int length)

Creates a Float32x4List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 16 bytes.

Example
import 'raya:typed_data';

void main() {
  final v = Float32x4List(2);
  v[0] = Float32x4(1, 2, 3, 4);
  v[1] = v[0].scale(2);
  print('length: ${v.length}, bytes: ${v.lengthInBytes}');
  print('v[1]: ${v[1]}');
}
Output
length: 2, bytes: 32
v[1]: [2.000000, 4.000000, 6.000000, 8.000000]
external factory Float32x4List.fromList(List<Float32x4> elements)

Creates a Float32x4List with the same length as the elements list and copies over the elements.

The list is backed by a ByteBuffer containing precisely elements.length times 16 bytes.

Example
import 'raya:typed_data';

void main() {
  final points = Float32x4List.fromList([Float32x4(1, 0, 0, 1), Float32x4(0, 2, 0, 1)]);
  var sum = Float32x4.zero();
  for (final p in points) {
    sum += p;
  }
  print('sum of points: $sum');
}
Output
sum of points: [1.000000, 2.000000, 0.000000, 2.000000]
factory Float32x4List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Float32x4List view of the specified region in buffer.

Changes in the Float32x4List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Float32x4List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Float32x4List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Float32x4List.sublistView which includes this computation:

Float32x4List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final flat = Float32List.fromList([1, 2, 3, 4, 5, 6, 7, 8]);
  final quads = Float32x4List.view(flat.buffer);
  quads[1] = quads[1] * Float32x4.splat(10);
  print('flat after x10 on second quad: $flat');
}
Output
flat after x10 on second quad: [1.0, 2.0, 3.0, 4.0, 50.0, 60.0, 70.0, 80.0]
factory Float32x4List.sublistView(TypedData data, [int start = 0, int? end])

Creates a Float32x4List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of sixteen.

Example
import 'raya:typed_data';

void main() {
  final flat = Float32List.fromList([for (var i = 0; i < 12; i++) i.toDouble()]);
  // sublistView start/end count elements of the source (floats here).
  final mid = Float32x4List.sublistView(flat, 4, 8);
  print('quads: ${mid.length}, value: ${mid[0]}');
}
Output
quads: 1, value: [4.000000, 5.000000, 6.000000, 7.000000]

Static

static const int bytesPerElement = 16

Methods

Float32x4List asUnmodifiableView()

A read-only view of this Float32x4List.

Example
import 'raya:typed_data';

void main() {
  final v = Float32x4List.fromList([Float32x4(1, 1, 1, 1)]);
  final ro = v.asUnmodifiableView();
  try {
    ro[0] = Float32x4.zero();
  } on UnsupportedError {
    print('read-only');
  }
  print('still: ${ro[0]}');
}
Output
read-only
still: [1.000000, 1.000000, 1.000000, 1.000000]
sublistmethod
Float32x4List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Float32x4List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Float32x4List.fromList([
  Float32x4(0, 1, 2, 3),
  Float32x4(1, 2, 3, 4),
  Float32x4(2, 3, 4, 5),
  Float32x4(3, 4, 5, 6),
  Float32x4(4, 5, 6, 7),
]);
print(numbers.sublist(1, 2)); // [Float32x4(1, 2, 3, 4)]
print(numbers.sublist(1, 2).runtimeType); // Float32x4List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(4)); // [Float32x4(4, 5, 6, 7)]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final v = Float32x4List.fromList([for (var i = 0; i < 3; i++) Float32x4.splat(i.toDouble())]);
  final s = v.sublist(1);
  print('copy length ${s.length}: ${s[0]}, ${s[1]}');
}
Output
copy length 2: [1.000000, 1.000000, 1.000000, 1.000000], [2.000000, 2.000000, 2.000000, 2.000000]

Operators

operator +operator
List<Float32x4> operator +(List<Float32x4> other)

The concatenation of this list and other.

If other is also a Float32x4List, the result is a new Float32x4List, otherwise the result is a normal growable List<Float32x4>.

Example
import 'raya:typed_data';

void main() {
  final a = Float32x4List.fromList([Float32x4(1, 2, 3, 4)]);
  final b = Float32x4List.fromList([Float32x4(5, 6, 7, 8)]);
  final joined = a + b; // concatenation, not lane-wise addition
  print('length: ${joined.length}');
  print('items:  ${joined[0]} ${joined[1]}');
}
Output
length: 2
items:  [1.000000, 2.000000, 3.000000, 4.000000] [5.000000, 6.000000, 7.000000, 8.000000]
abstract final class Int32x4List implements TypedDataList<Int32x4>, TypedData

A fixed-length list of Int32x4 numbers that is viewable as a TypedData.

For long lists, this implementation will be considerably more space- and time-efficient than the default List implementation.

Constructors

external factory Int32x4List(int length)

Creates a Int32x4List of the specified length (in elements), all of whose elements are initially zero.

The list is backed by a ByteBuffer containing precisely length times 16 bytes.

Example
import 'raya:typed_data';

void main() {
  final m = Int32x4List(2);
  m[0] = Int32x4(1, 2, 3, 4);
  m[1] = m[0] + m[0];
  print('length: ${m.length}, bytes: ${m.lengthInBytes}');
  print('m[1] lanes: ${m[1].x} ${m[1].y} ${m[1].z} ${m[1].w}');
}
Output
length: 2, bytes: 32
m[1] lanes: 2 4 6 8
external factory Int32x4List.fromList(List<Int32x4> elements)

Creates a Int32x4List with the same length as the elements list and copies over the elements.

The list is backed by a ByteBuffer containing precisely elements.length times 16 bytes.

Example
import 'raya:typed_data';

void main() {
  final masks = Int32x4List.fromList([
    Int32x4.bool(true, false, true, false),
    Int32x4.bool(false, false, false, true),
  ]);
  for (final m in masks) {
    print('flags: ${m.flagX} ${m.flagY} ${m.flagZ} ${m.flagW}  signMask ${m.signMask}');
  }
}
Output
flags: true false true false  signMask 5
flags: false false false true  signMask 8
factory Int32x4List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Int32x4List view of the specified region in buffer.

Changes in the Int32x4List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Int32x4List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Int32x4List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Int32x4List.sublistView which includes this computation:

Int32x4List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final ints = Int32List.fromList([1, 2, 3, 4, 5, 6, 7, 8]);
  final quads = Int32x4List.view(ints.buffer);
  quads[0] = quads[0] + quads[1];
  print('ints after quad add: $ints');
}
Output
ints after quad add: [6, 8, 10, 12, 5, 6, 7, 8]
factory Int32x4List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Int32x4List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of sixteen.

Example
import 'raya:typed_data';

void main() {
  final ints = Int32List.fromList([for (var i = 0; i < 8; i++) i]);
  final second = Int32x4List.sublistView(ints, 4);
  print('one quad: ${second[0].x} ${second[0].y} ${second[0].z} ${second[0].w}');
}
Output
one quad: 4 5 6 7

Static

static const int bytesPerElement = 16

Methods

Int32x4List asUnmodifiableView()

A read-only view of this Int32x4List.

Example
import 'raya:typed_data';

void main() {
  final q = Int32x4List.fromList([Int32x4(9, 9, 9, 9)]);
  final ro = q.asUnmodifiableView();
  try {
    ro[0] = Int32x4(0, 0, 0, 0);
  } on UnsupportedError {
    print('read-only');
  }
  print('x: ${ro[0].x}');
}
Output
read-only
x: 9
sublistmethod
Int32x4List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is an Int32x4List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Int32x4List.fromList([
  Int32x4(0, 1, 2, 3),
  Int32x4(1, 2, 3, 4),
  Int32x4(2, 3, 4, 5),
  Int32x4(3, 4, 5, 6),
  Int32x4(4, 5, 6, 7),
]);
print(numbers.sublist(1, 2)); // [Int32x4(1, 2, 3, 4)]
print(numbers.sublist(1, 2).runtimeType); // Int32x4List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(3)); // [Int32x4(3, 4, 5, 6), Int32x4(4, 5, 6, 7)]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final q = Int32x4List.fromList([Int32x4(1, 1, 1, 1), Int32x4(2, 2, 2, 2)]);
  final s = q.sublist(1);
  print('copy length: ${s.length}, first x: ${s[0].x}');
}
Output
copy length: 1, first x: 2

Operators

operator +operator
List<Int32x4> operator +(List<Int32x4> other)

The concatenation of this list and other.

If other is also a Int32x4List, the result is a new Int32x4List, otherwise the result is a normal growable List<Int32x4>.

Example
import 'raya:typed_data';

void main() {
  final a = Int32x4List.fromList([Int32x4(1, 2, 3, 4)]);
  final b = Int32x4List.fromList([Int32x4(10, 20, 30, 40)]);
  final both = a + b; // concatenation
  print('length: ${both.length}, x values: ${both.map((v) => v.x).toList()}');
}
Output
length: 2, x values: [1, 10]
abstract final class Float64x2List implements TypedDataList<Float64x2>, TypedData

A fixed-length list of Float64x2 numbers that is viewable as a TypedData.

For long lists, this implementation will be considerably more space- and time-efficient than the default List implementation.

It is a compile-time error for a class to attempt to extend or implement Float64x2List.

Constructors

external factory Float64x2List(int length)

Creates a Float64x2List of the specified length (in elements), all of whose elements have all lanes set to zero.

The list is backed by a ByteBuffer containing precisely length times 16 bytes.

Example
import 'raya:typed_data';

void main() {
  final pts = Float64x2List(2);
  pts[0] = Float64x2(1.5, -2);
  pts[1] = pts[0].scale(2);
  print('length: ${pts.length}, bytes: ${pts.lengthInBytes}');
  print('pts[1]: ${pts[1]}');
}
Output from the Raya VM
length: 2, bytes: 32
pts[1]: [3.000000, -4.000000]
external factory Float64x2List.fromList(List<Float64x2> elements)

Creates a Float64x2List with the same length as the elements list and copies over the elements.

The list is backed by a ByteBuffer containing precisely elements.length times 16 bytes.

Example
import 'raya:typed_data';

void main() {
  final pts = Float64x2List.fromList([Float64x2(0, 0), Float64x2(4, 0), Float64x2(4, 3)]);
  var perimeter = 0.0;
  for (var i = 0; i < pts.length; i++) {
    final d = pts[(i + 1) % pts.length] - pts[i];
    final sq = d * d;
    perimeter += (sq.x + sq.y) == 0 ? 0 : (sq.x + sq.y);
  }
  print('sum of squared side lengths: $perimeter');
}
Output
sum of squared side lengths: 50.0
factory Float64x2List.view(ByteBuffer buffer, [int offsetInBytes = 0, int? length])

Creates a Float64x2List view of the specified region in buffer.

Changes in the Float64x2List will be visible in the byte buffer and vice versa. If the offsetInBytes index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not provided, the view extends to the end of the byte buffer.

The offsetInBytes and length must be non-negative, and offsetInBytes + (length * bytesPerElement) must be less than or equal to the length of buffer.

The offsetInBytes must be a multiple of bytesPerElement.

Note that when creating a view from a TypedData list or byte data, that list or byte data may itself be a view on a larger buffer with a TypedData.offsetInBytes greater than zero. Merely doing Float64x2List.view(other.buffer, 0, count) may not point to the bytes you intended. Instead you may need to do:

Float64x2List.view(other.buffer, other.offsetInBytes, count)

Alternatively, use Float64x2List.sublistView which includes this computation:

Float64x2List.sublistView(other, 0, count);

(The third argument is an end index rather than a length, so if you start from a position greater than zero, you need not reduce the count correspondingly).

Example
import 'raya:typed_data';

void main() {
  final flat = Float64List.fromList([1, 2, 3, 4]);
  final pairs = Float64x2List.view(flat.buffer);
  pairs[0] = pairs[0] + pairs[1];
  print('flat after pair add: $flat');
}
Output
flat after pair add: [4.0, 6.0, 3.0, 4.0]
factory Float64x2List.sublistView(TypedData data, [int start = 0, int? end])

Creates an Float64x2List view on a range of elements of data.

Creates a view on the range of data.buffer which corresponds to the elements of data from start until end. If data is a typed data list, like Uint16List, then the view is on the bytes of the elements with indices from start until end. If data is a ByteData, it's treated like a list of bytes.

If provided, start and end must satisfy

0 &le; start &le; end &le; elementCount

Where elementCount is the number of elements in data, which is the same as the List.length of a typed data list.

If omitted, start defaults to zero and end to elementCount.

The start and end indices of the range of bytes being viewed must be multiples of sixteen.

Example
import 'raya:typed_data';

void main() {
  final flat = Float64List.fromList([1, 2, 3, 4, 5, 6]);
  final last = Float64x2List.sublistView(flat, 4);
  print('pairs: ${last.length}, (${last[0].x}, ${last[0].y})');
}
Output
pairs: 1, (5.0, 6.0)

Static

static const int bytesPerElement = 16

Methods

Float64x2List asUnmodifiableView()

A read-only view of this Float64x2List.

Example
import 'raya:typed_data';

void main() {
  final p = Float64x2List.fromList([Float64x2(1, 2)]);
  final ro = p.asUnmodifiableView();
  try {
    ro[0] = Float64x2.zero();
  } on UnsupportedError {
    print('read-only');
  }
  print('still: ${ro[0]}');
}
Output from the Raya VM
read-only
still: [1.000000, 2.000000]
sublistmethod
Float64x2List sublist(int start, [int? end])

Creates a new list containing the elements between start and end.

The new list is a Float64x2List containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

var numbers = Float64x2List.fromList([
  Float64x2(0, 1),
  Float64x2(1, 2),
  Float64x2(2, 3),
  Float64x2(3, 4),
  Float64x2(4, 5),
]);
print(numbers.sublist(1, 3)); // [Float64x2(1, 2), Float64x2(2, 3)]
print(numbers.sublist(1, 3).runtimeType); // Float64x2List

If end is omitted, it defaults to the length of this list.

print(numbers.sublist(3)); // [Float64x2(3, 4), Float64x2(4, 5)]

The start and end positions must satisfy the relations 0 ≤ start ≤ end ≤ this.length. If end is equal to start, then the returned list is empty.

Example
import 'raya:typed_data';

void main() {
  final p = Float64x2List.fromList([Float64x2(1, 1), Float64x2(2, 2), Float64x2(3, 3)]);
  final s = p.sublist(0, 2);
  print('copy: ${s.length} pairs, last ${s[1]}');
}
Output from the Raya VM
copy: 2 pairs, last [2.000000, 2.000000]

Operators

operator +operator
List<Float64x2> operator +(List<Float64x2> other)

The concatenation of this list and other.

If other is also a Float64x2List, the result is a new Float64x2List, otherwise the result is a normal growable List<Float64x2>.

Example
import 'raya:typed_data';

void main() {
  final a = Float64x2List.fromList([Float64x2(1, 2)]);
  final b = Float64x2List.fromList([Float64x2(3, 4)]);
  final both = a + b; // concatenation, not element-wise
  print('length: ${both.length}: ${both[0]} ${both[1]}');
}
Output from the Raya VM
length: 2: [1.000000, 2.000000] [3.000000, 4.000000]
abstract final class Float32x4

Four 32-bit floating point values.

Float32x4 stores four 32-bit floating point values in "lanes". The lanes are named x, y, z, and w respectively.

Single operations can be performed on the multiple values of one or more Float32x4s, which will perform the corresponding operation for each lane of the operands, and provide a new Float32x4 (or similar multi-value) result with the results from each lane.

The Float32x4 class cannot be extended or implemented.

Example
import 'raya:typed_data';

void main() {
  final a = Float32x4(1, 2, 3, 4);
  final b = Float32x4.splat(10);
  final c = a * b + Float32x4(0.5, 0.5, 0.5, 0.5);
  print('lanes: ${c.x}, ${c.y}, ${c.z}, ${c.w}');
  print('max:   ${a.max(Float32x4(2, 2, 2, 2))}');
  print('sqrt:  ${Float32x4(1, 4, 9, 16).sqrt()}');
  print('shuffle wzyx: ${a.shuffle(Float32x4.wzyx)}');
}
Output
lanes: 10.5, 20.5, 30.5, 40.5
max:   [2.000000, 2.000000, 3.000000, 4.000000]
sqrt:  [1.000000, 2.000000, 3.000000, 4.000000]
shuffle wzyx: [4.000000, 3.000000, 2.000000, 1.000000]

Constructors

Float32x4factory
external factory Float32x4(double x, double y, double z, double w)

Creates a Float32x4 containing the 32-bit float values of the arguments.

The created value has Float32x4.x, Float32x4.y, Float32x4.z and Float32x4.w values that are the 32-bit floating point values created from the x, y, z and w arguments by conversion from 64-bit floating point to 32-bit floating point values.

The conversion from 64-bit float to 32-bit float loses significant precision, and may become zero or infinite even if the original 64-bit floating point value was non-zero and finite.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2.5, -3, 4);
  print('lanes: ${lanes(v)}');
  // Each lane is a 32-bit float, so 0.1 is stored as its nearest float.
  print('0.1 as a float32 lane: ${Float32x4(0.1, 0, 0, 0).x}');
}
Output
lanes: [1.0, 2.5, -3.0, 4.0]
0.1 as a float32 lane: 0.10000000149011612
external factory Float32x4.splat(double value)

Creates a Float32x4 with the same 32-bit float value four times.

The created value has the same Float32x4.x, Float32x4.y, Float32x4.z and Float32x4.w value, which is the 32-bit floating point value created by converting the 64-bit floating point value to a 32-bit floating point value.

The conversion from 64-bit float to 32-bit float loses significant precision, and may become zero or infinite even if the original 64-bit floating point value was non-zero and finite.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4.splat(2.5);
  print('splat(2.5): ${lanes(v)}');
  final scaled = Float32x4(1, 2, 3, 4) * Float32x4.splat(10);
  print('times splat(10): ${lanes(scaled)}');
}
Output
splat(2.5): [2.5, 2.5, 2.5, 2.5]
times splat(10): [10.0, 20.0, 30.0, 40.0]
external factory Float32x4.zero()

Creates a Float32x4 with all values being zero.

The created value has the same Float32x4.x, Float32x4.y, Float32x4.z and Float32x4.w value, which is the 32-bit floating point zero value.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final z = Float32x4.zero();
  print('zero: ${lanes(z)}');
  final v = Float32x4(1, -2, 3, -4);
  print('v + zero == v: ${lanes(v + z)}');
}
Output
zero: [0.0, 0.0, 0.0, 0.0]
v + zero == v: [1.0, -2.0, 3.0, -4.0]
external factory Float32x4.fromInt32x4Bits(Int32x4 bits)

Creates a Float32x4 with 32-bit float values from the provided bits.

The created value has Float32x4.x, Float32x4.y, Float32x4.z and Float32x4.w values, which are the 32-bit floating point values of the bit-representations of the corresponding lanes of bits.

The conversion is performed using the platform endianness for both 32-bit integers and 32-bit floating point numbers.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  // Reinterpret the 32-bit patterns; no numeric conversion.
  final bits = Int32x4(0x3f800000, 0x40000000, 0xbf800000, 0);
  print('bits as floats: ${lanes(Float32x4.fromInt32x4Bits(bits))}');
  final back = Int32x4.fromFloat32x4Bits(Float32x4(1, 2, -1, 0));
  print('1.0 as bits: 0x${back.x.toRadixString(16)}');
}
Output
bits as floats: [1.0, 2.0, -1.0, 0.0]
1.0 as bits: 0x3f800000
external factory Float32x4.fromFloat64x2(Float64x2 xy)

Creates a Float32x4 with its x and y lanes set to values from xy.

The created value has Float32x4.x and Float32x4.y values which are the conversions of the Float64x2.x and Float64x2.y lanes of xy to 32-bit floating point values. The Float32x4.z and Float32x4.w lanes are set to the zero value.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final xy = Float64x2(1.5, -2.25);
  final v = Float32x4.fromFloat64x2(xy);
  print('from Float64x2(1.5, -2.25): ${lanes(v)} (z and w are 0)');
}
Output
from Float64x2(1.5, -2.25): [1.5, -2.25, 0.0, 0.0] (z and w are 0)

Static

xxxxconstant
static const int xxxx = 0x00

Shuffle mask "xxxx".

Used by shuffle and shuffleMix.

xxxyconstant
static const int xxxy = 0x40

Shuffle mask "xxxy".

Used by shuffle and shuffleMix.

xxxzconstant
static const int xxxz = 0x80

Shuffle mask "xxxz".

Used by shuffle and shuffleMix.

xxxwconstant
static const int xxxw = 0xC0

Shuffle mask "xxxw".

Used by shuffle and shuffleMix.

xxyxconstant
static const int xxyx = 0x10

Shuffle mask "xxyx".

Used by shuffle and shuffleMix.

xxyyconstant
static const int xxyy = 0x50

Shuffle mask "xxyy".

Used by shuffle and shuffleMix.

xxyzconstant
static const int xxyz = 0x90

Shuffle mask "xxyz".

Used by shuffle and shuffleMix.

xxywconstant
static const int xxyw = 0xD0

Shuffle mask "xxyw".

Used by shuffle and shuffleMix.

xxzxconstant
static const int xxzx = 0x20

Shuffle mask "xxzx".

Used by shuffle and shuffleMix.

xxzyconstant
static const int xxzy = 0x60

Shuffle mask "xxzy".

Used by shuffle and shuffleMix.

xxzzconstant
static const int xxzz = 0xA0

Shuffle mask "xxzz".

Used by shuffle and shuffleMix.

xxzwconstant
static const int xxzw = 0xE0

Shuffle mask "xxzw".

Used by shuffle and shuffleMix.

xxwxconstant
static const int xxwx = 0x30

Shuffle mask "xxwx".

Used by shuffle and shuffleMix.

xxwyconstant
static const int xxwy = 0x70

Shuffle mask "xxwy".

Used by shuffle and shuffleMix.

xxwzconstant
static const int xxwz = 0xB0

Shuffle mask "xxwz".

Used by shuffle and shuffleMix.

xxwwconstant
static const int xxww = 0xF0

Shuffle mask "xxww".

Used by shuffle and shuffleMix.

xyxxconstant
static const int xyxx = 0x04

Shuffle mask "xyxx".

Used by shuffle and shuffleMix.

xyxyconstant
static const int xyxy = 0x44

Shuffle mask "xyxy".

Used by shuffle and shuffleMix.

xyxzconstant
static const int xyxz = 0x84

Shuffle mask "xyxz".

Used by shuffle and shuffleMix.

xyxwconstant
static const int xyxw = 0xC4

Shuffle mask "xyxw".

Used by shuffle and shuffleMix.

xyyxconstant
static const int xyyx = 0x14

Shuffle mask "xyyx".

Used by shuffle and shuffleMix.

xyyyconstant
static const int xyyy = 0x54

Shuffle mask "xyyy".

Used by shuffle and shuffleMix.

xyyzconstant
static const int xyyz = 0x94

Shuffle mask "xyyz".

Used by shuffle and shuffleMix.

xyywconstant
static const int xyyw = 0xD4

Shuffle mask "xyyw".

Used by shuffle and shuffleMix.

xyzxconstant
static const int xyzx = 0x24

Shuffle mask "xyzx".

Used by shuffle and shuffleMix.

xyzyconstant
static const int xyzy = 0x64

Shuffle mask "xyzy".

Used by shuffle and shuffleMix.

xyzzconstant
static const int xyzz = 0xA4

Shuffle mask "xyzz".

Used by shuffle and shuffleMix.

xyzwconstant
static const int xyzw = 0xE4

Shuffle mask "xyzw".

Used by shuffle and shuffleMix.

xywxconstant
static const int xywx = 0x34

Shuffle mask "xywx".

Used by shuffle and shuffleMix.

xywyconstant
static const int xywy = 0x74

Shuffle mask "xywy".

Used by shuffle and shuffleMix.

xywzconstant
static const int xywz = 0xB4

Shuffle mask "xywz".

Used by shuffle and shuffleMix.

xywwconstant
static const int xyww = 0xF4

Shuffle mask "xyww".

Used by shuffle and shuffleMix.

xzxxconstant
static const int xzxx = 0x08

Shuffle mask "xzxx".

Used by shuffle and shuffleMix.

xzxyconstant
static const int xzxy = 0x48

Shuffle mask "xzxy".

Used by shuffle and shuffleMix.

xzxzconstant
static const int xzxz = 0x88

Shuffle mask "xzxz".

Used by shuffle and shuffleMix.

xzxwconstant
static const int xzxw = 0xC8

Shuffle mask "xzxw".

Used by shuffle and shuffleMix.

xzyxconstant
static const int xzyx = 0x18

Shuffle mask "xzyx".

Used by shuffle and shuffleMix.

xzyyconstant
static const int xzyy = 0x58

Shuffle mask "xzyy".

Used by shuffle and shuffleMix.

xzyzconstant
static const int xzyz = 0x98

Shuffle mask "xzyz".

Used by shuffle and shuffleMix.

xzywconstant
static const int xzyw = 0xD8

Shuffle mask "xzyw".

Used by shuffle and shuffleMix.

xzzxconstant
static const int xzzx = 0x28

Shuffle mask "xzzx".

Used by shuffle and shuffleMix.

xzzyconstant
static const int xzzy = 0x68

Shuffle mask "xzzy".

Used by shuffle and shuffleMix.

xzzzconstant
static const int xzzz = 0xA8

Shuffle mask "xzzz".

Used by shuffle and shuffleMix.

xzzwconstant
static const int xzzw = 0xE8

Shuffle mask "xzzw".

Used by shuffle and shuffleMix.

xzwxconstant
static const int xzwx = 0x38

Shuffle mask "xzwx".

Used by shuffle and shuffleMix.

xzwyconstant
static const int xzwy = 0x78

Shuffle mask "xzwy".

Used by shuffle and shuffleMix.

xzwzconstant
static const int xzwz = 0xB8

Shuffle mask "xzwz".

Used by shuffle and shuffleMix.

xzwwconstant
static const int xzww = 0xF8

Shuffle mask "xzww".

Used by shuffle and shuffleMix.

xwxxconstant
static const int xwxx = 0x0C

Shuffle mask "xwxx".

Used by shuffle and shuffleMix.

xwxyconstant
static const int xwxy = 0x4C

Shuffle mask "xwxy".

Used by shuffle and shuffleMix.

xwxzconstant
static const int xwxz = 0x8C

Shuffle mask "xwxz".

Used by shuffle and shuffleMix.

xwxwconstant
static const int xwxw = 0xCC

Shuffle mask "xwxw".

Used by shuffle and shuffleMix.

xwyxconstant
static const int xwyx = 0x1C

Shuffle mask "xwyx".

Used by shuffle and shuffleMix.

xwyyconstant
static const int xwyy = 0x5C

Shuffle mask "xwyy".

Used by shuffle and shuffleMix.

xwyzconstant
static const int xwyz = 0x9C

Shuffle mask "xwyz".

Used by shuffle and shuffleMix.

xwywconstant
static const int xwyw = 0xDC

Shuffle mask "xwyw".

Used by shuffle and shuffleMix.

xwzxconstant
static const int xwzx = 0x2C

Shuffle mask "xwzx".

Used by shuffle and shuffleMix.

xwzyconstant
static const int xwzy = 0x6C

Shuffle mask "xwzy".

Used by shuffle and shuffleMix.

xwzzconstant
static const int xwzz = 0xAC

Shuffle mask "xwzz".

Used by shuffle and shuffleMix.

xwzwconstant
static const int xwzw = 0xEC

Shuffle mask "xwzw".

Used by shuffle and shuffleMix.

xwwxconstant
static const int xwwx = 0x3C

Shuffle mask "xwwx".

Used by shuffle and shuffleMix.

xwwyconstant
static const int xwwy = 0x7C

Shuffle mask "xwwy".

Used by shuffle and shuffleMix.

xwwzconstant
static const int xwwz = 0xBC

Shuffle mask "xwwz".

Used by shuffle and shuffleMix.

xwwwconstant
static const int xwww = 0xFC

Shuffle mask "xwww".

Used by shuffle and shuffleMix.

yxxxconstant
static const int yxxx = 0x01

Shuffle mask "yxxx".

Used by shuffle and shuffleMix.

yxxyconstant
static const int yxxy = 0x41

Shuffle mask "yxxy".

Used by shuffle and shuffleMix.

yxxzconstant
static const int yxxz = 0x81

Shuffle mask "yxxz".

Used by shuffle and shuffleMix.

yxxwconstant
static const int yxxw = 0xC1

Shuffle mask "yxxw".

Used by shuffle and shuffleMix.

yxyxconstant
static const int yxyx = 0x11

Shuffle mask "yxyx".

Used by shuffle and shuffleMix.

yxyyconstant
static const int yxyy = 0x51

Shuffle mask "yxyy".

Used by shuffle and shuffleMix.

yxyzconstant
static const int yxyz = 0x91

Shuffle mask "yxyz".

Used by shuffle and shuffleMix.

yxywconstant
static const int yxyw = 0xD1

Shuffle mask "yxyw".

Used by shuffle and shuffleMix.

yxzxconstant
static const int yxzx = 0x21

Shuffle mask "yxzx".

Used by shuffle and shuffleMix.

yxzyconstant
static const int yxzy = 0x61

Shuffle mask "yxzy".

Used by shuffle and shuffleMix.

yxzzconstant
static const int yxzz = 0xA1

Shuffle mask "yxzz".

Used by shuffle and shuffleMix.

yxzwconstant
static const int yxzw = 0xE1

Shuffle mask "yxzw".

Used by shuffle and shuffleMix.

yxwxconstant
static const int yxwx = 0x31

Shuffle mask "yxwx".

Used by shuffle and shuffleMix.

yxwyconstant
static const int yxwy = 0x71

Shuffle mask "yxwy".

Used by shuffle and shuffleMix.

yxwzconstant
static const int yxwz = 0xB1

Shuffle mask "yxwz".

Used by shuffle and shuffleMix.

yxwwconstant
static const int yxww = 0xF1

Shuffle mask "yxww".

Used by shuffle and shuffleMix.

yyxxconstant
static const int yyxx = 0x05

Shuffle mask "yyxx".

Used by shuffle and shuffleMix.

yyxyconstant
static const int yyxy = 0x45

Shuffle mask "yyxy".

Used by shuffle and shuffleMix.

yyxzconstant
static const int yyxz = 0x85

Shuffle mask "yyxz".

Used by shuffle and shuffleMix.

yyxwconstant
static const int yyxw = 0xC5

Shuffle mask "yyxw".

Used by shuffle and shuffleMix.

yyyxconstant
static const int yyyx = 0x15

Shuffle mask "yyyx".

Used by shuffle and shuffleMix.

yyyyconstant
static const int yyyy = 0x55

Shuffle mask "yyyy".

Used by shuffle and shuffleMix.

yyyzconstant
static const int yyyz = 0x95

Shuffle mask "yyyz".

Used by shuffle and shuffleMix.

yyywconstant
static const int yyyw = 0xD5

Shuffle mask "yyyw".

Used by shuffle and shuffleMix.

yyzxconstant
static const int yyzx = 0x25

Shuffle mask "yyzx".

Used by shuffle and shuffleMix.

yyzyconstant
static const int yyzy = 0x65

Shuffle mask "yyzy".

Used by shuffle and shuffleMix.

yyzzconstant
static const int yyzz = 0xA5

Shuffle mask "yyzz".

Used by shuffle and shuffleMix.

yyzwconstant
static const int yyzw = 0xE5

Shuffle mask "yyzw".

Used by shuffle and shuffleMix.

yywxconstant
static const int yywx = 0x35

Shuffle mask "yywx".

Used by shuffle and shuffleMix.

yywyconstant
static const int yywy = 0x75

Shuffle mask "yywy".

Used by shuffle and shuffleMix.

yywzconstant
static const int yywz = 0xB5

Shuffle mask "yywz".

Used by shuffle and shuffleMix.

yywwconstant
static const int yyww = 0xF5

Shuffle mask "yyww".

Used by shuffle and shuffleMix.

yzxxconstant
static const int yzxx = 0x09

Shuffle mask "yzxx".

Used by shuffle and shuffleMix.

yzxyconstant
static const int yzxy = 0x49

Shuffle mask "yzxy".

Used by shuffle and shuffleMix.

yzxzconstant
static const int yzxz = 0x89

Shuffle mask "yzxz".

Used by shuffle and shuffleMix.

yzxwconstant
static const int yzxw = 0xC9

Shuffle mask "yzxw".

Used by shuffle and shuffleMix.

yzyxconstant
static const int yzyx = 0x19

Shuffle mask "yzyx".

Used by shuffle and shuffleMix.

yzyyconstant
static const int yzyy = 0x59

Shuffle mask "yzyy".

Used by shuffle and shuffleMix.

yzyzconstant
static const int yzyz = 0x99

Shuffle mask "yzyz".

Used by shuffle and shuffleMix.

yzywconstant
static const int yzyw = 0xD9

Shuffle mask "yzyw".

Used by shuffle and shuffleMix.

yzzxconstant
static const int yzzx = 0x29

Shuffle mask "yzzx".

Used by shuffle and shuffleMix.

yzzyconstant
static const int yzzy = 0x69

Shuffle mask "yzzy".

Used by shuffle and shuffleMix.

yzzzconstant
static const int yzzz = 0xA9

Shuffle mask "yzzz".

Used by shuffle and shuffleMix.

yzzwconstant
static const int yzzw = 0xE9

Shuffle mask "yzzw".

Used by shuffle and shuffleMix.

yzwxconstant
static const int yzwx = 0x39

Shuffle mask "yzwx".

Used by shuffle and shuffleMix.

yzwyconstant
static const int yzwy = 0x79

Shuffle mask "yzwy".

Used by shuffle and shuffleMix.

yzwzconstant
static const int yzwz = 0xB9

Shuffle mask "yzwz".

Used by shuffle and shuffleMix.

yzwwconstant
static const int yzww = 0xF9

Shuffle mask "yzww".

Used by shuffle and shuffleMix.

ywxxconstant
static const int ywxx = 0x0D

Shuffle mask "ywxx".

Used by shuffle and shuffleMix.

ywxyconstant
static const int ywxy = 0x4D

Shuffle mask "ywxy".

Used by shuffle and shuffleMix.

ywxzconstant
static const int ywxz = 0x8D

Shuffle mask "ywxz".

Used by shuffle and shuffleMix.

ywxwconstant
static const int ywxw = 0xCD

Shuffle mask "ywxw".

Used by shuffle and shuffleMix.

ywyxconstant
static const int ywyx = 0x1D

Shuffle mask "ywyx".

Used by shuffle and shuffleMix.

ywyyconstant
static const int ywyy = 0x5D

Shuffle mask "ywyy".

Used by shuffle and shuffleMix.

ywyzconstant
static const int ywyz = 0x9D

Shuffle mask "ywyz".

Used by shuffle and shuffleMix.

ywywconstant
static const int ywyw = 0xDD

Shuffle mask "ywyw".

Used by shuffle and shuffleMix.

ywzxconstant
static const int ywzx = 0x2D

Shuffle mask "ywzx".

Used by shuffle and shuffleMix.

ywzyconstant
static const int ywzy = 0x6D

Shuffle mask "ywzy".

Used by shuffle and shuffleMix.

ywzzconstant
static const int ywzz = 0xAD

Shuffle mask "ywzz".

Used by shuffle and shuffleMix.

ywzwconstant
static const int ywzw = 0xED

Shuffle mask "ywzw".

Used by shuffle and shuffleMix.

ywwxconstant
static const int ywwx = 0x3D

Shuffle mask "ywwx".

Used by shuffle and shuffleMix.

ywwyconstant
static const int ywwy = 0x7D

Shuffle mask "ywwy".

Used by shuffle and shuffleMix.

ywwzconstant
static const int ywwz = 0xBD

Shuffle mask "ywwz".

Used by shuffle and shuffleMix.

ywwwconstant
static const int ywww = 0xFD

Shuffle mask "ywww".

Used by shuffle and shuffleMix.

zxxxconstant
static const int zxxx = 0x02

Shuffle mask "zxxx".

Used by shuffle and shuffleMix.

zxxyconstant
static const int zxxy = 0x42

Shuffle mask "zxxy".

Used by shuffle and shuffleMix.

zxxzconstant
static const int zxxz = 0x82

Shuffle mask "zxxz".

Used by shuffle and shuffleMix.

zxxwconstant
static const int zxxw = 0xC2

Shuffle mask "zxxw".

Used by shuffle and shuffleMix.

zxyxconstant
static const int zxyx = 0x12

Shuffle mask "zxyx".

Used by shuffle and shuffleMix.

zxyyconstant
static const int zxyy = 0x52

Shuffle mask "zxyy".

Used by shuffle and shuffleMix.

zxyzconstant
static const int zxyz = 0x92

Shuffle mask "zxyz".

Used by shuffle and shuffleMix.

zxywconstant
static const int zxyw = 0xD2

Shuffle mask "zxyw".

Used by shuffle and shuffleMix.

zxzxconstant
static const int zxzx = 0x22

Shuffle mask "zxzx".

Used by shuffle and shuffleMix.

zxzyconstant
static const int zxzy = 0x62

Shuffle mask "zxzy".

Used by shuffle and shuffleMix.

zxzzconstant
static const int zxzz = 0xA2

Shuffle mask "zxzz".

Used by shuffle and shuffleMix.

zxzwconstant
static const int zxzw = 0xE2

Shuffle mask "zxzw".

Used by shuffle and shuffleMix.

zxwxconstant
static const int zxwx = 0x32

Shuffle mask "zxwx".

Used by shuffle and shuffleMix.

zxwyconstant
static const int zxwy = 0x72

Shuffle mask "zxwy".

Used by shuffle and shuffleMix.

zxwzconstant
static const int zxwz = 0xB2

Shuffle mask "zxwz".

Used by shuffle and shuffleMix.

zxwwconstant
static const int zxww = 0xF2

Shuffle mask "zxww".

Used by shuffle and shuffleMix.

zyxxconstant
static const int zyxx = 0x06

Shuffle mask "zyxx".

Used by shuffle and shuffleMix.

zyxyconstant
static const int zyxy = 0x46

Shuffle mask "zyxy".

Used by shuffle and shuffleMix.

zyxzconstant
static const int zyxz = 0x86

Shuffle mask "zyxz".

Used by shuffle and shuffleMix.

zyxwconstant
static const int zyxw = 0xC6

Shuffle mask "zyxw".

Used by shuffle and shuffleMix.

zyyxconstant
static const int zyyx = 0x16

Shuffle mask "zyyx".

Used by shuffle and shuffleMix.

zyyyconstant
static const int zyyy = 0x56

Shuffle mask "zyyy".

Used by shuffle and shuffleMix.

zyyzconstant
static const int zyyz = 0x96

Shuffle mask "zyyz".

Used by shuffle and shuffleMix.

zyywconstant
static const int zyyw = 0xD6

Shuffle mask "zyyw".

Used by shuffle and shuffleMix.

zyzxconstant
static const int zyzx = 0x26

Shuffle mask "zyzx".

Used by shuffle and shuffleMix.

zyzyconstant
static const int zyzy = 0x66

Shuffle mask "zyzy".

Used by shuffle and shuffleMix.

zyzzconstant
static const int zyzz = 0xA6

Shuffle mask "zyzz".

Used by shuffle and shuffleMix.

zyzwconstant
static const int zyzw = 0xE6

Shuffle mask "zyzw".

Used by shuffle and shuffleMix.

zywxconstant
static const int zywx = 0x36

Shuffle mask "zywx".

Used by shuffle and shuffleMix.

zywyconstant
static const int zywy = 0x76

Shuffle mask "zywy".

Used by shuffle and shuffleMix.

zywzconstant
static const int zywz = 0xB6

Shuffle mask "zywz".

Used by shuffle and shuffleMix.

zywwconstant
static const int zyww = 0xF6

Shuffle mask "zyww".

Used by shuffle and shuffleMix.

zzxxconstant
static const int zzxx = 0x0A

Shuffle mask "zzxx".

Used by shuffle and shuffleMix.

zzxyconstant
static const int zzxy = 0x4A

Shuffle mask "zzxy".

Used by shuffle and shuffleMix.

zzxzconstant
static const int zzxz = 0x8A

Shuffle mask "zzxz".

Used by shuffle and shuffleMix.

zzxwconstant
static const int zzxw = 0xCA

Shuffle mask "zzxw".

Used by shuffle and shuffleMix.

zzyxconstant
static const int zzyx = 0x1A

Shuffle mask "zzyx".

Used by shuffle and shuffleMix.

zzyyconstant
static const int zzyy = 0x5A

Shuffle mask "zzyy".

Used by shuffle and shuffleMix.

zzyzconstant
static const int zzyz = 0x9A

Shuffle mask "zzyz".

Used by shuffle and shuffleMix.

zzywconstant
static const int zzyw = 0xDA

Shuffle mask "zzyw".

Used by shuffle and shuffleMix.

zzzxconstant
static const int zzzx = 0x2A

Shuffle mask "zzzx".

Used by shuffle and shuffleMix.

zzzyconstant
static const int zzzy = 0x6A

Shuffle mask "zzzy".

Used by shuffle and shuffleMix.

zzzzconstant
static const int zzzz = 0xAA

Shuffle mask "zzzz".

Used by shuffle and shuffleMix.

zzzwconstant
static const int zzzw = 0xEA

Shuffle mask "zzzw".

Used by shuffle and shuffleMix.

zzwxconstant
static const int zzwx = 0x3A

Shuffle mask "zzwx".

Used by shuffle and shuffleMix.

zzwyconstant
static const int zzwy = 0x7A

Shuffle mask "zzwy".

Used by shuffle and shuffleMix.

zzwzconstant
static const int zzwz = 0xBA

Shuffle mask "zzwz".

Used by shuffle and shuffleMix.

zzwwconstant
static const int zzww = 0xFA

Shuffle mask "zzww".

Used by shuffle and shuffleMix.

zwxxconstant
static const int zwxx = 0x0E

Shuffle mask "zwxx".

Used by shuffle and shuffleMix.

zwxyconstant
static const int zwxy = 0x4E

Shuffle mask "zwxy".

Used by shuffle and shuffleMix.

zwxzconstant
static const int zwxz = 0x8E

Shuffle mask "zwxz".

Used by shuffle and shuffleMix.

zwxwconstant
static const int zwxw = 0xCE

Shuffle mask "zwxw".

Used by shuffle and shuffleMix.

zwyxconstant
static const int zwyx = 0x1E

Shuffle mask "zwyx".

Used by shuffle and shuffleMix.

zwyyconstant
static const int zwyy = 0x5E

Shuffle mask "zwyy".

Used by shuffle and shuffleMix.

zwyzconstant
static const int zwyz = 0x9E

Shuffle mask "zwyz".

Used by shuffle and shuffleMix.

zwywconstant
static const int zwyw = 0xDE

Shuffle mask "zwyw".

Used by shuffle and shuffleMix.

zwzxconstant
static const int zwzx = 0x2E

Shuffle mask "zwzx".

Used by shuffle and shuffleMix.

zwzyconstant
static const int zwzy = 0x6E

Shuffle mask "zwzy".

Used by shuffle and shuffleMix.

zwzzconstant
static const int zwzz = 0xAE

Shuffle mask "zwzz".

Used by shuffle and shuffleMix.

zwzwconstant
static const int zwzw = 0xEE

Shuffle mask "zwzw".

Used by shuffle and shuffleMix.

zwwxconstant
static const int zwwx = 0x3E

Shuffle mask "zwwx".

Used by shuffle and shuffleMix.

zwwyconstant
static const int zwwy = 0x7E

Shuffle mask "zwwy".

Used by shuffle and shuffleMix.

zwwzconstant
static const int zwwz = 0xBE

Shuffle mask "zwwz".

Used by shuffle and shuffleMix.

zwwwconstant
static const int zwww = 0xFE

Shuffle mask "zwww".

Used by shuffle and shuffleMix.

wxxxconstant
static const int wxxx = 0x03

Shuffle mask "wxxx".

Used by shuffle and shuffleMix.

wxxyconstant
static const int wxxy = 0x43

Shuffle mask "wxxy".

Used by shuffle and shuffleMix.

wxxzconstant
static const int wxxz = 0x83

Shuffle mask "wxxz".

Used by shuffle and shuffleMix.

wxxwconstant
static const int wxxw = 0xC3

Shuffle mask "wxxw".

Used by shuffle and shuffleMix.

wxyxconstant
static const int wxyx = 0x13

Shuffle mask "wxyx".

Used by shuffle and shuffleMix.

wxyyconstant
static const int wxyy = 0x53

Shuffle mask "wxyy".

Used by shuffle and shuffleMix.

wxyzconstant
static const int wxyz = 0x93

Shuffle mask "wxyz".

Used by shuffle and shuffleMix.

wxywconstant
static const int wxyw = 0xD3

Shuffle mask "wxyw".

Used by shuffle and shuffleMix.

wxzxconstant
static const int wxzx = 0x23

Shuffle mask "wxzx".

Used by shuffle and shuffleMix.

wxzyconstant
static const int wxzy = 0x63

Shuffle mask "wxzy".

Used by shuffle and shuffleMix.

wxzzconstant
static const int wxzz = 0xA3

Shuffle mask "wxzz".

Used by shuffle and shuffleMix.

wxzwconstant
static const int wxzw = 0xE3

Shuffle mask "wxzw".

Used by shuffle and shuffleMix.

wxwxconstant
static const int wxwx = 0x33

Shuffle mask "wxwx".

Used by shuffle and shuffleMix.

wxwyconstant
static const int wxwy = 0x73

Shuffle mask "wxwy".

Used by shuffle and shuffleMix.

wxwzconstant
static const int wxwz = 0xB3

Shuffle mask "wxwz".

Used by shuffle and shuffleMix.

wxwwconstant
static const int wxww = 0xF3

Shuffle mask "wxww".

Used by shuffle and shuffleMix.

wyxxconstant
static const int wyxx = 0x07

Shuffle mask "wyxx".

Used by shuffle and shuffleMix.

wyxyconstant
static const int wyxy = 0x47

Shuffle mask "wyxy".

Used by shuffle and shuffleMix.

wyxzconstant
static const int wyxz = 0x87

Shuffle mask "wyxz".

Used by shuffle and shuffleMix.

wyxwconstant
static const int wyxw = 0xC7

Shuffle mask "wyxw".

Used by shuffle and shuffleMix.

wyyxconstant
static const int wyyx = 0x17

Shuffle mask "wyyx".

Used by shuffle and shuffleMix.

wyyyconstant
static const int wyyy = 0x57

Shuffle mask "wyyy".

Used by shuffle and shuffleMix.

wyyzconstant
static const int wyyz = 0x97

Shuffle mask "wyyz".

Used by shuffle and shuffleMix.

wyywconstant
static const int wyyw = 0xD7

Shuffle mask "wyyw".

Used by shuffle and shuffleMix.

wyzxconstant
static const int wyzx = 0x27

Shuffle mask "wyzx".

Used by shuffle and shuffleMix.

wyzyconstant
static const int wyzy = 0x67

Shuffle mask "wyzy".

Used by shuffle and shuffleMix.

wyzzconstant
static const int wyzz = 0xA7

Shuffle mask "wyzz".

Used by shuffle and shuffleMix.

wyzwconstant
static const int wyzw = 0xE7

Shuffle mask "wyzw".

Used by shuffle and shuffleMix.

wywxconstant
static const int wywx = 0x37

Shuffle mask "wywx".

Used by shuffle and shuffleMix.

wywyconstant
static const int wywy = 0x77

Shuffle mask "wywy".

Used by shuffle and shuffleMix.

wywzconstant
static const int wywz = 0xB7

Shuffle mask "wywz".

Used by shuffle and shuffleMix.

wywwconstant
static const int wyww = 0xF7

Shuffle mask "wyww".

Used by shuffle and shuffleMix.

wzxxconstant
static const int wzxx = 0x0B

Shuffle mask "wzxx".

Used by shuffle and shuffleMix.

wzxyconstant
static const int wzxy = 0x4B

Shuffle mask "wzxy".

Used by shuffle and shuffleMix.

wzxzconstant
static const int wzxz = 0x8B

Shuffle mask "wzxz".

Used by shuffle and shuffleMix.

wzxwconstant
static const int wzxw = 0xCB

Shuffle mask "wzxw".

Used by shuffle and shuffleMix.

wzyxconstant
static const int wzyx = 0x1B

Shuffle mask "wzyx".

Used by shuffle and shuffleMix.

wzyyconstant
static const int wzyy = 0x5B

Shuffle mask "wzyy".

Used by shuffle and shuffleMix.

wzyzconstant
static const int wzyz = 0x9B

Shuffle mask "wzyz".

Used by shuffle and shuffleMix.

wzywconstant
static const int wzyw = 0xDB

Shuffle mask "wzyw".

Used by shuffle and shuffleMix.

wzzxconstant
static const int wzzx = 0x2B

Shuffle mask "wzzx".

Used by shuffle and shuffleMix.

wzzyconstant
static const int wzzy = 0x6B

Shuffle mask "wzzy".

Used by shuffle and shuffleMix.

wzzzconstant
static const int wzzz = 0xAB

Shuffle mask "wzzz".

Used by shuffle and shuffleMix.

wzzwconstant
static const int wzzw = 0xEB

Shuffle mask "wzzw".

Used by shuffle and shuffleMix.

wzwxconstant
static const int wzwx = 0x3B

Shuffle mask "wzwx".

Used by shuffle and shuffleMix.

wzwyconstant
static const int wzwy = 0x7B

Shuffle mask "wzwy".

Used by shuffle and shuffleMix.

wzwzconstant
static const int wzwz = 0xBB

Shuffle mask "wzwz".

Used by shuffle and shuffleMix.

wzwwconstant
static const int wzww = 0xFB

Shuffle mask "wzww".

Used by shuffle and shuffleMix.

wwxxconstant
static const int wwxx = 0x0F

Shuffle mask "wwxx".

Used by shuffle and shuffleMix.

wwxyconstant
static const int wwxy = 0x4F

Shuffle mask "wwxy".

Used by shuffle and shuffleMix.

wwxzconstant
static const int wwxz = 0x8F

Shuffle mask "wwxz".

Used by shuffle and shuffleMix.

wwxwconstant
static const int wwxw = 0xCF

Shuffle mask "wwxw".

Used by shuffle and shuffleMix.

wwyxconstant
static const int wwyx = 0x1F

Shuffle mask "wwyx".

Used by shuffle and shuffleMix.

wwyyconstant
static const int wwyy = 0x5F

Shuffle mask "wwyy".

Used by shuffle and shuffleMix.

wwyzconstant
static const int wwyz = 0x9F

Shuffle mask "wwyz".

Used by shuffle and shuffleMix.

wwywconstant
static const int wwyw = 0xDF

Shuffle mask "wwyw".

Used by shuffle and shuffleMix.

wwzxconstant
static const int wwzx = 0x2F

Shuffle mask "wwzx".

Used by shuffle and shuffleMix.

wwzyconstant
static const int wwzy = 0x6F

Shuffle mask "wwzy".

Used by shuffle and shuffleMix.

wwzzconstant
static const int wwzz = 0xAF

Shuffle mask "wwzz".

Used by shuffle and shuffleMix.

wwzwconstant
static const int wwzw = 0xEF

Shuffle mask "wwzw".

Used by shuffle and shuffleMix.

wwwxconstant
static const int wwwx = 0x3F

Shuffle mask "wwwx".

Used by shuffle and shuffleMix.

wwwyconstant
static const int wwwy = 0x7F

Shuffle mask "wwwy".

Used by shuffle and shuffleMix.

wwwzconstant
static const int wwwz = 0xBF

Shuffle mask "wwwz".

Used by shuffle and shuffleMix.

wwwwconstant
static const int wwww = 0xFF

Shuffle mask "wwww".

Used by shuffle and shuffleMix.

Properties

xgetter
double get x

The value of the "x" lane.

ygetter
double get y

The value of the "y" lane.

zgetter
double get z

The value of the "z" lane.

wgetter
double get w

The value of the "w" lane.

signMaskgetter
int get signMask

The sign bits of each lane as single bits.

The sign bits of each lane's 32-bit floating point value are stored in the low four bits of this value:

  • The x lane in bit 0.
  • The y lane in bit 1.
  • The z lane in bit 2.
  • The w lane in bit 3.

Methods

lessThanmethod
Int32x4 lessThan(Float32x4 other)

Lane-wise less-than comparison.

Compares the 32-bit floating point value of each lane of this to the value of the corresponding lane of other, using 32-bit floating point comparison. For floating point comparisons, a comparison with a NaN value is always false, and -0.0 (negative zero) is considered equal to 0.0 (positive zero), and not less strictly than it. The result for a lane is a 32-bit signed integer which is -1 (all bits set) if the value from this object is less than the value from other, and the result is 0 (all bits cleared) if not, including if either value is a NaN value.

Returns four values that are always either 0 or -1.

Example
import 'raya:typed_data';

void main() {
  final a = Float32x4(1, 5, 3, 8);
  final b = Float32x4(4, 4, 4, 4);
  final mask = a.lessThan(b);
  print('a < b sign mask: ${mask.signMask.toRadixString(2).padLeft(4, '0')} (lane x is bit 0)');
  print('min(a, b) by select: ${mask.select(a, b)}');
}
Output
a < b sign mask: 0101 (lane x is bit 0)
min(a, b) by select: [1.000000, 4.000000, 3.000000, 4.000000]
Int32x4 lessThanOrEqual(Float32x4 other)

Lane-wise less-than-or-equal comparison.

Compares the 32-bit floating point value of each lane of this to the value of the corresponding lane of other, using 32-bit floating point comparison. For floating point comparisons, a comparison with a NaN value is always false, and -0.0 (negative zero) is considered equal to 0.0 (positive zero), and not less strictly than it. The result for a lane is a 32-bit signed integer which is -1 (all bits set) if the value from this object is less than or equal to the value from other, and the result is 0 (all bits cleared) if not, including if either value is a NaN value.

Returns four values that are always either 0 or -1.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];
List<int> mask(Int32x4 m) => [m.x, m.y, m.z, m.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final a = Float32x4(1, 5, 3, 9), b = Float32x4(2, 5, 1, 9);
  final m = a.lessThanOrEqual(b);
  print('a <= b lane flags: ${flags(m)}');
  print('as masks: ${mask(m)} (-1 = all bits set)');
  print('pick a where true, else 0: ${lanes(m.select(a, Float32x4.zero()))}');
}
Output
a <= b lane flags: [true, true, false, true]
as masks: [-1, -1, 0, -1] (-1 = all bits set)
pick a where true, else 0: [1.0, 5.0, 0.0, 9.0]
Int32x4 greaterThan(Float32x4 other)

Lane-wise greater-than comparison.

Compares the 32-bit floating point value of each lane of this to the value of the corresponding lane of other, using 32-bit floating point comparison. For floating point comparisons, a comparison with a NaN value is always false, and -0.0 (negative zero) is considered equal to 0.0 (positive zero), and not less strictly than it. The result for a lane is a 32-bit signed integer which is -1 (all bits set) if the value from this object is greater than the value from other, and the result is 0 (all bits cleared) if not, including if either value is a NaN value.

Returns four values that are always either 0 or -1.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];
List<int> mask(Int32x4 m) => [m.x, m.y, m.z, m.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final a = Float32x4(1, 5, 3, 9), b = Float32x4(2, 5, 1, 9);
  final m = a.greaterThan(b);
  print('a > b lane flags: ${flags(m)}');
  print('as masks: ${mask(m)} (-1 = all bits set)');
  print('pick a where true, else 0: ${lanes(m.select(a, Float32x4.zero()))}');
}
Output
a > b lane flags: [false, false, true, false]
as masks: [0, 0, -1, 0] (-1 = all bits set)
pick a where true, else 0: [0.0, 0.0, 3.0, 0.0]
Int32x4 greaterThanOrEqual(Float32x4 other)

Lane-wise greater-than-or-equal comparison.

Compares the 32-bit floating point value of each lane of this to the value of the corresponding lane of other, using 32-bit floating point comparison. For floating point comparisons, a comparison with a NaN value is always false, and -0.0 (negative zero) is considered equal to 0.0 (positive zero), and not less strictly than it. The result for a lane is a 32-bit signed integer which is -1 (all bits set) if the value from this object is greater than or equal to the value from other, and the result is 0 (all bits cleared) if not, including if either value is a NaN value.

Returns four values that are always either 0 or -1.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];
List<int> mask(Int32x4 m) => [m.x, m.y, m.z, m.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final a = Float32x4(1, 5, 3, 9), b = Float32x4(2, 5, 1, 9);
  final m = a.greaterThanOrEqual(b);
  print('a >= b lane flags: ${flags(m)}');
  print('as masks: ${mask(m)} (-1 = all bits set)');
  print('pick a where true, else 0: ${lanes(m.select(a, Float32x4.zero()))}');
}
Output
a >= b lane flags: [false, true, true, true]
as masks: [0, -1, -1, -1] (-1 = all bits set)
pick a where true, else 0: [0.0, 5.0, 3.0, 9.0]
equalmethod
Int32x4 equal(Float32x4 other)

Lane-wise equals comparison.

Compares the 32-bit floating point value of each lane of this to the value of the corresponding lane of other, using 32-bit floating point comparison. For floating point comparisons, a comparison with a NaN value is always false, and -0.0 (negative zero) is considered equal to 0.0 (positive zero), and not less strictly than it. The result for a lane is a 32-bit signed integer which is -1 (all bits set) if the value from this object is equal to the value from other, and the result is 0 (all bits cleared) if not, including if either value is a NaN value.

Returns four values that are always either 0 or -1.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];
List<int> mask(Int32x4 m) => [m.x, m.y, m.z, m.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final a = Float32x4(1, 5, 3, 9), b = Float32x4(2, 5, 1, 9);
  final m = a.equal(b);
  print('a == b lane flags: ${flags(m)}');
  print('as masks: ${mask(m)} (-1 = all bits set)');
  print('pick a where true, else 0: ${lanes(m.select(a, Float32x4.zero()))}');
}
Output
a == b lane flags: [false, true, false, true]
as masks: [0, -1, 0, -1] (-1 = all bits set)
pick a where true, else 0: [0.0, 5.0, 0.0, 9.0]
notEqualmethod
Int32x4 notEqual(Float32x4 other)

Lane-wise not-equals comparison.

Compares the 32-bit floating point value of each lane of this to the value of the corresponding lane of other, using 32-bit floating point comparison. For floating point comparisons, a comparison with a NaN value is always false, and -0.0 (negative zero) is considered equal to 0.0 (positive zero), and not less strictly than it. The result for a lane is a 32-bit signed integer which is -1 (all bits set) if the value from this object is not equal to the value from other, and the result is 0 (all bits cleared) if not, including if either value is a NaN value.

Returns four values that are always either 0 or -1.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];
List<int> mask(Int32x4 m) => [m.x, m.y, m.z, m.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final a = Float32x4(1, 5, 3, 9), b = Float32x4(2, 5, 1, 9);
  final m = a.notEqual(b);
  print('a != b lane flags: ${flags(m)}');
  print('as masks: ${mask(m)} (-1 = all bits set)');
  print('pick a where true, else 0: ${lanes(m.select(a, Float32x4.zero()))}');
}
Output
a != b lane flags: [true, false, true, false]
as masks: [-1, 0, -1, 0] (-1 = all bits set)
pick a where true, else 0: [1.0, 0.0, 3.0, 0.0]
scalemethod
Float32x4 scale(double scale)

Lane-wise multiplication by scale.

Returns a result where each lane is the result of multiplying the corresponding lane of this value with scale. This can happen either by converting the lane value to a 64-bit floating point value, multiplying it with scale and converting the result back to a 32-bit floating point value, or by converting scale to a 32-bit floating point value and performing a 32-bit floating point multiplication.

In the latter case it is equivalent to thisValue * Float32x4.splat(s).

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, -2, 0.5, 4);
  print('scale(3):    ${lanes(v.scale(3))}');
  print('scale(-0.5): ${lanes(v.scale(-0.5))}');
}
Output
scale(3):    [3.0, -6.0, 1.5, 12.0]
scale(-0.5): [-0.5, 1.0, -0.25, -2.0]
absmethod
Float32x4 abs()

Lane-wise conversion to absolute value.

Converts each lane's value to a non-negative value by negating the value if it is negative, and keeping the original value if it is not negative.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(-1.5, 2, -0.0, -8);
  print('abs: ${lanes(v.abs())}');
}
Output
abs: [1.5, 2.0, 0.0, 8.0]
clampmethod
Float32x4 clamp(Float32x4 lowerLimit, Float32x4 upperLimit)

Lane-wise clamp to a range.

Clamps the value of each lane to a minimum value of the corresponding lane of lowerLimit and a maximum value of the corresponding lane of upperLimit. If the original value is lower than the minimum value, the result is the minimum value, and if original value is greater than the maximum value, the result is the maximum value. The result is unspecified if the maximum value is lower than the minimum value, or if any of the three values is a NaN value, other than that the result will be one of those three values, or possibly a different NaN value if any value is a NaN value.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(-5, 0.5, 2, 9);
  final c = v.clamp(Float32x4.splat(0), Float32x4.splat(1));
  print('clamp to [0, 1]: ${lanes(c)}');
}
Output
clamp to [0, 1]: [0.0, 0.5, 1.0, 1.0]
shufflemethod
Float32x4 shuffle(int mask)

Shuffle the lane values based on the mask.

The mask must be one of the 256 shuffle masks from xxxx to wwww.

Creates a new Float32x4 whose lane values are taken from the lanes of this value based on the lanes of the shuffle mask, with the result's x lane being taken from the lane of the first letter of the shuffle mask's name, the y lane from the second letter, z lane from the third letter and w lane from the fourth letter.

For example, the shuffle mask wxyz creates a new Float32x4 whose x lane is the w lane of this value, because the first letter of the shuffle mask's name, wxyz is "w". Then the y, z and w lanes of the result are the values of the x, y and z lanes of this value.

The xyzw "identity shuffle" mask gives a result with the same lanes as the original.

Some masks preserve the values of all lanes, but may permute them. Other masks duplicates some lanes and discards the values of others.

For example, doing v1.shuffle(yyyy) is equivalent to Float32x4.splat(v1.y).

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2, 3, 4);
  print('wzyx (reverse): ${lanes(v.shuffle(Float32x4.wzyx))}');
  print('xxxx (splat x): ${lanes(v.shuffle(Float32x4.xxxx))}');
  print('yxwz (swap pairs): ${lanes(v.shuffle(Float32x4.yxwz))}');
}
Output
wzyx (reverse): [4.0, 3.0, 2.0, 1.0]
xxxx (splat x): [1.0, 1.0, 1.0, 1.0]
yxwz (swap pairs): [2.0, 1.0, 4.0, 3.0]
Float32x4 shuffleMix(Float32x4 other, int mask)

Mixes lanes chosen from two Float32x4 values using a mask.

Creates a new Float32x4 where the x and y lanes are chosen from the lanes of this value selected by the first two letters of the mask's name, and the z and w lanes are the lanes of other selected by the last two letters of the mask's name.

For example, v1.shuffleMix(v2, Float32x4.xyzw) is equivalent to Float32x4(v1.x, v1.y, v2.z, v2.w).

If other is the same value as this Float32x4, this function is the same as shuffle. That is, doing v1.shuffleMix(v1, mask) is equivalent to v1.shuffle(mask).

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(1, 2, 3, 4), b = Float32x4(10, 20, 30, 40);
  // x and y come from a, z and w from b.
  print('a.shuffleMix(b, xyxy): ${lanes(a.shuffleMix(b, Float32x4.xyxy))}');
  print('a.shuffleMix(b, wzzw): ${lanes(a.shuffleMix(b, Float32x4.wzzw))}');
}
Output
a.shuffleMix(b, xyxy): [1.0, 2.0, 10.0, 20.0]
a.shuffleMix(b, wzzw): [4.0, 3.0, 30.0, 40.0]
withXmethod
Float32x4 withX(double x)

This value, but with the value of the Float32x4.x lane set to x.

Returns a new Float32x4 with the same values for the y, z and w lanes as this value, and with a Float32x4.x lane having the value x converted to a 32-bit floating point number.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2, 3, 4);
  final w = v.withX(99);
  print('withX(99): ${lanes(w)}');
  print('original unchanged: ${lanes(v)}');
}
Output
withX(99): [99.0, 2.0, 3.0, 4.0]
original unchanged: [1.0, 2.0, 3.0, 4.0]
withYmethod
Float32x4 withY(double y)

This value, but with the value of the Float32x4.y lane set to y.

Returns a new Float32x4 with the same values for the x, z and w lanes as this value, and with a Float32x4.y lane having the value y converted to a 32-bit floating point number.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2, 3, 4);
  final w = v.withY(99);
  print('withY(99): ${lanes(w)}');
  print('original unchanged: ${lanes(v)}');
}
Output
withY(99): [1.0, 99.0, 3.0, 4.0]
original unchanged: [1.0, 2.0, 3.0, 4.0]
withZmethod
Float32x4 withZ(double z)

This value, but with the value of the Float32x4.z lane set to z.

Returns a new Float32x4 with the same values for the x, y and w lanes as this value, and with a Float32x4.z lane having the value z converted to a 32-bit floating point number.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2, 3, 4);
  final w = v.withZ(99);
  print('withZ(99): ${lanes(w)}');
  print('original unchanged: ${lanes(v)}');
}
Output
withZ(99): [1.0, 2.0, 99.0, 4.0]
original unchanged: [1.0, 2.0, 3.0, 4.0]
withWmethod
Float32x4 withW(double w)

This value, but with the value of the Float32x4.w lane set to w.

Returns a new Float32x4 with the same values for the x, y and z lanes as this value, and with a Float32x4.w lane having the value w converted to a 32-bit floating point number.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2, 3, 4);
  final w = v.withW(99);
  print('withW(99): ${lanes(w)}');
  print('original unchanged: ${lanes(v)}');
}
Output
withW(99): [1.0, 2.0, 3.0, 99.0]
original unchanged: [1.0, 2.0, 3.0, 4.0]
minmethod
Float32x4 min(Float32x4 other)

Lane-wise minimum.

For each lane select the lesser of the lane value of this and other.

The result is the lesser of the two lane values if either is lesser. The result is unspecified if either lane contains a NaN value or if the values are -0.0 and 0.0, so that neither value is smaller or greater than the other. Different platforms may give different results in those cases, but always one of the lane values.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(1, 8, -3, 4), b = Float32x4(2, 5, -7, 4);
  print('lane-wise min: ${lanes(a.min(b))}');
}
Output
lane-wise min: [1.0, 5.0, -7.0, 4.0]
maxmethod
Float32x4 max(Float32x4 other)

Lane-wise maximum.

For each lane select the greater of the lane value of this and other.

The result is the greater of the two lane values if either is greater. The result is unspecified if either lane contains a NaN value or if the values are -0.0 and 0.0, so that neither value is smaller or greater than the other. Different platforms may give different results in those cases, but always one of the lane values.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(1, 8, -3, 4), b = Float32x4(2, 5, -7, 4);
  print('lane-wise max: ${lanes(a.max(b))}');
}
Output
lane-wise max: [2.0, 8.0, -3.0, 4.0]
sqrtmethod
Float32x4 sqrt()

Lane-wise square root.

For each lane compute the 32-bit floating point square root of the lane's value.

The result for a lane is a NaN value if the original value is less than zero or if it is a NaN value. The result for a negative zero, -0.0, is the same value again. The result for positive infinity is positive infinity. Otherwise the result is a positive value which approximates the mathematical square root of the original value.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(4, 9, 16, 2);
  final r = v.sqrt();
  print('sqrt: ${lanes(r).map((d) => d.toStringAsFixed(4)).toList()}');
}
Output
sqrt: [2.0000, 3.0000, 4.0000, 1.4142]
Float32x4 reciprocal()

Lane-wise reciprocal.

For each lane compute the result of dividing 1.0 by the lane's value.

If the value is a NaN value, so is the result. If the value is infinite, the result is a zero value with the same sign. If the value is zero, the result is infinite with the same sign. Otherwise the result is an approximation of the mathematical result of dividing 1 by the (finite, non-zero) value of the lane.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 2, 4, 8);
  final r = v.reciprocal();
  print('1/v: ${lanes(r).map((d) => d.toStringAsFixed(3)).toList()}');
}
Output
1/v: [1.000, 0.500, 0.250, 0.125]
Float32x4 reciprocalSqrt()

Lane-wise approximation of reciprocal square root.

Approximates the same result as reciprocal followed by sqrt, or sqrt followed by reciprocal, but may be more precise and/or efficient due to computing the result directly, rather than not creating a an intermediate result, and possibly by working entirely at a reduced precision.

The result can differ between platforms due to differences in approximation and precision, and for values where the order of sqrt and reciprocal makes a difference. The latter applies specifically to -0.0 where sqrt(-0.0) is defined to be -0.0, and reciprocal of that is -Infinity. In the opposite order it computes sqrt of -Infinity which is NaN.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, 4, 16, 64);
  final r = v.reciprocalSqrt();
  print('1/sqrt(v): ${lanes(r).map((d) => d.toStringAsFixed(3)).toList()}');
}
Output
1/sqrt(v): [1.000, 0.500, 0.250, 0.125]

Operators

operator +operator
Float32x4 operator +(Float32x4 other)

Lane-wise addition.

Adds the value of each lane of this value to the value of the corresponding lane of other.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(1, 2, 3, 4), b = Float32x4(10, 20, 30, 40);
  print('a + b: ${lanes(a + b)}');
}
Output
a + b: [11.0, 22.0, 33.0, 44.0]
operator -operator
Float32x4 operator -()

Lane-wise negation.

Returns a result where each lane is the negation of the corresponding lane of this value.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Float32x4(1, -2, 3, 0);
  print('-v: ${lanes(-v)}');
}
Output
-v: [-1.0, 2.0, -3.0, -0.0]
operator -operator
Float32x4 operator -(Float32x4 other)

Lane-wise subtraction.

Subtracts the value of each lane of other from the value of the corresponding lane of this value.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(10, 20, 30, 40), b = Float32x4(1, 2, 3, 4);
  print('a - b: ${lanes(a - b)}');
}
Output
a - b: [9.0, 18.0, 27.0, 36.0]
operator *operator
Float32x4 operator *(Float32x4 other)

Lane-wise multiplication.

Multiplies the value of each lane of this value with the value of the corresponding lane of other.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(1, 2, 3, 4), b = Float32x4(2, 2, 0.5, -1);
  print('a * b: ${lanes(a * b)}');
  // A 4-lane dot product: multiply, then add the lanes.
  final p = a * a;
  print('|a|^2 = ${p.x + p.y + p.z + p.w}');
}
Output
a * b: [2.0, 4.0, 1.5, -4.0]
|a|^2 = 30.0
operator /operator
Float32x4 operator /(Float32x4 other)

Lane-wise division.

Divides the value of each lane of this value with the value of the corresponding lane of other.

Returns the result for each lane.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Float32x4(1, 9, 5, -8), b = Float32x4(2, 3, 0.5, 4);
  print('a / b: ${lanes(a / b)}');
}
Output
a / b: [0.5, 3.0, 10.0, -2.0]
class

Int32x4

abstract final class Int32x4

Int32x4 and operations.

Int32x4 stores 4 32-bit bit-masks in "lanes". The lanes are "x", "y", "z", and "w" respectively.

Example
import 'raya:typed_data';

void main() {
  final a = Int32x4(1, 2, 3, 4);
  final b = Int32x4(10, 20, 30, 40);
  print('a + b: ${a + b}');
  print('a & b: ${a & b}');
  print('lanes: ${(a + b).x}, ${(a + b).w}');
}
Output
a + b: [0000000b, 00000016, 00000021, 0000002c]
a & b: [00000000, 00000000, 00000002, 00000000]
lanes: 11, 44

Constructors

Int32x4factory
external factory Int32x4(int x, int y, int z, int w)
Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Int32x4(1, -2, 3, 0x7fffffff);
  print('lanes: ${lanes(v)}');
  // Lanes are 32 bits: larger values wrap.
  print('2^32 + 5 -> ${Int32x4(0x100000005, 0, 0, 0).x}');
}
Output
lanes: [1, -2, 3, 2147483647]
2^32 + 5 -> 5
external factory Int32x4.bool(bool x, bool y, bool z, bool w)
Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final m = Int32x4.bool(true, false, true, false);
  print('lanes: ${lanes(m)} (true = -1, all bits set)');
  print('flags: ${flags(m)}');
}
Output
lanes: [-1, 0, -1, 0] (true = -1, all bits set)
flags: [true, false, true, false]
external factory Int32x4.fromFloat32x4Bits(Float32x4 x)
Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final bits = Int32x4.fromFloat32x4Bits(Float32x4(1, -1, 0.5, 0));
  print('float bit patterns: ${lanes(bits).map((b) => '0x${b.toUnsigned(32).toRadixString(16)}').toList()}');
}
Output
float bit patterns: [0x3f800000, 0xbf800000, 0x3f000000, 0x0]

Static

xxxxconstant
static const int xxxx = 0x00

Mask passed to shuffle or shuffleMix.

xxxyconstant
static const int xxxy = 0x40
xxxzconstant
static const int xxxz = 0x80
xxxwconstant
static const int xxxw = 0xC0
xxyxconstant
static const int xxyx = 0x10
xxyyconstant
static const int xxyy = 0x50
xxyzconstant
static const int xxyz = 0x90
xxywconstant
static const int xxyw = 0xD0
xxzxconstant
static const int xxzx = 0x20
xxzyconstant
static const int xxzy = 0x60
xxzzconstant
static const int xxzz = 0xA0
xxzwconstant
static const int xxzw = 0xE0
xxwxconstant
static const int xxwx = 0x30
xxwyconstant
static const int xxwy = 0x70
xxwzconstant
static const int xxwz = 0xB0
xxwwconstant
static const int xxww = 0xF0
xyxxconstant
static const int xyxx = 0x04
xyxyconstant
static const int xyxy = 0x44
xyxzconstant
static const int xyxz = 0x84
xyxwconstant
static const int xyxw = 0xC4
xyyxconstant
static const int xyyx = 0x14
xyyyconstant
static const int xyyy = 0x54
xyyzconstant
static const int xyyz = 0x94
xyywconstant
static const int xyyw = 0xD4
xyzxconstant
static const int xyzx = 0x24
xyzyconstant
static const int xyzy = 0x64
xyzzconstant
static const int xyzz = 0xA4
xyzwconstant
static const int xyzw = 0xE4
xywxconstant
static const int xywx = 0x34
xywyconstant
static const int xywy = 0x74
xywzconstant
static const int xywz = 0xB4
xywwconstant
static const int xyww = 0xF4
xzxxconstant
static const int xzxx = 0x08
xzxyconstant
static const int xzxy = 0x48
xzxzconstant
static const int xzxz = 0x88
xzxwconstant
static const int xzxw = 0xC8
xzyxconstant
static const int xzyx = 0x18
xzyyconstant
static const int xzyy = 0x58
xzyzconstant
static const int xzyz = 0x98
xzywconstant
static const int xzyw = 0xD8
xzzxconstant
static const int xzzx = 0x28
xzzyconstant
static const int xzzy = 0x68
xzzzconstant
static const int xzzz = 0xA8
xzzwconstant
static const int xzzw = 0xE8
xzwxconstant
static const int xzwx = 0x38
xzwyconstant
static const int xzwy = 0x78
xzwzconstant
static const int xzwz = 0xB8
xzwwconstant
static const int xzww = 0xF8
xwxxconstant
static const int xwxx = 0x0C
xwxyconstant
static const int xwxy = 0x4C
xwxzconstant
static const int xwxz = 0x8C
xwxwconstant
static const int xwxw = 0xCC
xwyxconstant
static const int xwyx = 0x1C
xwyyconstant
static const int xwyy = 0x5C
xwyzconstant
static const int xwyz = 0x9C
xwywconstant
static const int xwyw = 0xDC
xwzxconstant
static const int xwzx = 0x2C
xwzyconstant
static const int xwzy = 0x6C
xwzzconstant
static const int xwzz = 0xAC
xwzwconstant
static const int xwzw = 0xEC
xwwxconstant
static const int xwwx = 0x3C
xwwyconstant
static const int xwwy = 0x7C
xwwzconstant
static const int xwwz = 0xBC
xwwwconstant
static const int xwww = 0xFC
yxxxconstant
static const int yxxx = 0x01
yxxyconstant
static const int yxxy = 0x41
yxxzconstant
static const int yxxz = 0x81
yxxwconstant
static const int yxxw = 0xC1
yxyxconstant
static const int yxyx = 0x11
yxyyconstant
static const int yxyy = 0x51
yxyzconstant
static const int yxyz = 0x91
yxywconstant
static const int yxyw = 0xD1
yxzxconstant
static const int yxzx = 0x21
yxzyconstant
static const int yxzy = 0x61
yxzzconstant
static const int yxzz = 0xA1
yxzwconstant
static const int yxzw = 0xE1
yxwxconstant
static const int yxwx = 0x31
yxwyconstant
static const int yxwy = 0x71
yxwzconstant
static const int yxwz = 0xB1
yxwwconstant
static const int yxww = 0xF1
yyxxconstant
static const int yyxx = 0x05
yyxyconstant
static const int yyxy = 0x45
yyxzconstant
static const int yyxz = 0x85
yyxwconstant
static const int yyxw = 0xC5
yyyxconstant
static const int yyyx = 0x15
yyyyconstant
static const int yyyy = 0x55
yyyzconstant
static const int yyyz = 0x95
yyywconstant
static const int yyyw = 0xD5
yyzxconstant
static const int yyzx = 0x25
yyzyconstant
static const int yyzy = 0x65
yyzzconstant
static const int yyzz = 0xA5
yyzwconstant
static const int yyzw = 0xE5
yywxconstant
static const int yywx = 0x35
yywyconstant
static const int yywy = 0x75
yywzconstant
static const int yywz = 0xB5
yywwconstant
static const int yyww = 0xF5
yzxxconstant
static const int yzxx = 0x09
yzxyconstant
static const int yzxy = 0x49
yzxzconstant
static const int yzxz = 0x89
yzxwconstant
static const int yzxw = 0xC9
yzyxconstant
static const int yzyx = 0x19
yzyyconstant
static const int yzyy = 0x59
yzyzconstant
static const int yzyz = 0x99
yzywconstant
static const int yzyw = 0xD9
yzzxconstant
static const int yzzx = 0x29
yzzyconstant
static const int yzzy = 0x69
yzzzconstant
static const int yzzz = 0xA9
yzzwconstant
static const int yzzw = 0xE9
yzwxconstant
static const int yzwx = 0x39
yzwyconstant
static const int yzwy = 0x79
yzwzconstant
static const int yzwz = 0xB9
yzwwconstant
static const int yzww = 0xF9
ywxxconstant
static const int ywxx = 0x0D
ywxyconstant
static const int ywxy = 0x4D
ywxzconstant
static const int ywxz = 0x8D
ywxwconstant
static const int ywxw = 0xCD
ywyxconstant
static const int ywyx = 0x1D
ywyyconstant
static const int ywyy = 0x5D
ywyzconstant
static const int ywyz = 0x9D
ywywconstant
static const int ywyw = 0xDD
ywzxconstant
static const int ywzx = 0x2D
ywzyconstant
static const int ywzy = 0x6D
ywzzconstant
static const int ywzz = 0xAD
ywzwconstant
static const int ywzw = 0xED
ywwxconstant
static const int ywwx = 0x3D
ywwyconstant
static const int ywwy = 0x7D
ywwzconstant
static const int ywwz = 0xBD
ywwwconstant
static const int ywww = 0xFD
zxxxconstant
static const int zxxx = 0x02
zxxyconstant
static const int zxxy = 0x42
zxxzconstant
static const int zxxz = 0x82
zxxwconstant
static const int zxxw = 0xC2
zxyxconstant
static const int zxyx = 0x12
zxyyconstant
static const int zxyy = 0x52
zxyzconstant
static const int zxyz = 0x92
zxywconstant
static const int zxyw = 0xD2
zxzxconstant
static const int zxzx = 0x22
zxzyconstant
static const int zxzy = 0x62
zxzzconstant
static const int zxzz = 0xA2
zxzwconstant
static const int zxzw = 0xE2
zxwxconstant
static const int zxwx = 0x32
zxwyconstant
static const int zxwy = 0x72
zxwzconstant
static const int zxwz = 0xB2
zxwwconstant
static const int zxww = 0xF2
zyxxconstant
static const int zyxx = 0x06
zyxyconstant
static const int zyxy = 0x46
zyxzconstant
static const int zyxz = 0x86
zyxwconstant
static const int zyxw = 0xC6
zyyxconstant
static const int zyyx = 0x16
zyyyconstant
static const int zyyy = 0x56
zyyzconstant
static const int zyyz = 0x96
zyywconstant
static const int zyyw = 0xD6
zyzxconstant
static const int zyzx = 0x26
zyzyconstant
static const int zyzy = 0x66
zyzzconstant
static const int zyzz = 0xA6
zyzwconstant
static const int zyzw = 0xE6
zywxconstant
static const int zywx = 0x36
zywyconstant
static const int zywy = 0x76
zywzconstant
static const int zywz = 0xB6
zywwconstant
static const int zyww = 0xF6
zzxxconstant
static const int zzxx = 0x0A
zzxyconstant
static const int zzxy = 0x4A
zzxzconstant
static const int zzxz = 0x8A
zzxwconstant
static const int zzxw = 0xCA
zzyxconstant
static const int zzyx = 0x1A
zzyyconstant
static const int zzyy = 0x5A
zzyzconstant
static const int zzyz = 0x9A
zzywconstant
static const int zzyw = 0xDA
zzzxconstant
static const int zzzx = 0x2A
zzzyconstant
static const int zzzy = 0x6A
zzzzconstant
static const int zzzz = 0xAA
zzzwconstant
static const int zzzw = 0xEA
zzwxconstant
static const int zzwx = 0x3A
zzwyconstant
static const int zzwy = 0x7A
zzwzconstant
static const int zzwz = 0xBA
zzwwconstant
static const int zzww = 0xFA
zwxxconstant
static const int zwxx = 0x0E
zwxyconstant
static const int zwxy = 0x4E
zwxzconstant
static const int zwxz = 0x8E
zwxwconstant
static const int zwxw = 0xCE
zwyxconstant
static const int zwyx = 0x1E
zwyyconstant
static const int zwyy = 0x5E
zwyzconstant
static const int zwyz = 0x9E
zwywconstant
static const int zwyw = 0xDE
zwzxconstant
static const int zwzx = 0x2E
zwzyconstant
static const int zwzy = 0x6E
zwzzconstant
static const int zwzz = 0xAE
zwzwconstant
static const int zwzw = 0xEE
zwwxconstant
static const int zwwx = 0x3E
zwwyconstant
static const int zwwy = 0x7E
zwwzconstant
static const int zwwz = 0xBE
zwwwconstant
static const int zwww = 0xFE
wxxxconstant
static const int wxxx = 0x03
wxxyconstant
static const int wxxy = 0x43
wxxzconstant
static const int wxxz = 0x83
wxxwconstant
static const int wxxw = 0xC3
wxyxconstant
static const int wxyx = 0x13
wxyyconstant
static const int wxyy = 0x53
wxyzconstant
static const int wxyz = 0x93
wxywconstant
static const int wxyw = 0xD3
wxzxconstant
static const int wxzx = 0x23
wxzyconstant
static const int wxzy = 0x63
wxzzconstant
static const int wxzz = 0xA3
wxzwconstant
static const int wxzw = 0xE3
wxwxconstant
static const int wxwx = 0x33
wxwyconstant
static const int wxwy = 0x73
wxwzconstant
static const int wxwz = 0xB3
wxwwconstant
static const int wxww = 0xF3
wyxxconstant
static const int wyxx = 0x07
wyxyconstant
static const int wyxy = 0x47
wyxzconstant
static const int wyxz = 0x87
wyxwconstant
static const int wyxw = 0xC7
wyyxconstant
static const int wyyx = 0x17
wyyyconstant
static const int wyyy = 0x57
wyyzconstant
static const int wyyz = 0x97
wyywconstant
static const int wyyw = 0xD7
wyzxconstant
static const int wyzx = 0x27
wyzyconstant
static const int wyzy = 0x67
wyzzconstant
static const int wyzz = 0xA7
wyzwconstant
static const int wyzw = 0xE7
wywxconstant
static const int wywx = 0x37
wywyconstant
static const int wywy = 0x77
wywzconstant
static const int wywz = 0xB7
wywwconstant
static const int wyww = 0xF7
wzxxconstant
static const int wzxx = 0x0B
wzxyconstant
static const int wzxy = 0x4B
wzxzconstant
static const int wzxz = 0x8B
wzxwconstant
static const int wzxw = 0xCB
wzyxconstant
static const int wzyx = 0x1B
wzyyconstant
static const int wzyy = 0x5B
wzyzconstant
static const int wzyz = 0x9B
wzywconstant
static const int wzyw = 0xDB
wzzxconstant
static const int wzzx = 0x2B
wzzyconstant
static const int wzzy = 0x6B
wzzzconstant
static const int wzzz = 0xAB
wzzwconstant
static const int wzzw = 0xEB
wzwxconstant
static const int wzwx = 0x3B
wzwyconstant
static const int wzwy = 0x7B
wzwzconstant
static const int wzwz = 0xBB
wzwwconstant
static const int wzww = 0xFB
wwxxconstant
static const int wwxx = 0x0F
wwxyconstant
static const int wwxy = 0x4F
wwxzconstant
static const int wwxz = 0x8F
wwxwconstant
static const int wwxw = 0xCF
wwyxconstant
static const int wwyx = 0x1F
wwyyconstant
static const int wwyy = 0x5F
wwyzconstant
static const int wwyz = 0x9F
wwywconstant
static const int wwyw = 0xDF
wwzxconstant
static const int wwzx = 0x2F
wwzyconstant
static const int wwzy = 0x6F
wwzzconstant
static const int wwzz = 0xAF
wwzwconstant
static const int wwzw = 0xEF
wwwxconstant
static const int wwwx = 0x3F
wwwyconstant
static const int wwwy = 0x7F
wwwzconstant
static const int wwwz = 0xBF
wwwwconstant
static const int wwww = 0xFF

Properties

xgetter
int get x

Extract 32-bit mask from x lane.

ygetter
int get y

Extract 32-bit mask from y lane.

zgetter
int get z

Extract 32-bit mask from z lane.

wgetter
int get w

Extract 32-bit mask from w lane.

signMaskgetter
int get signMask

Extract the top bit from each lane return them in the first 4 bits. "x" lane is bit 0. "y" lane is bit 1. "z" lane is bit 2. "w" lane is bit 3.

flagXgetter
bool get flagX

Extracted x value. Returns false for 0, true for any other value.

flagYgetter
bool get flagY

Extracted y value. Returns false for 0, true for any other value.

flagZgetter
bool get flagZ

Extracted z value. Returns false for 0, true for any other value.

flagWgetter
bool get flagW

Extracted w value. Returns false for 0, true for any other value.

Methods

shufflemethod
Int32x4 shuffle(int mask)

Shuffle the lane values. mask must be one of the 256 shuffle constants.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Int32x4(1, 2, 3, 4);
  print('wzyx: ${lanes(v.shuffle(Int32x4.wzyx))}');
  print('zzzz: ${lanes(v.shuffle(Int32x4.zzzz))}');
}
Output
wzyx: [4, 3, 2, 1]
zzzz: [3, 3, 3, 3]
Int32x4 shuffleMix(Int32x4 other, int mask)

Shuffle the lane values in this Int32x4 and other. The returned Int32x4 will have XY lanes from this Int32x4 and ZW lanes from other. Uses the same mask as shuffle.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Int32x4(1, 2, 3, 4), b = Int32x4(10, 20, 30, 40);
  print('a.shuffleMix(b, xyzw): ${lanes(a.shuffleMix(b, Int32x4.xyzw))}');
  print('a.shuffleMix(b, wwxx): ${lanes(a.shuffleMix(b, Int32x4.wwxx))}');
}
Output
a.shuffleMix(b, xyzw): [1, 2, 30, 40]
a.shuffleMix(b, wwxx): [4, 4, 10, 10]
withXmethod
Int32x4 withX(int x)

Returns a new Int32x4 copied from this Int32x4 with a new x value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Int32x4(1, 2, 3, 4);
  print('withX(-7): ${lanes(v.withX(-7))}');
  print('original:   ${lanes(v)}');
}
Output
withX(-7): [-7, 2, 3, 4]
original:   [1, 2, 3, 4]
withYmethod
Int32x4 withY(int y)

Returns a new Int32x4 copied from this Int32x4 with a new y value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Int32x4(1, 2, 3, 4);
  print('withY(-7): ${lanes(v.withY(-7))}');
  print('original:   ${lanes(v)}');
}
Output
withY(-7): [1, -7, 3, 4]
original:   [1, 2, 3, 4]
withZmethod
Int32x4 withZ(int z)

Returns a new Int32x4 copied from this Int32x4 with a new z value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Int32x4(1, 2, 3, 4);
  print('withZ(-7): ${lanes(v.withZ(-7))}');
  print('original:   ${lanes(v)}');
}
Output
withZ(-7): [1, 2, -7, 4]
original:   [1, 2, 3, 4]
withWmethod
Int32x4 withW(int w)

Returns a new Int32x4 copied from this Int32x4 with a new w value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final v = Int32x4(1, 2, 3, 4);
  print('withW(-7): ${lanes(v.withW(-7))}');
  print('original:   ${lanes(v)}');
}
Output
withW(-7): [1, 2, 3, -7]
original:   [1, 2, 3, 4]
withFlagXmethod
Int32x4 withFlagX(bool x)

Returns a new Int32x4 copied from this Int32x4 with a new x value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final m = Int32x4.bool(false, false, false, false);
  final m2 = m.withFlagX(true);
  print('withFlagX(true): ${flags(m2)}');
  print('lane values: ${lanes(m2)}');
}
Output
withFlagX(true): [true, false, false, false]
lane values: [-1, 0, 0, 0]
withFlagYmethod
Int32x4 withFlagY(bool y)

Returns a new Int32x4 copied from this Int32x4 with a new y value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final m = Int32x4.bool(false, false, false, false);
  final m2 = m.withFlagY(true);
  print('withFlagY(true): ${flags(m2)}');
  print('lane values: ${lanes(m2)}');
}
Output
withFlagY(true): [false, true, false, false]
lane values: [0, -1, 0, 0]
withFlagZmethod
Int32x4 withFlagZ(bool z)

Returns a new Int32x4 copied from this Int32x4 with a new z value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final m = Int32x4.bool(false, false, false, false);
  final m2 = m.withFlagZ(true);
  print('withFlagZ(true): ${flags(m2)}');
  print('lane values: ${lanes(m2)}');
}
Output
withFlagZ(true): [false, false, true, false]
lane values: [0, 0, -1, 0]
withFlagWmethod
Int32x4 withFlagW(bool w)

Returns a new Int32x4 copied from this Int32x4 with a new w value.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final m = Int32x4.bool(false, false, false, false);
  final m2 = m.withFlagW(true);
  print('withFlagW(true): ${flags(m2)}');
  print('lane values: ${lanes(m2)}');
}
Output
withFlagW(true): [false, false, false, true]
lane values: [0, 0, 0, -1]
selectmethod
Float32x4 select(Float32x4 trueValue, Float32x4 falseValue)

Merge trueValue and falseValue based on this Int32x4 bit mask: Select bit from trueValue when bit in this Int32x4 is on. Select bit from falseValue when bit in this Int32x4 is off.

Example
import 'raya:typed_data';

List<double> lanes(Float32x4 v) => [v.x, v.y, v.z, v.w];
List<int> mask(Int32x4 m) => [m.x, m.y, m.z, m.w];
List<bool> flags(Int32x4 m) => [m.flagX, m.flagY, m.flagZ, m.flagW];

void main() {
  final a = Float32x4(1, 2, 3, 4), b = Float32x4(-1, -2, -3, -4);
  final m = Int32x4.bool(true, false, false, true);
  print('select(a, b): ${lanes(m.select(a, b))}');
  // Branch-free max: pick a where a > b.
  print('max via select: ${lanes(a.greaterThan(b).select(a, b))}');
}
Output
select(a, b): [1.0, -2.0, -3.0, 4.0]
max via select: [1.0, 2.0, 3.0, 4.0]

Operators

operator |operator
Int32x4 operator |(Int32x4 other)

The bit-wise or operator.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Int32x4(0x0f, 0, 1, 8), b = Int32x4(0xf0, 0, 2, 8);
  print('a | b: ${lanes(a | b)}');
}
Output
a | b: [255, 0, 3, 8]
operator &operator
Int32x4 operator &(Int32x4 other)

The bit-wise and operator.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Int32x4(0xff, 6, 1, -1), b = Int32x4(0x0f, 3, 2, 42);
  print('a & b: ${lanes(a & b)}');
}
Output
a & b: [15, 2, 0, 42]
operator ^operator
Int32x4 operator ^(Int32x4 other)

The bit-wise xor operator.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Int32x4(5, 6, 0, -1), b = Int32x4(3, 6, 7, 0);
  print('a ^ b: ${lanes(a ^ b)}');
}
Output
a ^ b: [6, 0, 7, -1]
operator +operator
Int32x4 operator +(Int32x4 other)

Addition operator.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Int32x4(1, 2, 0x7fffffff, -1), b = Int32x4(10, 20, 1, 1);
  print('a + b: ${lanes(a + b)} (the third lane wraps)');
}
Output
a + b: [11, 22, -2147483648, 0] (the third lane wraps)
operator -operator
Int32x4 operator -(Int32x4 other)

Subtraction operator.

Example
import 'raya:typed_data';

List<int> lanes(Int32x4 v) => [v.x, v.y, v.z, v.w];

void main() {
  final a = Int32x4(10, 20, -0x80000000, 0), b = Int32x4(1, 2, 1, 5);
  print('a - b: ${lanes(a - b)} (the third lane wraps)');
}
Output
a - b: [9, 18, 2147483647, -5] (the third lane wraps)
abstract final class Float64x2

Float64x2 immutable value type and operations.

Float64x2 stores 2 64-bit floating point values in "lanes". The lanes are "x" and "y" respectively.

It is a compile-time error for a class to attempt to extend or implement Float64x2.

Constructors

Float64x2factory
external factory Float64x2(double x, double y)
Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final v = Float64x2(0.1, -2.5);
  print('lanes: ${lanes(v)}');
  print('full double precision kept: ${v.x == 0.1}');
}
Output
lanes: [0.1, -2.5]
full double precision kept: true
external factory Float64x2.splat(double v)
Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('splat(3.5): ${lanes(Float64x2.splat(3.5))}');
}
Output
splat(3.5): [3.5, 3.5]
external factory Float64x2.zero()
Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final z = Float64x2.zero();
  print('zero: ${lanes(z)}');
  print('v + zero: ${lanes(Float64x2(1, 2) + z)}');
}
Output
zero: [0.0, 0.0]
v + zero: [1.0, 2.0]
external factory Float64x2.fromFloat32x4(Float32x4 v)

Uses the "x" and "y" lanes from v.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final v = Float64x2.fromFloat32x4(Float32x4(1.5, -2, 3, 4));
  print('first two lanes: ${lanes(v)}');
}
Output
first two lanes: [1.5, -2.0]

Properties

xgetter
double get x

Extracted x value.

ygetter
double get y

Extracted y value.

signMaskgetter
int get signMask

Extract the sign bits from each lane return them in the first 2 bits. "x" lane is bit 0. "y" lane is bit 1.

Methods

scalemethod
Float64x2 scale(double s)

Returns a copy of this Float64x2 each lane being scaled by s. Equivalent to this * new Float64x2.splat(s)

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('scale(4): ${lanes(Float64x2(0.25, -1).scale(4))}');
}
Output
scale(4): [1.0, -4.0]
absmethod
Float64x2 abs()

The lane-wise absolute value of this Float64x2.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('abs: ${lanes(Float64x2(-3.5, 2).abs())}');
}
Output
abs: [3.5, 2.0]
clampmethod
Float64x2 clamp(Float64x2 lowerLimit, Float64x2 upperLimit)

Lane-wise clamp this Float64x2 to be in the range lowerLimit-upperLimit.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final c = Float64x2(-1, 7).clamp(Float64x2(0, 0), Float64x2(5, 5));
  print('clamp to [0, 5]: ${lanes(c)}');
}
Output
clamp to [0, 5]: [0.0, 5.0]
withXmethod
Float64x2 withX(double x)

Returns a new Float64x2 copied from this Float64x2 with a new x value.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final v = Float64x2(1, 2);
  print('withX(9): ${lanes(v.withX(9))}, original ${lanes(v)}');
}
Output
withX(9): [9.0, 2.0], original [1.0, 2.0]
withYmethod
Float64x2 withY(double y)

Returns a new Float64x2 copied from this Float64x2 with a new y value.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final v = Float64x2(1, 2);
  print('withY(9): ${lanes(v.withY(9))}, original ${lanes(v)}');
}
Output
withY(9): [1.0, 9.0], original [1.0, 2.0]
minmethod
Float64x2 min(Float64x2 other)

The lane-wise minimum value in this Float64x2 or other.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('min: ${lanes(Float64x2(1, 8).min(Float64x2(3, 2)))}');
}
Output
min: [1.0, 2.0]
maxmethod
Float64x2 max(Float64x2 other)

The lane-wise maximum value in this Float64x2 or other.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('max: ${lanes(Float64x2(1, 8).max(Float64x2(3, 2)))}');
}
Output
max: [3.0, 8.0]
sqrtmethod
Float64x2 sqrt()

The lane-wise square root of this Float64x2.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final r = Float64x2(2, 9).sqrt();
  print('sqrt: ${lanes(r)}');
}
Output
sqrt: [1.4142135623730951, 3.0]

Operators

operator +operator
Float64x2 operator +(Float64x2 other)

Addition operator.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('(1, 2) + (0.5, 0.25): ${lanes(Float64x2(1, 2) + Float64x2(0.5, 0.25))}');
}
Output
(1, 2) + (0.5, 0.25): [1.5, 2.25]
operator -operator
Float64x2 operator -()

Negate operator.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('-(1, -2): ${lanes(-Float64x2(1, -2))}');
}
Output
-(1, -2): [-1.0, 2.0]
operator -operator
Float64x2 operator -(Float64x2 other)

Subtraction operator.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('(5, 5) - (1, 2): ${lanes(Float64x2(5, 5) - Float64x2(1, 2))}');
}
Output
(5, 5) - (1, 2): [4.0, 3.0]
operator *operator
Float64x2 operator *(Float64x2 other)

Multiplication operator.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  final p = Float64x2(3, 4) * Float64x2(3, 4);
  print('(3, 4) * (3, 4): ${lanes(p)}, sum ${p.x + p.y}');
}
Output
(3, 4) * (3, 4): [9.0, 16.0], sum 25.0
operator /operator
Float64x2 operator /(Float64x2 other)

Division operator.

Example
import 'raya:typed_data';

List<double> lanes(Float64x2 v) => [v.x, v.y];

void main() {
  print('(1, 9) / (4, 3): ${lanes(Float64x2(1, 9) / Float64x2(4, 3))}');
}
Output
(1, 9) / (4, 3): [0.25, 3.0]
abstract interface class BytesBuilder

Builds a list of bytes, allowing bytes and lists of bytes to be added at the end.

Used to efficiently collect bytes and lists of bytes.

Example
import 'raya:typed_data';

void main() {
  final bb = BytesBuilder();
  bb.add([1, 2]);
  bb.addByte(3);
  bb.add(Uint8List.fromList([4, 5]));
  print('length ${bb.length}');
  print('bytes: ${bb.takeBytes()}');
  print('after takeBytes: ${bb.length}');
}
Output
length 5
bytes: [1, 2, 3, 4, 5]
after takeBytes: 0

Constructors

factory BytesBuilder({bool copy = true})

Construct a new empty BytesBuilder.

If copy is true (the default), the created builder is a copying builder. A copying builder maintains its own internal buffer and copies the bytes added to it eagerly.

If copy set to false, the created builder assumes that lists added to it will not change. Any Uint8List added using add is kept until toBytes or takeBytes is called, and only then are their contents copied. A non-Uint8List may be copied eagerly. If only a single Uint8List is added to the builder, that list is returned by toBytes or takeBytes directly, without any copying. A list added to a non-copying builder should not change its content after being added, and it must not change its length after being added. (Normal Uint8Lists are fixed length lists, but growing lists implementing Uint8List exist.)

Example
import 'raya:typed_data';

void main() {
  final copying = BytesBuilder();
  final noCopy = BytesBuilder(copy: false);
  final chunk = Uint8List.fromList([1, 2, 3]);
  copying.add(chunk);
  noCopy.add(chunk);
  print('copy:   ${copying.toBytes()}  length ${copying.length}');
  print('noCopy: ${noCopy.toBytes()}  isEmpty ${noCopy.isEmpty}');
}
Output
copy:   [1, 2, 3]  length 3
noCopy: [1, 2, 3]  isEmpty false

Properties

lengthgetter
int get length

The number of bytes in this builder.

isEmptygetter
bool get isEmpty

Whether the buffer is empty.

bool get isNotEmpty

Whether the buffer is non-empty.

Methods

addmethod
void add(List<int> bytes)

Appends bytes to the current contents of this builder.

Each value of bytes will be truncated to an 8-bit value in the range 0.. 255.

Example
import 'raya:typed_data';

void main() {
  final b = BytesBuilder();
  b.add([0x48, 0x69]);
  b.add(' there'.codeUnits);
  b.add(Uint8List.fromList([33]));
  print('length: ${b.length}');
  print('text:   ${String.fromCharCodes(b.toBytes())}');
}
Output
length: 9
text:   Hi there!
addBytemethod
void addByte(int byte)

Appends byte to the current contents of this builder.

The byte will be truncated to an 8-bit value in the range 0.. 255.

Example
import 'raya:typed_data';

void main() {
  final b = BytesBuilder();
  for (var i = 0; i < 5; i++) {
    b.addByte(i * i);
  }
  b.addByte(257); // low 8 bits: 1
  print('bytes: ${b.toBytes()}');
}
Output
bytes: [0, 1, 4, 9, 16, 1]
takeBytesmethod
Uint8List takeBytes()

Returns the bytes currently contained in this builder and clears it.

The returned list may be a view of a larger buffer.

Example
import 'raya:typed_data';

void main() {
  final b = BytesBuilder()..add([1, 2])..add([3]);
  final taken = b.takeBytes();
  print('taken:         $taken');
  print('builder empty: ${b.isEmpty}');
  b.addByte(9);
  print('next message:  ${b.takeBytes()}');
}
Output
taken:         [1, 2, 3]
builder empty: true
next message:  [9]
toBytesmethod
Uint8List toBytes()

Returns a copy of the current byte contents of this builder.

Leaves the contents of this builder intact.

Example
import 'raya:typed_data';

void main() {
  final b = BytesBuilder()..add([10, 20]);
  final first = b.toBytes();
  b.addByte(30);
  print('snapshot:   $first');
  print('now:        ${b.toBytes()}');
  print('still full: ${b.length}');
}
Output
snapshot:   [10, 20]
now:        [10, 20, 30]
still full: 3
clearmethod
void clear()

Clears the contents of this builder.

The current contents are discarded and this builder becomes empty.

Example
import 'raya:typed_data';

void main() {
  final b = BytesBuilder()..add([1, 2, 3]);
  print('before: ${b.length}');
  b.clear();
  print('after:  ${b.length}, bytes ${b.toBytes()}');
}
Output
before: 3
after:  0, bytes []