Skip to content
About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

Float16Array

NPM versionBuild StatusCoverage Status

16-bit half-precision floating-point number array.

Installation

npm install @stdlib/array-float16

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (see README).

The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.

To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

Usage

varFloat16Array=require('@stdlib/array-float16');

Float16Array()

Creates a 16-bit half-precision floating-point number array.

vararr=newFloat16Array();// returns <Float16Array>

Float16Array( length )

Creates a 16-bit half-precision floating-point number array having a specified length.

vararr=newFloat16Array(5);// returns <Float16Array>varlen=arr.length;// returns 5

Float16Array( typedarray )

Creates a 16-bit half-precision floating-point number array from a typed array.

varFloat64Array=require('@stdlib/array-float64');varbuf=newFloat64Array([0.5,0.5,0.5]);// returns <Float64Array>vararr=newFloat16Array(buf);// returns <Float16Array>varlen=arr.length;// returns 3

Float16Array( obj )

Creates a 16-bit half-precision floating-point number array from an array-like object or iterable.

vararr=newFloat16Array([0.5,0.5,0.5]);// returns <Float16Array>varlen=arr.length;// returns 3

Float16Array( buffer[, byteOffset[, length]] )

Returns a 16-bit half-precision floating-point number array view of an ArrayBuffer.

varArrayBuffer=require('@stdlib/array-buffer');varbuf=newArrayBuffer(8);vararr=newFloat16Array(buf);// returns <Float16Array>varlen=arr.length;// returns 4arr=newFloat16Array(buf,2);// returns <Float16Array>len=arr.length;// returns 3arr=newFloat16Array(buf,2,2);// returns <Float16Array>len=arr.length;// returns 2

Properties

Float16Array.BYTES_PER_ELEMENT

Static property returning the size (in bytes) of each array element.

varnbytes=Float16Array.BYTES_PER_ELEMENT;// returns 2

Float16Array.name

Static property returning the constructor name.

varstr=Float16Array.name;// returns 'Float16Array'

Float16Array.prototype.buffer

Pointer to the underlying data buffer.

vararr=newFloat16Array(5);// returns <Float16Array>varbuf=arr.buffer;// returns <ArrayBuffer>

Float16Array.prototype.byteLength

Size (in bytes) of the array.

vararr=newFloat16Array(5);// returns <Float16Array>varbyteLength=arr.byteLength;// returns 10

Float16Array.prototype.byteOffset

Offset (in bytes) of the array from the start of its underlying ArrayBuffer.

varArrayBuffer=require('@stdlib/array-buffer');vararr=newFloat16Array(5);// returns <Float16Array>varoffset=arr.byteOffset;// returns 0varbuf=newArrayBuffer(20);arr=newFloat16Array(buf,10);// returns <Float16Array>offset=arr.byteOffset;// returns 10

Float16Array.prototype.BYTES_PER_ELEMENT

Size (in bytes) of each array element.

vararr=newFloat16Array(5);// returns <Float16Array>varnbytes=arr.BYTES_PER_ELEMENT;// returns 2

Float16Array.prototype.length

Number of array elements.

vararr=newFloat16Array(5);// returns <Float16Array>varlen=arr.length;// returns 5

Methods

Float16Array.from( src[, clbk[, thisArg]] )

Creates a new 16-bit half-precision floating-point number array from an array-like object or an iterable.

vararr=Float16Array.from([1.0,2.0]);// returns <Float16Array>varv=arr[0];// returns 1.0v=arr[1];// returns 2.0varlen=arr.length;// returns 2

To invoke a function for each src value, provide a callback function.

vararr=Float16Array.from([1.0,2.0],clbk);// returns <Float16Array>varv=arr[0];// returns 2.0v=arr[1];// returns 4.0varlen=arr.length;// returns 2functionclbk(v){returnv*2.0;}

A callback function is provided two arguments:

  • value: source value.
  • index: source index.

To set the callback execution context, provide a thisArg.

functionmap(v){this.count+=1;returnv*2.0;}varctx={'count': 0};vararr=Float16Array.from([1.0,2.0],map,ctx);// returns <Float16Array>varv=arr[0];// returns 2.0v=arr[1];// returns 4.0varn=ctx.count;// returns 2

Float16Array.of( element0[, element1[, ...elementN]] )

Creates a new 16-bit half-precision floating-point number array from a variable number of arguments.

vararr=Float16Array.of(1.0,2.0);// returns <Float16Array>varv=arr[0];// returns 1.0v=arr[1];// returns 2.0

Float16Array.prototype.at( i )

Returns an array element located at integer position (index) i, with support for both nonnegative and negative integer positions.

vararr=newFloat16Array([10.0,20.0,30.0]);varv=arr.at(0);// returns 10.0v=arr.at(-1);// returns 30.0

If provided an out-of-bounds index, the method returns undefined.

vararr=newFloat16Array(10);varv=arr.at(100);// returns undefinedv=arr.at(-100);// returns undefined

Float16Array.prototype.copyWithin( target, start[, end] )

Copies a sequence of elements within an array starting at start and ending at end (non-inclusive) to the position starting at target.

vararr=newFloat16Array([1.0,2.0,3.0,4.0,5.0]);// Copy the last two elements to the first two elements:arr.copyWithin(0,3);varv=arr[0];// returns 4.0v=arr[1];// returns 5.0v=arr[2];// returns 3.0

By default, end equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an end argument.

vararr=newFloat16Array([1.0,2.0,3.0,4.0,5.0]);// Copy the first two elements to the last two elements:arr.copyWithin(3,0,2);varv=arr[3];// returns 1.0v=arr[4];// returns 2.0v=arr[0];// returns 1.0

When a target, start, and/or end index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example:

vararr=newFloat16Array([1.0,2.0,3.0,4.0,5.0]);// Copy the first two elements to the last two elements:arr.copyWithin(-2,-5,-3);varv=arr[3];// returns 1.0v=arr[4];// returns 2.0v=arr[0];// returns 1.0

Float16Array.prototype.entries()

Returns an iterator for iterating over array key-value pairs.

vararr=newFloat16Array([1.0,2.0]);// Create an iterator:varit=arr.entries();// Iterate over key-value pairs...varv=it.next().value;// returns [ 0, 1.0 ]v=it.next().value;// returns [ 1, 2.0 ]varbool=it.next().done;// returns true

The returned iterator protocol-compliant object has the following properties:

  • next: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a value property and a done property having a boolean value indicating whether the iterator is finished.
  • return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.

Float16Array.prototype.every( predicate[, thisArg] )

Returns a boolean indicating whether all elements pass a test.

functionpredicate(v){return(v<0.0);}vararr=newFloat16Array([1.0,2.0]);varbool=arr.every(predicate);// returns falsearr=newFloat16Array([-1.0,-2.0]);bool=arr.every(predicate);// returns true

A predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the callback execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>0.0);}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0]);varbool=arr.every(predicate,ctx);// returns truevarn=ctx.count;// returns 2

Float16Array.prototype.fill( value[, start[, end]] )

Returns a modified typed array filled with a fill value.

vararr=newFloat16Array(2);// Set all array elements to the same value:arr.fill(2.0);varv=arr[0];// returns 2.0v=arr[1];// returns 2.0// Set all array elements starting from the first index to the same value:arr.fill(3.0,1);v=arr[0];// returns 2.0v=arr[1];// returns 3.0// Set all array elements, except the last element, to the same value:arr.fill(4.0,0,arr.length-1);v=arr[0];// returns 4.0v=arr[1];// returns 3.0

When a start and/or end index is negative, the respective index is determined relative to the last array element.

vararr=newFloat16Array(2);// Set all array elements, except the last element, to the same value:arr.fill(2.0,-arr.length,-1);varv=arr[0];// returns 2.0v=arr[1];// returns 0.0

Float16Array.prototype.filter( predicate[, thisArg] )

Returns a new array containing the elements of an array which pass a test implemented by a predicate function.

functionpredicate(v){return(v>1.0);}vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.filter(predicate);// returns <Float16Array>varv=out[0];// returns 2.0v=out[1];// returns 3.0

The predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>1.0);}varctx={'count': 0};vararr=newFloat16Array([2.0,3.0]);varout=arr.filter(predicate,ctx);// returns <Float16Array>varv=out[0];// returns 2.0v=out[1];// returns 3.0varn=ctx.count;// returns 2

Float16Array.prototype.find( predicate[, thisArg] )

Returns the first element in an array for which a predicate function returns a truthy value.

functionpredicate(v){return(v>1.0);}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.find(predicate);// returns 2.0

A predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the callback execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>1.0);}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.find(predicate,ctx);// returns 2.0varn=ctx.count;// returns 2

Float16Array.prototype.findIndex( predicate[, thisArg] )

Returns the index of the first element in an array for which a predicate function returns a truthy value.

functionpredicate(v){return(v>2.0);}vararr=newFloat16Array([1.0,2.0,3.0]);varidx=arr.findIndex(predicate);// returns 2

The predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>3.0);}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0,3.0]);varidx=arr.findIndex(predicate,ctx);// returns -1varn=ctx.count;// returns 3

Float16Array.prototype.findLast( predicate[, thisArg] )

Returns the last element in an array for which a predicate function returns a truthy value.

functionpredicate(v){returnv>2.0;}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.findLast(predicate);// returns 3.0

The predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>2.0);}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.findLast(predicate,ctx);// returns 3.0varcount=ctx.count;// returns 1

Float16Array.prototype.findLastIndex( predicate[, thisArg] )

Returns the index of the last element in an array for which a predicate function returns a truthy value.

functionpredicate(v){returnv>2.0;}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.findLastIndex(predicate);// returns 2

The predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>2.0);}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.findLastIndex(predicate,ctx);// returns 2varcount=ctx.count;// returns 1

Float16Array.prototype.forEach( callbackFn[, thisArg] )

Invokes a callback for each array element.

functionlog(v,i){console.log('%s: %s',i,v.toString());}vararr=newFloat16Array([1.0,2.0,3.0]);arr.forEach(log);/* => 0: 1 1: 2 2: 3*/

The invoked function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionlog(v,i){this.count+=1;console.log('%s: %s',i,v.toString());}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0,3.0]);arr.forEach(log,ctx);/* => 0: 1 1: 2 2: 3*/varcount=ctx.count;// returns 3

Float16Array.prototype.includes( searchElement[, fromIndex] )

Returns a boolean indicating whether an array includes a provided value.

vararr=newFloat16Array([1.0,2.0,3.0]);varbool=arr.includes(3.0);// returns truebool=arr.includes(0.0);// returns false

Float16Array.prototype.indexOf( searchElement[, fromIndex] )

Returns the first index at which a given element can be found.

vararr=newFloat16Array([1.0,2.0,3.0]);varidx=arr.indexOf(2.0);// returns 1idx=arr.indexOf(3.0);// returns 2

If searchElement is not present in the array, the method returns -1.

vararr=newFloat16Array([1.0,2.0,3.0]);varidx=arr.indexOf(4.0);// returns -1

Float16Array.prototype.join( [separator] )

Returns a new string by concatenating all array elements.

vararr=newFloat16Array([1.0,2.0,3.0]);varstr=arr.join();// returns '1,2,3'

By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a separator string.

vararr=newFloat16Array([1.0,2.0,3.0]);varstr=arr.join('|');// returns '1|2|3'

Float16Array.prototype.keys()

Returns an iterator for iterating over each index key in a typed array.

vararr=newFloat16Array([1.0,2.0]);varit=arr.keys();varv=it.next().value;// returns 0v=it.next().value;// returns 1varbool=it.next().done;// returns true

The returned iterator protocol-compliant object has the following properties:

  • next: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a value property and a done property having a boolean value indicating whether the iterator is finished.
  • return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.

Float16Array.prototype.lastIndexOf( searchElement[, fromIndex] )

Returns the last index at which a given element can be found.

vararr=newFloat16Array([1.0,2.0,3.0,4.0,2.0]);varidx=arr.lastIndexOf(3.0);// returns 2idx=arr.lastIndexOf(2.0);// returns 4idx=arr.lastIndexOf(2.0,2);// returns 1

If searchElement is not present in the array, the method returns -1.

vararr=newFloat16Array([1.0,2.0]);varidx=arr.lastIndexOf(3.0);// returns -1idx=arr.lastIndexOf(2.0,0);// returns -1

Float16Array.prototype.map( callbackFn[, thisArg] )

Returns a new array with each element being the result of a provided callback function.

functionscale(v){returnv*2.0;}vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.map(scale);// returns <Float16Array>varv=out[0];// returns 2.0v=out[1];// returns 4.0v=out[2];// returns 6.0

The callback function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionscale(v){this.count+=1;returnv*2.0;}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.map(scale,ctx);// returns <Float16Array>varv=out[0];// returns 2.0v=out[1];// returns 4.0v=out[2];// returns 6.0varcount=ctx.count;// returns 3

Float16Array.prototype.reduce( reducerFn[, initialValue] )

Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.

functionfcn(acc,v){returnacc+(v*v);}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.reduce(fcn);// returns 14.0

The reducer function is provided four arguments:

  • acc: accumulated result.
  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

By default, the function initializes the accumulated result to the first element in the array and passes the second array element as value during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as value during the first invocation of the provided callback, provide an initialValue argument.

functionfcn(acc,v){returnacc+(v*v);}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.reduce(fcn,0.0);// returns 14.0

Float16Array.prototype.reduceRight( reducerFn[, initialValue] )

Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion.

functionfcn(acc,v){returnacc+(v*v);}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.reduceRight(fcn);// returns 8.0

The reducer function is provided four arguments:

  • acc: accumulated result.
  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

By default, the function initializes the accumulated result to the last element in the array and passes the second-last array element as value during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element as value during the first invocation of the provided callback, provide an initialValue argument.

functionfcn(acc,v){returnacc+(v*v);}vararr=newFloat16Array([1.0,2.0,3.0]);varv=arr.reduceRight(fcn,0.0);// returns 14.0

Float16Array.prototype.reverse()

Reverses an array in-place.

vararr=newFloat16Array([1.0,2.0,3.0]);// Reverse the array:arr.reverse();varv=arr[0];// returns 3.0v=arr[1];// returns 2.0v=arr[2];// returns 1.0

Float16Array.prototype.set( arr[, offset] )

Sets one or more array elements.

vararr=newFloat16Array([1.0,2.0,3.0]);// returns <Float16Array>arr.set([4.0,5.0]);varv=arr[0];// returns 4.0v=arr[1];// returns 5.0v=arr[2];// returns 3.0

By default, the method sets array elements starting at position (index) i = 0. To set elements starting elsewhere in the array, provide an index argument i.

vararr=newFloat16Array([1.0,2.0,3.0]);// returns <Float16Array>// Set the last two array elements:arr.set([4.0,5.0],1);varv=arr[1];// returns 4.0v=arr[2];// returns 5.0

A few notes:

  • If i is out-of-bounds, the method throws an error.
  • If a target array cannot accommodate all values (i.e., the length of source array plus i exceeds the target array length), the method throws an error.
  • If provided a typed array which shares an ArrayBuffer with the target array, the method will intelligently copy the source range to the destination range.

Float16Array.prototype.slice( [begin[, end]] )

Copies a portion of a typed array to a new typed array.

vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.slice();varlen=out.length;// returns 3varv=out[0];// returns 1.0v=out[1];// returns 2.0v=out[2];// returns 3.0

By default, the method returns a typed array beginning with the first array element. To specify an alternative array index at which to begin, provide a start index (inclusive).

vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.slice(1);varlen=out.length;// returns 2varv=out[0];// returns 2.0v=out[1];// returns 3.0

By default, the method returns a typed array which includes all array elements after start. To limit the number of array elements after start, provide an end index (exclusive).

vararr=newFloat16Array([1.0,2.0,3.0,4.0]);varout=arr.slice(1,-1);varlen=out.length;// returns 2varv=out[0];// returns 2.0v=out[1];// returns 3.0

Float16Array.prototype.some( predicate[, thisArg] )

Returns a boolean indicating whether at least one element passes a test.

functionpredicate(v){return(v>2.0);}vararr=newFloat16Array([1.0,2.0,3.0]);varbool=arr.some(predicate);// returns true

The predicate function is provided three arguments:

  • value: current array element.
  • index: current array element index.
  • arr: the array on which this method was called.

To set the function execution context, provide a thisArg.

functionpredicate(v){this.count+=1;return(v>2.0);}varctx={'count': 0};vararr=newFloat16Array([1.0,2.0]);varbool=arr.some(predicate,ctx);// returns falsevarn=ctx.count;// returns 2

Float16Array.prototype.sort( [compareFcn] )

Sorts an array in-place.

functioncompare(a,b){if(a<b){return-1;}if(a>b){return1;}return0;}vararr=newFloat16Array([2.0,3.0,1.0]);arr.sort(compare);varv=arr[0];// returns 1.0v=arr[1];// returns 2.0v=arr[2];// returns 3.0

The compareFcn determines the order of the elements. The function is called with the following arguments:

  • a: the first element for comparison.
  • b: the second element for comparison.

The function should return a number where:

  • a negative value indicates that a should come before b.
  • a positive value indicates that a should come after b.
  • zero or NaN indicates that a and b are considered equal.

Float16Array.prototype.subarray( [begin[, end]] )

Creates a new typed array view over the same underlying ArrayBuffer and with the same underlying data type as the host array.

vararr=newFloat16Array([1.0,2.0,3.0]);varsubarr=arr.subarray();// returns <Float16Array>varv=subarr[0];// returns 1.0v=subarr[1];// returns 2.0v=subarr[2];// returns 3.0varlen=subarr.length;// returns 3

By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a begin index (inclusive).

vararr=newFloat16Array([1.0,2.0,3.0]);varsubarr=arr.subarray(1);// returns <Float16Array>varv=subarr[0];// returns 2.0v=subarr[1];// returns 3.0varlen=subarr.length;// returns 2

By default, the method creates a typed array view which includes all array elements after begin. To limit the number of array elements after begin, provide an end index (exclusive).

vararr=newFloat16Array([1.0,2.0,3.0,4.0]);varsubarr=arr.subarray(1,-1);// returns <Float16Array>varv=subarr[0];// returns 2.0v=subarr[1];// returns 3.0varlen=subarr.length;// returns 2

Float16Array.prototype.toLocaleString( [locales[, options]] )

Serializes an array as a locale-specific string.

vararr=newFloat16Array([1.0,2.0,3.0]);varstr=arr.toLocaleString();// returns '1,2,3'

The method supports the following arguments:

  • locales: a string with a BCP 47 language tag or an array of such strings.
  • options: configuration properties.

Float16Array.prototype.toReversed()

Returns a new typed array containing the elements in reversed order.

vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.toReversed();// returns <Float16Array>varv=out[0];// returns 3.0v=out[1];// returns 2.0v=out[2];// returns 1.0

Float16Array.prototype.toSorted( [compareFcn] )

Returns a new typed array containing the elements in sorted order.

functioncompare(a,b){if(a<b){return-1;}if(a>b){return1;}return0;}vararr=newFloat16Array([2.0,3.0,1.0]);varout=arr.toSorted(compare);// returns <Float16Array>varv=out[0];// returns 1.0v=out[1];// returns 2.0v=out[2];// returns 3.0

The compareFcn determines the order of the elements. The function is called with the following arguments:

  • a: the first element for comparison.
  • b: the second element for comparison.

The function should return a number where:

  • a negative value indicates that a should come before b.
  • a positive value indicates that a should come after b.
  • zero or NaN indicates that a and b are considered equal.

Float16Array.prototype.toString()

Serializes an array as a string.

vararr=newFloat16Array([1.0,2.0,3.0]);varstr=arr.toString();// returns '1,2,3'

Float16Array.prototype.values()

Returns an iterator for iterating over each value in a typed array.

vararr=newFloat16Array([1.0,2.0]);varit=arr.values();varv=it.next().value;// returns 1.0v=it.next().value;// returns 2.0varbool=it.next().done;// returns true

The returned iterator protocol-compliant object has the following properties:

  • next: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a value property and a done property having a boolean value indicating whether the iterator is finished.
  • return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.

Float16Array.prototype.with( index, value )

Returns a new typed array with the element at a provided index replaced with a provided value.

vararr=newFloat16Array([1.0,2.0,3.0]);varout=arr.with(0,0.0);// returns <Float16Array>varv=out[0];// returns 0.0

Examples

varUint16Array=require('@stdlib/array-uint16');varlogEach=require('@stdlib/console-log-each');varFloat16Array=require('@stdlib/array-float16');// Create a half-precision floating-point number array by specifying a length:varout=newFloat16Array(3);logEach('%s',out);// Create a half-precision floating-point number array from an array of numbers:vararr=[1.05,2.05,3.05];out=newFloat16Array(arr);logEach('%s',out);// Create a half-precision floating-point number array from an array buffer:arr=newUint16Array([1000,2000,3000,4000]);out=newFloat16Array(arr.buffer);logEach('%s',out);// Create a half-precision floating-point number array from an array buffer view:arr=newUint16Array([1000,2000,3000,4000]);out=newFloat16Array(arr.buffer,2,2);logEach('%s',out);

See Also


Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.