Installations
npm install @stdlib/array-float32
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
16.20.2
NPM Version
8.19.4
Score
99.8
Supply Chain
95.5
Quality
82.9
Maintenance
100
Vulnerability
88
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
65,076,657
Last Day
83,033
Last Week
356,740
Last Month
1,579,874
Last Year
27,760,189
GitHub Statistics
1 Stars
65 Commits
3 Watching
5 Branches
11 Contributors
Bundle Size
2.24 kB
Minified
683.00 B
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
0.2.2
Package Id
@stdlib/array-float32@0.2.2
Unpacked Size
57.43 kB
Size
12.24 kB
File Count
12
NPM Version
8.19.4
Node Version
16.20.2
Publised On
27 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
65,076,657
Last day
-7%
83,033
Compared to previous day
Last week
-13.6%
356,740
Compared to previous week
Last month
11.3%
1,579,874
Compared to previous month
Last year
-2.3%
27,760,189
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
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!
Float32Array
Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.
Installation
1npm install @stdlib/array-float32
Usage
1var Float32Array = require( '@stdlib/array-float32' );
Float32Array()
A typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.
1var arr = new Float32Array(); 2// returns <Float32Array>
Float32Array( length )
Returns a typed array having a specified length.
1var arr = new Float32Array( 5 ); 2// returns <Float32Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]
Float32Array( typedarray )
Creates a typed array from another typed array.
1var Float64Array = require( '@stdlib/array-float64' ); 2 3var arr1 = new Float64Array( [ 0.5, 0.5, 0.5 ] ); 4var arr2 = new Float32Array( arr1 ); 5// returns <Float32Array>[ 0.5, 0.5, 0.5 ]
Float32Array( obj )
Creates a typed array from an array-like object
or iterable.
1var arr = new Float32Array( [ 0.5, 0.5, 0.5 ] ); 2// returns <Float32Array>[ 0.5, 0.5, 0.5 ]
Float32Array( buffer[, byteOffset[, length]] )
Returns a typed array view of an ArrayBuffer
.
1var ArrayBuffer = require( '@stdlib/array-buffer' ); 2 3var buf = new ArrayBuffer( 16 ); 4var arr = new Float32Array( buf, 0, 4 ); 5// returns <Float32Array>[ 0.0, 0.0, 0.0, 0.0 ]
Properties
Float32Array.BYTES_PER_ELEMENT
Number of bytes per view element.
1var nbytes = Float32Array.BYTES_PER_ELEMENT; 2// returns 4
Float32Array.name
Typed array constructor name.
1var str = Float32Array.name; 2// returns 'Float32Array'
Float32Array.prototype.buffer
Read-only property which returns the ArrayBuffer
referenced by the typed array.
1var arr = new Float32Array( 5 ); 2var buf = arr.buffer; 3// returns <ArrayBuffer>
Float32Array.prototype.byteLength
Read-only property which returns the length (in bytes) of the typed array.
1var arr = new Float32Array( 5 ); 2var byteLength = arr.byteLength; 3// returns 20
Float32Array.prototype.byteOffset
Read-only property which returns the offset (in bytes) of the typed array from the start of its ArrayBuffer
.
1var arr = new Float32Array( 5 ); 2var byteOffset = arr.byteOffset; 3// returns 0
Float32Array.prototype.BYTES_PER_ELEMENT
Number of bytes per view element.
1var arr = new Float32Array( 5 ); 2var nbytes = arr.BYTES_PER_ELEMENT; 3// returns 4
Float32Array.prototype.length
Read-only property which returns the number of view elements.
1var arr = new Float32Array( 5 ); 2var len = arr.length; 3// returns 5
Methods
Float32Array.from( src[, map[, thisArg]] )
Creates a new typed array from an array-like object
or an iterable.
1var arr = Float32Array.from( [ 1.0, 2.0 ] ); 2// returns <Float32Array>[ 1.0, 2.0 ]
To invoke a function for each src
value, provide a callback function.
1function mapFcn( v ) { 2 return v * 2.0; 3} 4 5var arr = Float32Array.from( [ 1.0, 2.0 ], mapFcn ); 6// returns <Float32Array>[ 2.0, 4.0 ]
A callback function is provided two arguments:
value
: source valueindex
: source index
To set the callback execution context, provide a thisArg
.
1function mapFcn( v ) { 2 this.count += 1; 3 return v * 2.0; 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr = Float32Array.from( [ 1.0, 2.0 ], mapFcn, ctx ); 11// returns <Float32Array>[ 2.0, 4.0 ] 12 13var n = ctx.count; 14// returns 2
Float32Array.of( element0[, element1[, ...elementN]] )
Creates a new typed array from a variable number of arguments.
1var arr = Float32Array.of( 1.0, 2.0 ); 2// returns <Float32Array>[ 1.0, 2.0 ]
Float32Array.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
.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); 2 3// Copy the last two elements to the first two elements: 4arr.copyWithin( 0, 3 ); 5 6var v = arr[ 0 ]; 7// returns 4.0 8 9v = arr[ 1 ]; 10// returns 5.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.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); 2 3// Copy the first two elements to the last two elements: 4arr.copyWithin( 3, 0, 2 ); 5 6var v = arr[ 3 ]; 7// returns 1.0 8 9v = arr[ 4 ]; 10// returns 2.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:
1var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); 2 3// Copy the first two elements to the last two elements: 4arr.copyWithin( -2, -5, -3 ); 5 6var v = arr[ 3 ]; 7// returns 1.0 8 9v = arr[ 4 ]; 10// returns 2.0
Float32Array.prototype.entries()
Returns an iterator for iterating over array key-value pairs.
1var arr = new Float32Array( [ 1.0, 2.0 ] ); 2 3// Create an iterator: 4var it = arr.entries(); 5 6// Iterate over key-value pairs... 7var v = it.next().value; 8// returns [ 0, 1.0 ] 9 10v = it.next().value; 11// returns [ 1, 2.0 ] 12 13var bool = it.next().done; 14// returns true
Float32Array.prototype.every( predicate[, thisArg] )
Tests whether all array elements pass a test implemented by a predicate
function.
1function predicate( v ) { 2 return ( v <= 1.0 ); 3} 4 5var arr = new Float32Array( [ 1.0, 2.0 ] ); 6 7var bool = arr.every( predicate ); 8// returns false
A predicate
function is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function predicate( v ) { 2 this.count += 1; 3 return ( v >= 1.0 ); 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr = new Float32Array( [ 1.0, 2.0 ] ); 11 12var bool = arr.every( predicate, ctx ); 13// returns true 14 15var n = ctx.count; 16// returns 2
Float32Array.prototype.fill( value[, start[, end]] )
Fills an array from a start
index to an end
index (non-inclusive) with a provided value
.
1var arr = new Float32Array( 2 ); 2 3// Set all array elements to the same value: 4arr.fill( 2.0 ); 5 6var v = arr[ 0 ]; 7// returns 2.0 8 9v = arr[ 1 ]; 10// returns 2.0 11 12// Set all array elements starting from the first index to the same value: 13arr.fill( 3.0, 1 ); 14 15v = arr[ 0 ]; 16// returns 2.0 17 18v = arr[ 1 ]; 19// returns 3.0 20 21// Set all array elements, except the last element, to the same value: 22arr.fill( 4.0, 0, arr.length-1 ); 23 24v = arr[ 0 ]; 25// returns 4.0 26 27v = arr[ 1 ]; 28// returns 3.0
When a start
and/or end
index is negative, the respective index is determined relative to the last array element.
1var arr = new Float32Array( 2 ); 2 3// Set all array elements, except the last element, to the same value: 4arr.fill( 2.0, -arr.length, -1 ); 5 6var v = arr[ 0 ]; 7// returns 2.0 8 9v = arr[ 1 ]; 10// returns 0.0
Float32Array.prototype.filter( predicate[, thisArg] )
Creates a new array (of the same data type as the host array) which includes those elements for which a predicate
function returns a truthy value.
1function predicate( v ) { 2 return ( v >= 2.0 ); 3} 4 5var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var arr2 = arr1.filter( predicate ); 8// returns <Float32Array>[ 2.0, 3.0 ]
If a predicate
function does not return a truthy value for any array element, the method returns an empty array.
1function predicate( v ) { 2 return ( v >= 10.0 ); 3} 4 5var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var arr2 = arr1.filter( predicate ); 8// returns <Float32Array>[]
A predicate
function is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function predicate( v ) { 2 this.count += 1; 3 return ( v >= 2.0 ); 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 11 12var arr2 = arr1.filter( predicate, ctx ); 13 14var n = ctx.count; 15// returns 3
Float32Array.prototype.find( predicate[, thisArg] )
Returns the first array element for which a provided predicate
function returns a truthy value.
1function predicate( v ) { 2 return ( v > 2.0 ); 3} 4 5var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var v = arr.find( predicate ); 8// returns 3.0
If a predicate
function does not return a truthy value for any array element, the method returns undefined
.
1function predicate( v ) { 2 return ( v < 1.0 ); 3} 4 5var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var v = arr.find( predicate ); 8// returns undefined
A predicate
function is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function predicate( v ) { 2 this.count += 1; 3 return ( v > 2.0 ); 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 11 12var v = arr.find( predicate, ctx ); 13// returns 3.0 14 15var n = ctx.count; 16// returns 3
Float32Array.prototype.findIndex( predicate[, thisArg] )
Returns the index of the first array element for which a provided predicate
function returns a truthy value.
1function predicate( v ) { 2 return ( v >= 3.0 ); 3} 4 5var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var idx = arr.findIndex( predicate ); 8// returns 2
If a predicate
function does not return a truthy value for any array element, the method returns -1
.
1function predicate( v ) { 2 return ( v < 1.0 ); 3} 4 5var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var idx = arr.findIndex( predicate ); 8// returns -1
A predicate
function is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function predicate( v ) { 2 this.count += 1; 3 return ( v >= 3.0 ); 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 11 12var idx = arr.findIndex( predicate, ctx ); 13// returns 2 14 15var n = ctx.count; 16// returns 3
Float32Array.prototype.forEach( fcn[, thisArg] )
Invokes a callback for each array element.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var str = ''; 4 5function fcn( v, i ) { 6 str += i + ':' + v; 7 if ( i < arr.length-1 ) { 8 str += ' '; 9 } 10} 11 12arr.forEach( fcn ); 13 14console.log( str ); 15// => '0:1 1:2 2:3'
The callback is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function fcn() { 2 this.count += 1; 3} 4 5var ctx = { 6 'count': 0 7}; 8 9var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 10 11arr.forEach( fcn, ctx ); 12 13var n = ctx.count; 14// returns 3
Float32Array.prototype.includes( searchElement[, fromIndex] )
Returns a boolean
indicating whether an array includes a search element.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var bool = arr.includes( 3.0 ); 4// returns true 5 6bool = arr.includes( 0.0 ); 7// returns false
By default, the method searches the entire array (fromIndex = 0
). To begin searching from a specific array index, provide a fromIndex
.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var bool = arr.includes( 1.0, 1 ); 4// returns false
When a fromIndex
is negative, the starting index is resolved relative to the last array element.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var bool = arr.includes( 1.0, -2 ); 4// returns false
The method does not distinguish between signed and unsigned zero.
Float32Array.prototype.indexOf( searchElement[, fromIndex] )
Returns the index of the first array element strictly equal to a search element.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var idx = arr.indexOf( 3.0 ); 4// returns 2 5 6idx = arr.indexOf( 0.0 ); 7// returns -1
By default, the method searches the entire array (fromIndex = 0
). To begin searching from a specific array index, provide a fromIndex
.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var idx = arr.indexOf( 1.0, 1 ); 4// returns -1
When a fromIndex
is negative, the starting index is resolved relative to the last array element.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var idx = arr.indexOf( 1.0, -2 ); 4// returns -1
The method does not distinguish between signed and unsigned zero.
Float32Array.prototype.join( [separator] )
Serializes an array by joining all array elements as a string.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var str = arr.join(); 4// returns '1,2,3'
By default, the method delineates array elements using a comma ,
. To specify a custom separator, provide a separator
string.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var str = arr.join( '|' ); 4// returns '1|2|3'
Float32Array.prototype.keys()
Returns an iterator for iterating over array keys.
1var arr = new Float32Array( [ 1.0, 2.0 ] ); 2 3// Create an iterator: 4var it = arr.keys(); 5 6// Iterate over keys... 7var v = it.next().value; 8// returns 0 9 10v = it.next().value; 11// returns 1 12 13var bool = it.next().done; 14// returns true
Float32Array.prototype.lastIndexOf( searchElement[, fromIndex] )
Returns the index of the last array element strictly equal to a search element, iterating from right to left.
1var arr = new Float32Array( [ 1.0, 0.0, 2.0, 0.0, 1.0 ] ); 2 3var idx = arr.lastIndexOf( 0.0 ); 4// returns 3 5 6idx = arr.lastIndexOf( 3.0 ); 7// returns -1
By default, the method searches the entire array (fromIndex = -1
). To begin searching from a specific array index, provide a fromIndex
.
1var arr = new Float32Array( [ 1.0, 0.0, 2.0, 0.0, 1.0 ] ); 2 3var idx = arr.lastIndexOf( 0.0, 2 ); 4// returns 1
When a fromIndex
is negative, the starting index is resolved relative to the last array element.
1var arr = new Float32Array( [ 1.0, 0.0, 2.0, 0.0, 1.0 ] ); 2 3var idx = arr.lastIndexOf( 0.0, -3 ); 4// returns 1
The method does not distinguish between signed and unsigned zero.
Float32Array.prototype.map( fcn[, thisArg] )
Maps each array element to an element in a new array having the same data type as the host array.
1function fcn( v ) { 2 return v * 2.0; 3} 4 5var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 6 7var arr2 = arr1.map( fcn ); 8// returns <Float32Array>[ 2.0, 4.0, 6.0 ]
A callback is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function fcn( v ) { 2 this.count += 1; 3 return v * 2.0; 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 11 12var arr2 = arr1.map( fcn, ctx ); 13 14var n = ctx.count; 15// returns 3
Float32Array.prototype.reduce( fcn[, initialValue] )
Applies a function against an accumulator and each element in an array and returns the accumulated result.
1function fcn( acc, v ) { 2 return acc + ( v*v ); 3} 4 5var arr = new Float32Array( [ 2.0, 1.0, 3.0 ] ); 6 7var v = arr.reduce( fcn ); 8// returns 12.0
If not provided an initial value, the method invokes a provided function with the first array element as the first argument and the second array element as the second argument.
If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first array element as the second argument.
1function fcn( acc, v ) { 2 return acc + ( v*v ); 3} 4 5var arr = new Float32Array( [ 2.0, 1.0, 3.0 ] ); 6 7var v = arr.reduce( fcn, 0.0 ); 8// returns 14.0
A callback is provided four arguments:
acc
: accumulated resultvalue
: array elementindex
: array indexarr
: array on which the method is invoked
Float32Array.prototype.reduceRight( fcn[, initialValue] )
Applies a function against an accumulator and each element in an array and returns the accumulated result, iterating from right to left.
1function fcn( acc, v ) { 2 return acc + ( v*v ); 3} 4 5var arr = new Float32Array( [ 2.0, 1.0, 3.0 ] ); 6 7var v = arr.reduceRight( fcn ); 8// returns 8.0
If not provided an initial value, the method invokes a provided function with the last array element as the first argument and the second-to-last array element as the second argument.
If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last array element as the second argument.
1function fcn( acc, v ) { 2 return acc + ( v*v ); 3} 4 5var arr = new Float32Array( [ 2.0, 1.0, 3.0 ] ); 6 7var v = arr.reduce( fcn, 0.0 ); 8// returns 14.0
A callback is provided four arguments:
acc
: accumulated resultvalue
: array elementindex
: array indexarr
: array on which the method is invoked
Float32Array.prototype.reverse()
Reverses an array in-place (thus mutating the array on which the method is invoked).
1var arr = new Float32Array( [ 2.0, 0.0, 3.0 ] ); 2 3// Reverse the array: 4arr.reverse(); 5 6var v = arr[ 0 ]; 7// returns 3.0 8 9v = arr[ 1 ]; 10// returns 0.0 11 12v = arr[ 2 ]; 13// returns 2.0
Float32Array.prototype.set( arr[, offset] )
Sets array elements.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2// returns <Float32Array>[ 1.0, 2.0, 3.0 ] 3 4// Set the first two array elements: 5arr.set( [ 4.0, 5.0 ] ); 6 7var v = arr[ 0 ]; 8// returns 4.0 9 10v = arr[ 1 ]; 11// returns 5.0
By default, the method starts writing values at the first array index. To specify an alternative index, provide an index offset
.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2// returns <Float32Array>[ 1.0, 2.0, 3.0 ] 3 4// Set the last two array elements: 5arr.set( [ 4.0, 5.0 ], 1 ); 6 7var v = arr[ 1 ]; 8// returns 4.0 9 10v = arr[ 2 ]; 11// returns 5.0
Float32Array.prototype.slice( [begin[, end]] )
Copies array elements to a new array with the same underlying data type as the host array.
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.slice(); 4 5var bool = ( arr1 === arr2 ); 6// returns false 7 8bool = ( arr1.buffer === arr2.buffer ); 9// returns false 10 11var v = arr2[ 0 ]; 12// returns 1.0 13 14v = arr2[ 1 ]; 15// returns 2.0 16 17v = arr2[ 2 ]; 18// returns 3.0
By default, the method copies elements beginning with the first array element. To specify an alternative array index at which to begin copying, provide a begin
index (inclusive).
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.slice( 1 ); 4 5var len = arr2.length; 6// returns 2 7 8var v = arr2[ 0 ]; 9// returns 2.0 10 11v = arr2[ 1 ]; 12// returns 3.0
By default, the method copies all array elements after begin
. To specify an alternative array index at which to end copying, provide an end
index (exclusive).
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.slice( 0, 2 ); 4 5var len = arr2.length; 6// returns 2 7 8var v = arr2[ 0 ]; 9// returns 1.0 10 11v = arr2[ 1 ]; 12// returns 2.0
When a begin
and/or end
index is negative, the respective index is determined relative to the last array element.
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.slice( -arr1.length, -1 ); 4 5var len = arr2.length; 6// returns 2 7 8var v = arr2[ 0 ]; 9// returns 1.0 10 11v = arr2[ 1 ]; 12// returns 2.0
Float32Array.prototype.some( predicate[, thisArg] )
Tests whether at least one array element passes a test implemented by a predicate
function.
1function predicate( v ) { 2 return ( v >= 2.0 ); 3} 4 5var arr = new Float32Array( [ 1.0, 2.0 ] ); 6 7var bool = arr.some( predicate ); 8// returns true
A predicate
function is provided three arguments:
value
: array elementindex
: array indexarr
: array on which the method is invoked
To set the callback execution context, provide a thisArg
.
1function predicate( v ) { 2 this.count += 1; 3 return ( v >= 2.0 ); 4} 5 6var ctx = { 7 'count': 0 8}; 9 10var arr = new Float32Array( [ 1.0, 1.0 ] ); 11 12var bool = arr.some( predicate, ctx ); 13// returns false 14 15var n = ctx.count; 16// returns 2
Float32Array.prototype.sort( [compareFunction] )
Sorts an array in-place (thus mutating the array on which the method is invoked).
1var arr = new Float32Array( [ 2.0, 3.0, 0.0 ] ); 2 3// Sort the array (in ascending order): 4arr.sort(); 5 6var v = arr[ 0 ]; 7// returns 0.0 8 9v = arr[ 1 ]; 10// returns 2.0 11 12v = arr[ 2 ]; 13// returns 3.0
By default, the method sorts array elements in ascending order. To impose a custom order, provide a compareFunction
.
1function descending( a, b ) { 2 return b - a; 3} 4 5var arr = new Float32Array( [ 2.0, 3.0, 0.0 ] ); 6 7// Sort the array (in descending order): 8arr.sort( descending ); 9 10var v = arr[ 0 ]; 11// returns 3.0 12 13v = arr[ 1 ]; 14// returns 2.0 15 16v = arr[ 2 ]; 17// returns 0.0
The comparison function is provided two array elements, a
and b
, per invocation, and its return value determines the sort order as follows:
- If the comparison function returns a value less than zero, then the method sorts
a
to an index lower thanb
(i.e.,a
should come beforeb
). - If the comparison function returns a value greater than zero, then the method sorts
a
to an index higher thanb
(i.e.,b
should come beforea
). - If the comparison function returns zero, then the relative order of
a
andb
should remain unchanged.
Float32Array.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.
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.subarray(); 4// returns <Float32Array>[ 1.0, 2.0, 3.0 ] 5 6var bool = ( arr1.buffer === arr2.buffer ); 7// returns true
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).
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.subarray( 1 ); 4// returns <Float32Array>[ 2.0, 3.0 ] 5 6var bool = ( arr1.buffer === arr2.buffer ); 7// returns true
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).
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.subarray( 0, 2 ); 4// returns <Float32Array>[ 1.0, 2.0 ] 5 6var bool = ( arr1.buffer === arr2.buffer ); 7// returns true
When a begin
and/or end
index is negative, the respective index is determined relative to the last array element.
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.subarray( -arr1.length, -1 ); 4// returns <Float32Array>[ 1.0, 2.0 ] 5 6var bool = ( arr1.buffer === arr2.buffer ); 7// returns true
If the method is unable to resolve indices to a non-empty array subsequence, the method returns an empty typed array.
1var arr1 = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var arr2 = arr1.subarray( 10, -1 ); 4// returns <Float32Array>[]
Float32Array.prototype.toLocaleString( [locales[, options]] )
Serializes an array as a locale-specific string
.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var str = arr.toLocaleString(); 4// returns '1,2,3'
Float32Array.prototype.toString()
Serializes an array as a string
.
1var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); 2 3var str = arr.toString(); 4// returns '1,2,3'
Float32Array.prototype.values()
Returns an iterator for iterating over array elements.
1var arr = new Float32Array( [ 1.0, 2.0 ] ); 2 3// Create an iterator: 4var it = arr.values(); 5 6// Iterate over array elements... 7var v = it.next().value; 8// returns 1.0 9 10v = it.next().value; 11// returns 2.0 12 13var bool = it.next().done; 14// returns true
Examples
1var randu = require( '@stdlib/random-base-randu' ); 2var ctor = require( '@stdlib/array-float32' ); 3 4var arr; 5var i; 6 7arr = new ctor( 10 ); 8for ( i = 0; i < arr.length; i++ ) { 9 arr[ i ] = randu() * 100.0; 10} 11console.log( arr );
See Also
@stdlib/array-buffer
: ArrayBuffer.@stdlib/array-float64
: Float64Array.@stdlib/array-int16
: Int16Array.@stdlib/array-int32
: Int32Array.@stdlib/array-int8
: Int8Array.@stdlib/array-uint16
: Uint16Array.@stdlib/array-uint32
: Uint32Array.@stdlib/array-uint8
: Uint8Array.@stdlib/array-uint8c
: Uint8ClampedArray.
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
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/array-float32/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:275: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/array-float32/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:449: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/array-float32/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:457: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/array-float32/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:623: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/array-float32/productionize.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:165
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:83
- Warn: npmCommand not pinned by hash: .github/workflows/test_bundles.yml:72
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:74
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_published_package.yml:93
- Info: 33 out of 33 GitHub-owned GitHubAction dependencies pinned
- Info: 19 out of 24 third-party GitHubAction dependencies pinned
- Info: 0 out of 32 npmCommand dependencies pinned
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/cancel.yml:1
- Warn: no topLevel permission defined: .github/workflows/close_pull_requests.yml:1
- Warn: no topLevel permission defined: .github/workflows/examples.yml:1
- Warn: no topLevel permission defined: .github/workflows/npm_downloads.yml:1
- Warn: no topLevel permission defined: .github/workflows/productionize.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_bundles.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_coverage.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_install.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_published_package.yml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
4.4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @stdlib/array-float32
@stdlib/assert-is-float32array
Test if a value is a Float32Array.
@stdlib/strided-base-reinterpret-complex64
Reinterpret a Complex64Array as a Float32Array.
@stdlib/array-zeros
Create a zero-filled array having a specified length.
@stdlib/array-empty
Create an uninitialized array having a specified length.