Gathering detailed insights and metrics for @stdlib/array-complex128
Gathering detailed insights and metrics for @stdlib/array-complex128
Gathering detailed insights and metrics for @stdlib/array-complex128
Gathering detailed insights and metrics for @stdlib/array-complex128
@stdlib/strided-base-reinterpret-complex128
Reinterpret a Complex128Array as a Float64Array.
@stdlib/array-zeros
Create a zero-filled array having a specified length.
@stdlib/array-empty
Create an uninitialized array having a specified length.
@stdlib/array-full
Create a filled array having a specified length.
npm install @stdlib/array-complex128
Typescript
Module System
Min. Node Version
Node Version
NPM Version
90.3
Supply Chain
85.4
Quality
81.5
Maintenance
100
Vulnerability
87.6
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
1 Stars
127 Commits
3 Watchers
5 Branches
13 Contributors
Updated on Mar 31, 2025
Minified
Minified + Gzipped
Latest Version
0.3.0
Package Id
@stdlib/array-complex128@0.3.0
Unpacked Size
352.72 kB
Size
53.07 kB
File Count
14
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 29, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
29
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!
128-bit complex number array.
1npm install @stdlib/array-complex128
1var Complex128Array = require( '@stdlib/array-complex128' );
Creates a 128-bit complex number array.
1var arr = new Complex128Array(); 2// returns <Complex128Array>
Creates a 128-bit complex number array having a specified length
.
1var arr = new Complex128Array( 10 ); 2// returns <Complex128Array> 3 4var len = arr.length; 5// returns 10
Creates a 128-bit complex number array from another complex number array.
1var arr1 = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); // [ re, im, re, im ] 2// returns <Complex128Array> 3 4var arr2 = new Complex128Array( arr1 ); 5// returns <Complex128Array> 6 7var len = arr2.length; 8// returns 2
Creates a 128-bit complex number array from a typed array containing interleaved real and imaginary components.
1var Float64Array = require( '@stdlib/array-float64' ); 2 3var buf = new Float64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); // [ re, im, re, im ] 4// returns <Float64Array>[ 1.0, -1.0, 2.0, -2.0 ] 5 6var arr = new Complex128Array( buf ); 7// returns <Complex128Array> 8 9var len = arr.length; 10// returns 2
Creates a 128-bit complex number array from an array-like object or iterable.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3// From an array of interleaved real and imaginary components: 4var arr1 = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); 5// returns <Complex128Array> 6 7var len = arr1.length; 8// returns 2 9 10// From an array containing complex numbers: 11var buf = [ new Complex128( 1.0, -1.0 ), new Complex128( 2.0, -2.0 ) ]; 12var arr2 = new Complex128Array( buf ); 13 14len = arr2.length; 15// returns 2
Returns a 128-bit complex number array view of an ArrayBuffer
.
1var ArrayBuffer = require( '@stdlib/array-buffer' ); 2var buf = new ArrayBuffer( 480 ); 3 4var arr1 = new Complex128Array( buf ); 5// returns <Complex128Array> 6 7var len = arr1.length; 8// returns 30 9 10var arr2 = new Complex128Array( buf, 16 ); 11// returns <Complex128Array> 12 13len = arr2.length; 14// returns 29 15 16var arr3 = new Complex128Array( buf, 16, 20 ); 17// returns <Complex128Array> 18 19len = arr3.length; 20// returns 20
Static property returning the size (in bytes) of each array element.
1var nbytes = Complex128Array.BYTES_PER_ELEMENT; 2// returns 16
Static property returning the constructor name.
1var str = Complex128Array.name; 2// returns 'Complex128Array'
Pointer to the underlying data buffer.
1var arr = new Complex128Array( 2 ); 2// returns <Complex128Array> 3 4var buf = arr.buffer; 5// returns <ArrayBuffer>
Size (in bytes) of the array.
1var arr = new Complex128Array( 10 ); 2// returns <Complex128Array> 3 4var nbytes = arr.byteLength; 5// returns 160
Offset (in bytes) of the array from the start of its underlying ArrayBuffer
.
1var ArrayBuffer = require( '@stdlib/array-buffer' ); 2 3var arr = new Complex128Array( 10 ); 4// returns <Complex128Array> 5 6var offset = arr.byteOffset; 7// returns 0 8 9var buf = new ArrayBuffer( 480 ); 10arr = new Complex128Array( buf, 128 ); 11// returns <Complex128Array> 12 13offset = arr.byteOffset; 14// returns 128
Size (in bytes) of each array element.
1var arr = new Complex128Array( 10 ); 2// returns <Complex128Array> 3 4var nbytes = arr.BYTES_PER_ELEMENT; 5// returns 16
Number of array elements.
1var arr = new Complex128Array( 10 ); 2// returns <Complex128Array> 3 4var len = arr.length; 5// returns 10
Creates a new 128-bit complex number array from an array-like object or an iterable.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3// Create an array from interleaved real and imaginary components: 4var arr = Complex128Array.from( [ 1.0, -1.0 ] ); 5// returns <Complex128Array> 6 7var len = arr.length; 8// returns 1 9 10// Create an array from an array of complex numbers: 11arr = Complex128Array.from( [ new Complex128( 1.0, -1.0 ) ] ); 12// returns <Complex128Array> 13 14len = arr.length; 15// returns 1
The iterator returned by an iterable must return either a complex number or an array-like object containing a real and imaginary component.
1var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); 2var Float64Array = require( '@stdlib/array-float64' ); 3var real = require( '@stdlib/complex-float64-real' ); 4var imag = require( '@stdlib/complex-float64-imag' ); 5 6var iter; 7var arr; 8var len; 9var re; 10var im; 11var z; 12 13// Define a function which returns an iterator protocol-compliant object... 14function iterable() { 15 var buf = new Float64Array( 2 ); 16 var i = 0; 17 return { 18 'next': next 19 }; 20 21 function next() { 22 i += 1; 23 if ( i < 3 ) { 24 // Reuse allocated memory... 25 buf[ 0 ] = i; 26 buf[ 1 ] = -i; 27 return { 28 'value': buf 29 }; 30 } 31 return { 32 'done': true 33 }; 34 } 35} 36 37if ( ITERATOR_SYMBOL === null ) { 38 console.error( 'Environment does not support iterables.' ); 39} else { 40 // Create an iterable: 41 iter = {}; 42 iter[ ITERATOR_SYMBOL ] = iterable; 43 44 // Generate a complex number array: 45 arr = Complex128Array.from( iter ); 46 // returns <Complex128Array> 47 48 len = arr.length; 49 // returns 2 50 51 z = arr.get( 0 ); 52 // returns <Complex128> 53 54 re = real( z ); 55 // returns 1.0 56 57 im = imag( z ); 58 // returns -1.0 59}
To invoke a function for each src
value, provide a callback function. If src
is an iterable or an array-like object containing complex numbers, the callback must return either a complex number
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5function map( z ) { 6 return new Complex128( real(z)*2.0, imag(z)*2.0 ); 7} 8 9// Create a source array: 10var src = [ new Complex128( 1.0, -1.0 ) ]; 11 12// Create a new complex number array by scaling the source array: 13var arr = Complex128Array.from( src, map ); 14// returns <Complex128Array> 15 16var len = arr.length; 17// returns 1 18 19var z = arr.get( 0 ); 20// returns <Complex128> 21 22var re = real( z ); 23// returns 2.0 24 25var im = imag( z ); 26// returns -2.0
or an array-like object containing real and imaginary components
1var Float64Array = require( '@stdlib/array-float64' ); 2var Complex128 = require( '@stdlib/complex-float64-ctor' ); 3var real = require( '@stdlib/complex-float64-real' ); 4var imag = require( '@stdlib/complex-float64-imag' ); 5 6// Return a callback which reuses allocated memory... 7function mapFcn() { 8 var buf = new Float64Array( 2 ); 9 return map; 10 11 function map( z ) { 12 buf[ 0 ] = real( z ) * 2.0; 13 buf[ 1 ] = imag( z ) * 2.0; 14 return buf; 15 } 16} 17 18// Create a source array: 19var src = [ new Complex128( 1.0, -1.0 ), new Complex128( 2.0, -2.0 ) ]; 20 21// Create a new complex number array by scaling the source array: 22var arr = Complex128Array.from( src, mapFcn() ); 23// returns <Complex128Array> 24 25var len = arr.length; 26// returns 2 27 28var z = arr.get( 0 ); 29// returns <Complex128> 30 31var re = real( z ); 32// returns 2.0 33 34var im = imag( z ); 35// returns -2.0 36 37z = arr.get( 1 ); 38// returns <Complex128> 39 40re = real( z ); 41// returns 4.0 42 43im = imag( z ); 44// returns -4.0
If src
is an array-like object containing interleaved real and imaginary components, the callback is invoked for each component and should return the transformed component value.
1var Float64Array = require( '@stdlib/array-float64' ); 2var Complex128 = require( '@stdlib/complex-float64-ctor' ); 3var real = require( '@stdlib/complex-float64-real' ); 4var imag = require( '@stdlib/complex-float64-imag' ); 5 6function map( v ) { 7 return v * 2.0; 8} 9 10// Create a source array: 11var src = new Float64Array( [ 1.0, -1.0 ] ); 12 13// Create a new complex number array by scaling the source array: 14var arr = Complex128Array.from( src, map ); 15// returns <Complex128Array> 16 17var len = arr.length; 18// returns 1 19 20var z = arr.get( 0 ); 21// returns <Complex128> 22 23var re = real( z ); 24// returns 2.0 25 26var im = imag( z ); 27// returns -2.0
A callback function is provided two arguments:
To set the callback execution context, provide a thisArg
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5function map( z ) { 6 this.count += 1; 7 return new Complex128( real(z)*2.0, imag(z)*2.0 ); 8} 9 10// Create a source array: 11var src = [ new Complex128( 1.0, -1.0 ), new Complex128( 1.0, -1.0 ) ]; 12 13// Define an execution context: 14var ctx = { 15 'count': 0 16}; 17 18// Create a new complex number array by scaling the source array: 19var arr = Complex128Array.from( src, map, ctx ); 20// returns <Complex128Array> 21 22var len = arr.length; 23// returns 2 24 25var n = ctx.count; 26// returns 2
Creates a new 128-bit complex number array from a variable number of arguments.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3var arr = Complex128Array.of( 1.0, -1.0, 2.0, -2.0 ); 4// returns <Complex128Array> 5 6var len = arr.length; 7// returns 2 8 9var z1 = new Complex128( 1.0, -1.0 ); 10var z2 = new Complex128( 2.0, -2.0 ); 11 12arr = Complex128Array.of( z1, z2 ); 13// returns <Complex128Array> 14 15len = arr.length; 16// returns 2
Returns an array element located at integer position (index) i
, with support for both nonnegative and negative integer positions.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( 10 ); 5 6// Set the first, second, and last elements: 7arr.set( [ 1.0, -1.0 ], 0 ); 8arr.set( [ 2.0, -2.0 ], 1 ); 9arr.set( [ 9.0, -9.0 ], 9 ); 10 11// Get the first element: 12var z = arr.at( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 1.0 17 18var im = imag( z ); 19// returns -1.0 20 21// Get the last element: 22z = arr.at( -1 ); 23// returns <Complex128> 24 25re = real( z ); 26// returns 9.0 27 28im = imag( z ); 29// returns -9.0
If provided an out-of-bounds index, the method returns undefined
.
1var arr = new Complex128Array( 10 ); 2 3var z = arr.at( 100 ); 4// returns undefined 5 6z = arr.at( -100 ); 7// returns undefined
Copies a sequence of elements within the array starting at start
and ending at end
(non-inclusive) to the position starting at target
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 4 ); 6 7// Set the array elements: 8arr.set( new Complex128( 1.0, -1.0 ), 0 ); 9arr.set( new Complex128( 2.0, -2.0 ), 1 ); 10arr.set( new Complex128( 3.0, -3.0 ), 2 ); 11arr.set( new Complex128( 4.0, -4.0 ), 3 ); 12 13// Get the first array element: 14var z = arr.get( 0 ); 15// returns <Complex128> 16 17var re = real( z ); 18// returns 1.0 19 20var im = imag( z ); 21// returns -1.0 22 23// Get the second array element: 24z = arr.get( 1 ); 25// returns <Complex128> 26 27re = real( z ); 28// returns 2.0 29 30im = imag( z ); 31// returns -2.0 32 33// Copy the last two elements to the first two elements: 34arr.copyWithin( 0, 2 ); 35 36// Get the first array element: 37z = arr.get( 0 ); 38// returns <Complex128> 39 40re = real( z ); 41// returns 3.0 42 43im = imag( z ); 44// returns -3.0 45 46// Get the second array element: 47z = arr.get( 1 ); 48// returns <Complex128> 49 50re = real( z ); 51// returns 4.0 52 53im = imag( z ); 54// returns -4.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 Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 4 ); 6 7// Set the array elements: 8arr.set( new Complex128( 1.0, -1.0 ), 0 ); 9arr.set( new Complex128( 2.0, -2.0 ), 1 ); 10arr.set( new Complex128( 3.0, -3.0 ), 2 ); 11arr.set( new Complex128( 4.0, -4.0 ), 3 ); 12 13// Get the third array element: 14var z = arr.get( 2 ); 15// returns <Complex128> 16 17var re = real( z ); 18// returns 3.0 19 20var im = imag( z ); 21// returns -3.0 22 23// Get the last array element: 24z = arr.get( 3 ); 25// returns <Complex128> 26 27re = real( z ); 28// returns 4.0 29 30im = imag( z ); 31// returns -4.0 32 33// Copy the first two elements to the last two elements: 34arr.copyWithin( 2, 0, 2 ); 35 36// Get the third array element: 37z = arr.get( 2 ); 38// returns <Complex128> 39 40re = real( z ); 41// returns 1.0 42 43im = imag( z ); 44// returns -1.0 45 46// Get the last array element: 47z = arr.get( 3 ); 48// returns <Complex128> 49 50re = real( z ); 51// returns 2.0 52 53im = imag( z ); 54// 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 Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 4 ); 6 7// Set the array elements: 8arr.set( new Complex128( 1.0, -1.0 ), 0 ); 9arr.set( new Complex128( 2.0, -2.0 ), 1 ); 10arr.set( new Complex128( 3.0, -3.0 ), 2 ); 11arr.set( new Complex128( 4.0, -4.0 ), 3 ); 12 13// Get the third array element: 14var z = arr.get( 2 ); 15// returns <Complex128> 16 17var re = real( z ); 18// returns 3.0 19 20var im = imag( z ); 21// returns -3.0 22 23// Get the last array element: 24z = arr.get( 3 ); 25// returns <Complex128> 26 27re = real( z ); 28// returns 4.0 29 30im = imag( z ); 31// returns -4.0 32 33// Copy the first two elements to the last two elements using negative indices: 34arr.copyWithin( -2, -4, -2 ); 35 36// Get the third array element: 37z = arr.get( 2 ); 38// returns <Complex128> 39 40re = real( z ); 41// returns 1.0 42 43im = imag( z ); 44// returns -1.0 45 46// Get the last array element: 47z = arr.get( 3 ); 48// returns <Complex128> 49 50re = real( z ); 51// returns 2.0 52 53im = imag( z ); 54// returns -2.0
Returns an iterator for iterating over array key-value pairs.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = [ 6 new Complex128( 1.0, -1.0 ), 7 new Complex128( 2.0, -2.0 ), 8 new Complex128( 3.0, -3.0 ) 9]; 10arr = new Complex128Array( arr ); 11 12// Create an iterator: 13var it = arr.entries(); 14 15// Iterate over the key-value pairs... 16var v = it.next().value; 17// returns [ 0, <Complex128> ] 18 19var re = real( v[ 1 ] ); 20// returns 1.0 21 22var im = imag( v[ 1 ] ); 23// returns -1.0 24 25v = it.next().value; 26// returns [ 1, <Complex128> ] 27 28re = real( v[ 1 ] ); 29// returns 2.0 30 31im = imag( v[ 1 ] ); 32// returns -2.0 33 34v = it.next().value; 35// returns [ 2, <Complex128> ] 36 37re = real( v[ 1 ] ); 38// returns 3.0 39 40im = imag( v[ 1 ] ); 41// returns -3.0 42 43var bool = it.next().done; 44// returns true
Returns a boolean indicating whether all elements pass a test.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, 1.0 ], 0 ); 12arr.set( [ 2.0, 2.0 ], 1 ); 13arr.set( [ 3.0, 3.0 ], 2 ); 14 15// Check whether all elements pass a test: 16var bool = arr.every( predicate ); 17// returns true
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1function predicate( v, i ) { 2 this.count += 1; 3 return ( i >= 0 ); 4} 5 6var arr = new Complex128Array( 3 ); 7 8var context = { 9 'count': 0 10}; 11 12// Set the first three elements: 13arr.set( [ 1.0, 1.0 ], 0 ); 14arr.set( [ 2.0, 2.0 ], 1 ); 15arr.set( [ 3.0, 3.0 ], 2 ); 16 17var bool = arr.every( predicate, context ); 18// returns true 19 20var count = context.count; 21// returns 3
Returns a modified typed array filled with a fill value.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 3 ); 6 7// Set all elements to the same value: 8arr.fill( new Complex128( 1.0, 1.0 ) ); 9 10var z = arr.get( 0 ); 11// returns <Complex128> 12 13var re = real( z ); 14// returns 1.0 15 16var im = imag( z ); 17// returns 1.0 18 19z = arr.get( 2 ); 20// returns <Complex128> 21 22re = real( z ); 23// returns 1.0 24 25im = imag( z ); 26// returns 1.0 27 28// Fill all elements starting from the second element: 29arr.fill( new Complex128( 2.0, 2.0 ), 1 ); 30 31z = arr.get( 1 ); 32// returns <Complex128> 33 34re = real( z ); 35// returns 2.0 36 37im = imag( z ); 38// returns 2.0 39 40z = arr.get( 2 ); 41// returns <Complex128> 42 43re = real( z ); 44// returns 2.0 45 46im = imag( z ); 47// returns 2.0 48 49// Fill all elements from first element until the second-to-last element: 50arr.fill( new Complex128( 3.0, 3.0 ), 0, 2 ); 51 52z = arr.get( 0 ); 53// returns <Complex128> 54 55re = real( z ); 56// returns 3.0 57 58im = imag( z ); 59// returns 3.0 60 61z = arr.get( 1 ); 62// returns <Complex128> 63 64re = real( z ); 65// returns 3.0 66 67im = imag( z ); 68// returns 3.0
When a start
and/or end
index is negative, the respective index is determined relative to the last array element.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 3 ); 6 7// Set all array elements, except the last element, to the same value: 8arr.fill( new Complex128( 1.0, 1.0 ), 0, -1 ); 9 10var z = arr.get( 0 ); 11// returns <Complex128> 12 13var re = real( z ); 14// returns 1.0 15 16var im = imag( z ); 17// returns 1.0 18 19z = arr.get( arr.length - 1 ); 20// returns <Complex128> 21 22re = real( z ); 23// returns 0.0 24 25im = imag( z ); 26// returns 0.0
Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, -1.0 ], 0 ); 12arr.set( [ 2.0, 2.0 ], 1 ); 13arr.set( [ 3.0, -3.0 ], 2 ); 14 15var out = arr.filter( predicate ); 16// returns <Complex128Array> 17 18var len = out.length; 19// returns 1 20 21var z = out.get( 0 ); 22// returns <Complex128> 23 24var re = real( z ); 25// returns 2.0 26 27var im = imag( z ); 28// returns 2.0
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v, i ) { 5 this.count += 1; 6 return ( i >= 0 && real( v ) === imag( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11var context = { 12 'count': 0 13}; 14 15// Set the first three elements: 16arr.set( [ 1.0, -1.0 ], 0 ); 17arr.set( [ 2.0, 2.0 ], 1 ); 18arr.set( [ 3.0, 3.0 ], 2 ); 19 20var out = arr.filter( predicate, context ); 21// returns <Complex128Array> 22 23var len = out.length; 24// returns 2 25 26var count = context.count; 27// returns 3
Returns the first element in an array for which a predicate function returns a truthy value.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, 1.0 ], 0 ); 12arr.set( [ 2.0, 2.0 ], 1 ); 13arr.set( [ 3.0, 3.0 ], 2 ); 14 15var z = arr.find( predicate ); 16// returns <Complex128> 17 18var re = real( z ); 19// returns 1.0 20 21var im = imag( z ); 22// returns 1.0
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v, i ) { 5 this.count += 1; 6 return ( i >= 0 && real( v ) === imag( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11var context = { 12 'count': 0 13}; 14 15// Set the first three elements: 16arr.set( [ 1.0, -1.0 ], 0 ); 17arr.set( [ 2.0, 2.0 ], 1 ); 18arr.set( [ 3.0, 3.0 ], 2 ); 19 20var z = arr.find( predicate, context ); 21// returns <Complex128> 22 23var re = real( z ); 24// returns 2.0 25 26var im = imag( z ); 27// returns 2.0 28 29var count = context.count; 30// returns 2
Returns the index of the first element in an array for which a predicate function returns a truthy value.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, -1.0 ], 0 ); 12arr.set( [ 2.0, -2.0 ], 1 ); 13arr.set( [ 3.0, 3.0 ], 2 ); 14 15var idx = arr.findIndex( predicate ); 16// returns 2
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v, i ) { 5 this.count += 1; 6 return ( i >= 0 && real( v ) === imag( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11var context = { 12 'count': 0 13}; 14 15// Set the first three elements: 16arr.set( [ 1.0, -1.0 ], 0 ); 17arr.set( [ 2.0, -2.0 ], 1 ); 18arr.set( [ 3.0, -3.0 ], 2 ); 19 20var idx = arr.findIndex( predicate, context ); 21// returns -1 22 23var count = context.count; 24// returns 3
Returns the last element in an array for which a predicate function returns a truthy value.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, 1.0 ], 0 ); 12arr.set( [ 2.0, 2.0 ], 1 ); 13arr.set( [ 3.0, 3.0 ], 2 ); 14 15var z = arr.findLast( predicate ); 16// returns <Complex128> 17 18var re = real( z ); 19// returns 3.0 20 21var im = imag( z ); 22// returns 3.0
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v, i ) { 5 this.count += 1; 6 return ( i >= 0 && real( v ) === imag( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11var context = { 12 'count': 0 13}; 14 15// Set the first three elements: 16arr.set( [ 1.0, -1.0 ], 0 ); 17arr.set( [ 2.0, 2.0 ], 1 ); 18arr.set( [ 3.0, -3.0 ], 2 ); 19 20var z = arr.findLast( predicate, context ); 21// returns <Complex128> 22 23var re = real( z ); 24// returns 2.0 25 26var im = imag( z ); 27// returns 2.0 28 29var count = context.count; 30// returns 2
Returns the index of the last element in an array for which a predicate function returns a truthy value.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, 1.0 ], 0 ); 12arr.set( [ 2.0, 2.0 ], 1 ); 13arr.set( [ 3.0, -3.0 ], 2 ); 14 15var idx = arr.findLastIndex( predicate ); 16// returns 1
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v, i ) { 5 this.count += 1; 6 return ( i >= 0 && real( v ) === imag( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11var context = { 12 'count': 0 13}; 14 15// Set the first three elements: 16arr.set( [ 1.0, -1.0 ], 0 ); 17arr.set( [ 2.0, -2.0 ], 1 ); 18arr.set( [ 3.0, -3.0 ], 2 ); 19 20var idx = arr.findLastIndex( predicate, context ); 21// returns -1 22 23var count = context.count; 24// returns 3
Invokes a function once for each array element.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3function log( v, i ) { 4 console.log( '%s: %s', i, v.toString() ); 5} 6 7var arr = new Complex128Array( 3 ); 8 9// Set the first three elements: 10arr.set( [ 1.0, 1.0 ], 0 ); 11arr.set( [ 2.0, 2.0 ], 1 ); 12arr.set( [ 3.0, 3.0 ], 2 ); 13 14arr.forEach( log ); 15/* => 16 0: 1 + 1i 17 1: 2 + 2i 18 2: 3 + 3i 19*/
The invoked function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3function fcn( v, i ) { 4 this.count += 1; 5 console.log( '%s: %s', i, v.toString() ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10var context = { 11 'count': 0 12}; 13 14// Set the first three elements: 15arr.set( [ 1.0, -1.0 ], 0 ); 16arr.set( [ 2.0, -2.0 ], 1 ); 17arr.set( [ 3.0, -3.0 ], 2 ); 18 19arr.forEach( fcn, context ); 20/* => 21 0: 1 + 1i 22 1: 2 + 2i 23 2: 3 + 3i 24*/ 25 26var count = context.count; 27// returns 3
Returns an array element located at position (index) i
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( 10 ); 5 6// Set the first element: 7arr.set( [ 1.0, -1.0 ], 0 ); 8 9// Get the first element: 10var z = arr.get( 0 ); 11// returns <Complex128> 12 13var re = real( z ); 14// returns 1.0 15 16var im = imag( z ); 17// returns -1.0
If provided an out-of-bounds index, the method returns undefined
.
1var arr = new Complex128Array( 10 ); 2 3var z = arr.get( 100 ); 4// returns undefined
Returns a boolean indicating whether an array includes a provided value.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3var arr = new Complex128Array( 5 ); 4 5arr.set( [ 1.0, -1.0 ], 0 ); 6arr.set( [ 2.0, -2.0 ], 1 ); 7arr.set( [ 3.0, -3.0 ], 2 ); 8arr.set( [ 4.0, -4.0 ], 3 ); 9arr.set( [ 5.0, -5.0 ], 4 ); 10 11var bool = arr.includes( new Complex128( 3.0, -3.0 ) ); 12// returns true 13 14bool = arr.includes( new Complex128( 3.0, -3.0 ), 3 ); 15// returns false 16 17bool = arr.includes( new Complex128( 4.0, -4.0 ), -3 ); 18// returns true
Returns the first index at which a given element can be found.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3var arr = new Complex128Array( 5 ); 4 5arr.set( [ 1.0, -1.0 ], 0 ); 6arr.set( [ 2.0, -2.0 ], 1 ); 7arr.set( [ 3.0, -3.0 ], 2 ); 8arr.set( [ 4.0, -4.0 ], 3 ); 9arr.set( [ 2.0, -2.0 ], 4 ); 10 11var idx = arr.indexOf( new Complex128( 3.0, -3.0 ) ); 12// returns 2 13 14idx = arr.indexOf( new Complex128( 2.0, -2.0 ), 2 ); 15// returns 4 16 17idx = arr.indexOf( new Complex128( 4.0, -4.0 ), -3 ); 18// returns 3
If searchElement
is not present in the array, the method returns -1
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3var arr = new Complex128Array( 5 ); 4 5arr.set( [ 1.0, -1.0 ], 0 ); 6arr.set( [ 2.0, -2.0 ], 1 ); 7 8var idx = arr.indexOf( new Complex128( 3.0, -3.0 ) ); 9// returns -1 10 11idx = arr.indexOf( new Complex128( 1.0, -1.0 ), 1 ); 12// returns -1
Returns a new string by concatenating all array elements.
1var arr = new Complex128Array( 3 ); 2 3arr.set( [ 1.0, 1.0 ], 0 ); 4arr.set( [ 2.0, -2.0 ], 1 ); 5arr.set( [ 3.0, 3.0 ], 2 ); 6 7var str = arr.join(); 8// returns '1 + 1i,2 - 2i,3 + 3i'
By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a separator
string.
1var arr = new Complex128Array( 3 ); 2 3arr.set( [ 1.0, 1.0 ], 0 ); 4arr.set( [ 2.0, -2.0 ], 1 ); 5arr.set( [ 3.0, 3.0 ], 2 ); 6 7var str = arr.join( '/' ); 8// returns '1 + 1i/2 - 2i/3 + 3i'
Returns an iterator for iterating over each index key in a typed array.
1var arr = new Complex128Array( 2 ); 2 3arr.set( [ 1.0, -1.0 ], 0 ); 4arr.set( [ 2.0, -2.0 ], 1 ); 5 6var iter = arr.keys(); 7 8var v = iter.next().value; 9// returns 0 10 11v = iter.next().value; 12// returns 1 13 14var bool = iter.next().done; 15// returns true
The returned iterator protocol-compliant object has the following properties:
value
property and a done
property having a boolean
value indicating whether the iterator is finished.Returns the last index at which a given element can be found.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3var arr = new Complex128Array( 5 ); 4 5arr.set( [ 1.0, -1.0 ], 0 ); 6arr.set( [ 2.0, -2.0 ], 1 ); 7arr.set( [ 3.0, -3.0 ], 2 ); 8arr.set( [ 4.0, -4.0 ], 3 ); 9arr.set( [ 2.0, -2.0 ], 4 ); 10 11var idx = arr.lastIndexOf( new Complex128( 3.0, -3.0 ) ); 12// returns 2 13 14idx = arr.lastIndexOf( new Complex128( 2.0, -2.0 ), 2 ); 15// returns 1 16 17idx = arr.lastIndexOf( new Complex128( 4.0, -4.0 ), -1 ); 18// returns 3
If searchElement
is not present in the array, the method returns -1
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2 3var arr = new Complex128Array( 5 ); 4 5arr.set( [ 1.0, -1.0 ], 0 ); 6arr.set( [ 2.0, -2.0 ], 1 ); 7 8var idx = arr.lastIndexOf( new Complex128( 3.0, -3.0 ) ); 9// returns -1 10 11idx = arr.lastIndexOf( new Complex128( 2.0, -2.0 ), 0 ); 12// returns -1
Returns a new array with each element being the result of a provided callback function.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5function scale( v ) { 6 return new Complex128( 2.0*real( v ), 2.0*imag( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11// Set the first three elements: 12arr.set( [ 1.0, -1.0 ], 0 ); 13arr.set( [ 2.0, -2.0 ], 1 ); 14arr.set( [ 3.0, -3.0 ], 2 ); 15 16var out = arr.map( scale ); 17// returns <Complex128Array> 18 19var z = out.get( 0 ); 20// returns <Complex128> 21 22var re = real( z ); 23// returns 2.0 24 25var im = imag( z ); 26// returns -2.0
The callback function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5function scale( v ) { 6 this.count += 1; 7 return new Complex128( 2.0*real( v ), 2.0*imag( v ) ); 8} 9 10var arr = new Complex128Array( 3 ); 11 12var context = { 13 'count': 0 14}; 15 16// Set the first three elements: 17arr.set( [ 1.0, 1.0 ], 0 ); 18arr.set( [ 2.0, 2.0 ], 1 ); 19arr.set( [ 3.0, 3.0 ], 2 ); 20 21var out = arr.map( scale, context ); 22// returns <Complex128Array> 23 24var count = context.count; 25// returns 3
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.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3var cadd = require( '@stdlib/complex-float64-base-add' ); 4 5var arr = new Complex128Array( 3 ); 6 7arr.set( [ 1.0, 1.0 ], 0 ); 8arr.set( [ 2.0, 2.0 ], 1 ); 9arr.set( [ 3.0, 3.0 ], 2 ); 10 11var z = arr.reduce( cadd ); 12// returns <Complex128> 13 14var re = real( z ); 15// returns 6.0 16 17var im = imag( z ); 18// returns 6.0
The reducer function is provided four arguments:
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.
1var real = require( '@stdlib/complex-float64-real' ); 2 3function reducer( acc, v ) { 4 acc += real( v ); 5 return acc; 6} 7 8var arr = new Complex128Array( 3 ); 9 10arr.set( [ 1.0, 1.0 ], 0 ); 11arr.set( [ 2.0, 2.0 ], 1 ); 12arr.set( [ 3.0, 3.0 ], 2 ); 13 14var z = arr.reduce( reducer, 0.0 ); 15// returns 6.0
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.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3var cadd = require( '@stdlib/complex-float64-base-add' ); 4 5var arr = new Complex128Array( 3 ); 6 7arr.set( [ 1.0, 1.0 ], 0 ); 8arr.set( [ 2.0, 2.0 ], 1 ); 9arr.set( [ 3.0, 3.0 ], 2 ); 10 11var z = arr.reduceRight( cadd ); 12// returns <Complex128> 13 14var re = real( z ); 15// returns 6.0 16 17var im = imag( z ); 18// returns 6.0
The reducer function is provided four arguments:
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.
1var real = require( '@stdlib/complex-float64-real' ); 2 3function reducer( acc, v ) { 4 acc += real( v ); 5 return acc; 6} 7 8var arr = new Complex128Array( 3 ); 9 10arr.set( [ 1.0, 1.0 ], 0 ); 11arr.set( [ 2.0, 2.0 ], 1 ); 12arr.set( [ 3.0, 3.0 ], 2 ); 13 14var z = arr.reduceRight( reducer, 0.0 ); 15// returns 6.0
Reverses an array in-place.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( 3 ); 5 6arr.set( [ 1.0, 1.0 ], 0 ); 7arr.set( [ 2.0, 2.0 ], 1 ); 8arr.set( [ 3.0, 3.0 ], 2 ); 9 10var out = arr.reverse(); 11// returns <Complex128Array> 12 13var z = out.get( 0 ); 14// returns <Complex128> 15 16var re = real( z ); 17// returns 3.0 18 19var im = imag( z ); 20// returns 3.0 21 22z = out.get( 1 ); 23// returns <Complex128> 24 25re = real( z ); 26// returns 2.0 27 28im = imag( z ); 29// returns 2.0 30 31z = out.get( 2 ); 32// returns <Complex128> 33 34re = real( z ); 35// returns 1.0 36 37im = imag( z ); 38// returns 1.0
Sets one or more array elements.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 10 ); 6 7// Get the first element: 8var z = arr.get( 0 ); 9// returns <Complex128> 10 11var re = real( z ); 12// returns 0.0 13 14var im = imag( z ); 15// returns 0.0 16 17// Set the first element: 18arr.set( new Complex128( 1.0, -1.0 ) ); 19 20// Get the first element: 21z = arr.get( 0 ); 22// returns <Complex128> 23 24re = real( z ); 25// returns 1.0 26 27im = imag( z ); 28// returns -1.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
.
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 10 ); 6 7// Get the fifth element: 8var z = arr.get( 4 ); 9// returns <Complex128> 10 11var re = real( z ); 12// returns 0.0 13 14var im = imag( z ); 15// returns 0.0 16 17// Set the fifth element: 18arr.set( new Complex128( 1.0, -1.0 ), 4 ); 19 20// Get the fifth element: 21z = arr.get( 4 ); 22// returns <Complex128> 23 24re = real( z ); 25// returns 1.0 26 27im = imag( z ); 28// returns -1.0
In addition to providing a complex number, to set one or more array elements, provide an array-like object containing either complex numbers
1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 10 ); 6 7// Define an array of complex numbers: 8var buf = [ 9 new Complex128( 1.0, -1.0 ), 10 new Complex128( 2.0, -2.0 ), 11 new Complex128( 3.0, -3.0 ) 12]; 13 14// Set the fifth, sixth, and seventh elements: 15arr.set( buf, 4 ); 16 17// Get the sixth element: 18var z = arr.get( 5 ); 19// returns <Complex128> 20 21var re = real( z ); 22// returns 2.0 23 24var im = imag( z ); 25// returns -2.0
or interleaved real and imaginary components
1var Float64Array = require( '@stdlib/array-float64' ); 2var real = require( '@stdlib/complex-float64-real' ); 3var imag = require( '@stdlib/complex-float64-imag' ); 4 5var arr = new Complex128Array( 10 ); 6 7// Define an interleaved array of real and imaginary components: 8var buf = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); 9 10// Set the fifth, sixth, and seventh elements: 11arr.set( buf, 4 ); 12 13// Get the sixth element: 14var z = arr.get( 5 ); 15// returns <Complex128> 16 17var re = real( z ); 18// returns 2.0 19 20var im = imag( z ); 21// returns -2.0
A few notes:
i
is out-of-bounds, the method throws an error.i
exceeds the target array length), the method throws an error.ArrayBuffer
with the target array, the method will intelligently copy the source range to the destination range.Copies a portion of a typed array to a new typed array.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); 5 6var out = arr.slice(); 7// returns <Complex128Array> 8 9var len = out.length; 10// returns 4 11 12var z = out.get( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 1.0 17 18var im = imag( z ); 19// returns 2.0 20 21z = out.get( len-1 ); 22// returns <Complex128> 23 24re = real( z ); 25// returns 7.0 26 27im = imag( z ); 28// returns 8.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).
1var imag = require( '@stdlib/complex-float64-imag' ); 2var real = require( '@stdlib/complex-float64-real' ); 3 4var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); 5 6var out = arr.slice( 1 ); 7// returns <Complex128Array> 8 9var len = out.length; 10// returns 3 11 12var z = out.get( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 3.0 17 18var im = imag( z ); 19// returns 4.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).
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); 5 6var out = arr.slice( 1, -1 ); 7// returns <Complex128Array> 8 9var len = out.length; 10// returns 2 11 12var z = out.get( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 3.0 17 18var im = imag( z ); 19// returns 4.0 20 21z = out.get( len-1 ); 22// returns <Complex128> 23 24re = real( z ); 25// returns 5.0 26 27im = imag( z ); 28// returns 6.0
Returns a boolean indicating whether at least one element passes a test.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v ) { 5 return ( real( v ) === imag( v ) ); 6} 7 8var arr = new Complex128Array( 3 ); 9 10// Set the first three elements: 11arr.set( [ 1.0, -1.0 ], 0 ); 12arr.set( [ 2.0, 2.0 ], 1 ); 13arr.set( [ 3.0, -3.0 ], 2 ); 14 15// Check whether at least one element passes a test: 16var bool = arr.some( predicate ); 17// returns true
The predicate
function is provided three arguments:
To set the function execution context, provide a thisArg
.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function predicate( v, i ) { 5 this.count += 1; 6 return ( imag( v ) === real( v ) ); 7} 8 9var arr = new Complex128Array( 3 ); 10 11var context = { 12 'count': 0 13}; 14 15// Set the first three elements: 16arr.set( [ 1.0, -1.0 ], 0 ); 17arr.set( [ 2.0, 2.0 ], 1 ); 18arr.set( [ 3.0, -3.0 ], 2 ); 19 20var bool = arr.some( predicate, context ); 21// returns true 22 23var count = context.count; 24// returns 2
Sorts an array in-place.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function compare( a, b ) { 5 var re1; 6 var re2; 7 var im1; 8 var im2; 9 re1 = real( a ); 10 re2 = real( b ); 11 if ( re1 < re2 ) { 12 return -1; 13 } 14 if ( re1 > re2 ) { 15 return 1; 16 } 17 im1 = imag( a ); 18 im2 = imag( b ); 19 if ( im1 < im2 ) { 20 return -1; 21 } 22 if ( im1 > im2 ) { 23 return 1; 24 } 25 return 0; 26} 27 28var arr = new Complex128Array( 3 ); 29 30arr.set( [ 3.0, -3.0 ], 0 ); 31arr.set( [ 1.0, -1.0 ], 1 ); 32arr.set( [ 2.0, -2.0 ], 2 ); 33 34var out = arr.sort( compare ); 35// returns <Complex128Array> 36 37var z = out.get( 0 ); 38// returns <Complex128> 39 40var re = real( z ); 41// returns 1.0 42 43var im = imag( z ); 44// returns -1.0 45 46z = out.get( 1 ); 47// returns <Complex128> 48 49re = real( z ); 50// returns 2.0 51 52im = imag( z ); 53// returns -2.0 54 55z = out.get( 2 ); 56// returns <Complex128> 57 58re = real( z ); 59// returns 3.0 60 61im = imag( z ); 62// returns -3.0
The compareFcn
determines the order of the elements. The function is called with the following arguments:
The function should return a number where:
a
should come before b
.a
should come after b
.NaN
indicates that a
and b
are considered equal.In contrast to real numbers, one cannot define a default order relation which is compatible with multiplication. Accordingly, users must explicitly provide a compareFcn
argument and are thus responsible for specifying a complex number ordering.
Creates a new typed array view over the same underlying ArrayBuffer
and with the same underlying data type as the host array.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); 5 6var subarr = arr.subarray(); 7// returns <Complex128Array> 8 9var len = subarr.length; 10// returns 4 11 12var z = subarr.get( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 1.0 17 18var im = imag( z ); 19// returns 2.0 20 21z = subarr.get( len-1 ); 22// returns <Complex128> 23 24re = real( z ); 25// returns 7.0 26 27im = imag( z ); 28// returns 8.0
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 imag = require( '@stdlib/complex-float64-imag' ); 2var real = require( '@stdlib/complex-float64-real' ); 3 4var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); 5 6var subarr = arr.subarray( 1 ); 7// returns <Complex128Array> 8 9var len = subarr.length; 10// returns 3 11 12var z = subarr.get( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 3.0 17 18var im = imag( z ); 19// returns 4.0
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 real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); 5 6var subarr = arr.subarray( 1, -1 ); 7// returns <Complex128Array> 8 9var len = subarr.length; 10// returns 2 11 12var z = subarr.get( 0 ); 13// returns <Complex128> 14 15var re = real( z ); 16// returns 3.0 17 18var im = imag( z ); 19// returns 4.0 20 21z = subarr.get( len-1 ); 22// returns <Complex128> 23 24re = real( z ); 25// returns 5.0 26 27im = imag( z ); 28// returns 6.0
Serializes an array as a locale-specific string.
1var arr = new Complex128Array( 2 ); 2 3arr.set( [ 1.0, 1.0 ], 0 ); 4arr.set( [ 2.0, 2.0 ], 1 ); 5 6var str = arr.toLocaleString(); 7// returns '1 + 1i,2 + 2i'
The method supports the following arguments:
Returns a new typed array containing the elements in reversed order.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4var arr = new Complex128Array( 3 ); 5 6arr.set( [ 1.0, 1.0 ], 0 ); 7arr.set( [ 2.0, 2.0 ], 1 ); 8arr.set( [ 3.0, 3.0 ], 2 ); 9 10var out = arr.toReversed(); 11// returns <Complex128Array> 12 13var z = out.get( 0 ); 14// returns <Complex128> 15 16var re = real( z ); 17// returns 3.0 18 19var im = imag( z ); 20// returns 3.0 21 22z = out.get( 1 ); 23// returns <Complex128> 24 25re = real( z ); 26// returns 2.0 27 28im = imag( z ); 29// returns 2.0 30 31z = out.get( 2 ); 32// returns <Complex128> 33 34re = real( z ); 35// returns 1.0 36 37im = imag( z ); 38// returns 1.0
Returns a new typed array containing the elements in sorted order.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3 4function compare( a, b ) { 5 var re1; 6 var re2; 7 var im1; 8 var im2; 9 re1 = real( a ); 10 re2 = real( b ); 11 if ( re1 < re2 ) { 12 return -1; 13 } 14 if ( re1 > re2 ) { 15 return 1; 16 } 17 im1 = imag( a ); 18 im2 = imag( b ); 19 if ( im1 < im2 ) { 20 return -1; 21 } 22 if ( im1 > im2 ) { 23 return 1; 24 } 25 return 0; 26} 27 28var arr = new Complex128Array( 3 ); 29 30arr.set( [ 3.0, -3.0 ], 0 ); 31arr.set( [ 1.0, -1.0 ], 1 ); 32arr.set( [ 2.0, -2.0 ], 2 ); 33 34var out = arr.toSorted( compare ); 35// returns <Complex128Array> 36 37var z = out.get( 0 ); 38// returns <Complex128> 39 40var re = real( z ); 41// returns 1.0 42 43var im = imag( z ); 44// returns -1.0 45 46z = out.get( 1 ); 47// returns <Complex128> 48 49re = real( z ); 50// returns 2.0 51 52im = imag( z ); 53// returns -2.0 54 55z = out.get( 2 ); 56// returns <Complex128> 57 58re = real( z ); 59// returns 3.0 60 61im = imag( z ); 62// returns -3.0
The compareFcn
determines the order of the elements. The function is called with the following arguments:
The function should return a number where:
a
should come before b
.a
should come after b
.NaN
indicates that a
and b
are considered equal.In contrast to real numbers, one cannot define a default order relation which is compatible with multiplication. Accordingly, users must explicitly provide a compareFcn
argument and are thus responsible for specifying a complex number ordering.
Serializes an array as a string.
1var arr = new Complex128Array( 3 ); 2 3arr.set( [ 1.0, 1.0 ], 0 ); 4arr.set( [ 2.0, -2.0 ], 1 ); 5arr.set( [ 3.0, 3.0 ], 2 ); 6 7var str = arr.toString(); 8// returns '1 + 1i,2 - 2i,3 + 3i'
Returns an iterator for iterating over each value in a typed array.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3var arr = new Complex128Array( 2 ); 4 5arr.set( [ 1.0, -1.0 ], 0 ); 6arr.set( [ 2.0, -2.0 ], 1 ); 7 8var iter = arr.values(); 9 10var v = iter.next().value; 11// returns <Complex128> 12 13var re = real( v ); 14// returns 1.0 15 16var im = imag( v ); 17// returns -1.0 18 19v = iter.next().value; 20// returns <Complex128> 21 22re = real( v ); 23// returns 2.0 24 25im = imag( v ); 26// returns -2.0 27 28var bool = iter.next().done; 29// returns true
The returned iterator protocol-compliant object has the following properties:
value
property and a done
property having a boolean
value indicating whether the iterator is finished.Returns a new typed array with the element at a provided index replaced with a provided value.
1var real = require( '@stdlib/complex-float64-real' ); 2var imag = require( '@stdlib/complex-float64-imag' ); 3var Complex128 = require( '@stdlib/complex-float64-ctor' ); 4 5var arr = new Complex128Array( 3 ); 6 7arr.set( [ 1.0, 1.0 ], 0 ); 8arr.set( [ 2.0, 2.0 ], 1 ); 9arr.set( [ 3.0, 3.0 ], 1 ); 10 11var out = arr.with( 0, new Complex128( 4.0, 4.0 ) ); 12// returns <Complex128Array> 13 14var z = out.get( 0 ); 15// returns <Complex128> 16 17var re = real( z ); 18// returns 4.0 19 20var im = imag( z ); 21// returns 4.0
While a Complex128Array
strives to maintain (but does not guarantee) consistency with typed arrays, significant deviations from ECMAScript-defined typed array behavior are as follows:
new
operator.Z[i]
) is not supported. Instead, one must use the .get()
method which returns a value compatible with complex number output.set
method has extended behavior in order to support complex numbers.1var Complex128 = require( '@stdlib/complex-float64-ctor' ); 2var Float64Array = require( '@stdlib/array-float64' ); 3var logEach = require( '@stdlib/console-log-each' ); 4var Complex128Array = require( '@stdlib/array-complex128' ); 5 6// Create a complex array by specifying a length: 7var out = new Complex128Array( 3 ); 8logEach( '%s', out ); 9 10// Create a complex array from an array of complex numbers: 11var arr = [ 12 new Complex128( 1.0, -1.0 ), 13 new Complex128( -3.14, 3.14 ), 14 new Complex128( 0.5, 0.5 ) 15]; 16out = new Complex128Array( arr ); 17logEach( '%s', out ); 18 19// Create a complex array from an interleaved typed array: 20arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); 21out = new Complex128Array( arr ); 22logEach( '%s', out ); 23 24// Create a complex array from an array buffer: 25arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); 26out = new Complex128Array( arr.buffer ); 27logEach( '%s', out ); 28 29// Create a complex array from an array buffer view: 30arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); 31out = new Complex128Array( arr.buffer, 16, 2 ); 32logEach( '%s', out );
@stdlib/array-complex64
: Complex64Array.@stdlib/complex-cmplx
: create a complex number.@stdlib/complex-float64/ctor
: 128-bit complex number.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.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-05
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 More