Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Complex64Array.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/array-complex64

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!

Complex64Array

NPM versionBuild StatusCoverage Status

64-bit complex number array.

Usage

importComplex64Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-complex64@esm/index.mjs';

Complex64Array()

Creates a 64-bit complex number array.

vararr=newComplex64Array();// returns <Complex64Array>

Complex64Array( length )

Creates a 64-bit complex number array having a specifiedlength.

vararr=newComplex64Array(10);// returns <Complex64Array>varlen=arr.length;// returns 10

Complex64Array( complexarray )

Creates a 64-bit complex number array from another complex number array.

vararr1=newComplex64Array([1.0,-1.0,2.0,-2.0]);// [ re, im, re, im ]// returns <Complex64Array>vararr2=newComplex64Array(arr1);// returns <Complex64Array>varlen=arr2.length;// returns 2

Complex64Array( typedarray )

Creates a 64-bit complex number array from atyped array containing interleaved real and imaginary components.

importFloat32Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs';varbuf=newFloat32Array([1.0,-1.0,2.0,-2.0]);// [ re, im, re, im ]// returns <Float32Array>[ 1.0, -1.0, 2.0, -2.0 ]vararr=newComplex64Array(buf);// returns <Complex64Array>varlen=arr.length;// returns 2

Complex64Array( obj )

Creates a 64-bit complex number array from an array-like object or iterable.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';// From an array of interleaved real and imaginary components:vararr1=newComplex64Array([1.0,-1.0,2.0,-2.0]);// returns <Complex64Array>varlen=arr1.length;// returns 2// From an array containing complex numbers:varbuf=[newComplex64(1.0,-1.0),newComplex64(2.0,-2.0)];vararr2=newComplex64Array(buf);len=arr2.length;// returns 2

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

Returns a 64-bit complex number array view of anArrayBuffer.

importArrayBufferfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs';varbuf=newArrayBuffer(240);vararr1=newComplex64Array(buf);// returns <Complex64Array>varlen=arr1.length;// returns 30vararr2=newComplex64Array(buf,8);// returns <Complex64Array>len=arr2.length;// returns 29vararr3=newComplex64Array(buf,8,20);// returns <Complex64Array>len=arr3.length;// returns 20

Properties

Complex64Array.BYTES_PER_ELEMENT

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

varnbytes=Complex64Array.BYTES_PER_ELEMENT;// returns 8

Complex64Array.name

Static property returning the constructor name.

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

Complex64Array.prototype.buffer

Pointer to the underlying data buffer.

vararr=newComplex64Array(2);// returns <Complex64Array>varbuf=arr.buffer;// returns <ArrayBuffer>

Complex64Array.prototype.byteLength

Size (in bytes) of the array.

vararr=newComplex64Array(10);// returns <Complex64Array>varnbytes=arr.byteLength;// returns 80

Complex64Array.prototype.byteOffset

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

importArrayBufferfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs';vararr=newComplex64Array(10);// returns <Complex64Array>varoffset=arr.byteOffset;// returns 0varbuf=newArrayBuffer(240);arr=newComplex64Array(buf,64);// returns <Complex64Array>offset=arr.byteOffset;// returns 64

Complex64Array.prototype.BYTES_PER_ELEMENT

Size (in bytes) of each array element.

vararr=newComplex64Array(10);// returns <Complex64Array>varnbytes=arr.BYTES_PER_ELEMENT;// returns 8

Complex64Array.prototype.length

Number of array elements.

vararr=newComplex64Array(10);// returns <Complex64Array>varlen=arr.length;// returns 10

Methods

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

Creates a new 64-bit complex number array from an array-like object or an iterable.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';// Create an array from interleaved real and imaginary components:vararr=Complex64Array.from([1.0,-1.0]);// returns <Complex64Array>varlen=arr.length;// returns 1// Create an array from an array of complex numbers:arr=Complex64Array.from([newComplex64(1.0,-1.0)]);// returns <Complex64Array>len=arr.length;// 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.

importITERATOR_SYMBOLfrom'https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs';importFloat32Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';variter;vararr;varlen;varre;varim;varz;// Define a function which returns an iterator protocol-compliant object...functioniterable(){varbuf=newFloat32Array(2);vari=0;return{'next':next};functionnext(){i+=1;if(i<3){// Reuse allocated memory...buf[0]=i;buf[1]=-i;return{'value':buf};}return{'done':true};}}if(ITERATOR_SYMBOL===null){console.error('Environment does not support iterables.');}else{// Create an iterable:iter={};iter[ITERATOR_SYMBOL]=iterable;// Generate a complex number array:arr=Complex64Array.from(iter);// returns <Complex64Array>len=arr.length;// returns 2z=arr.get(0);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// returns -1.0}

To invoke a function for eachsrc value, provide a callback function. Ifsrc is an iterable or an array-like object containing complex numbers, the callback must return either a complex number

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionmap(z){returnnewComplex64(realf(z)*2.0,imagf(z)*2.0);}// Create a source array:varsrc=[newComplex64(1.0,-1.0)];// Create a new complex number array by scaling the source array:vararr=Complex64Array.from(src,map);// returns <Complex64Array>varlen=arr.length;// returns 1varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns -2.0

or an array-like object containing real and imaginary components

importFloat32Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs';importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';// Return a callback which reuses allocated memory...functionmapFcn(){varbuf=newFloat32Array(2);returnmap;functionmap(z){buf[0]=realf(z)*2.0;buf[1]=imagf(z)*2.0;returnbuf;}}// Create a source array:varsrc=[newComplex64(1.0,-1.0),newComplex64(2.0,-2.0)];// Create a new complex number array by scaling the source array:vararr=Complex64Array.from(src,mapFcn());// returns <Complex64Array>varlen=arr.length;// returns 2varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns -2.0z=arr.get(1);// returns <Complex64>re=realf(z);// returns 4.0im=imagf(z);// returns -4.0

Ifsrc 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.

importFloat32Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs';importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionmap(v){returnv*2.0;}// Create a source array:varsrc=newFloat32Array([1.0,-1.0]);// Create a new complex number array by scaling the source array:vararr=Complex64Array.from(src,map);// returns <Complex64Array>varlen=arr.length;// returns 1varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns -2.0

A callback function is provided two arguments:

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

To set the callback execution context, provide athisArg.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionmap(z){this.count+=1;returnnewComplex64(realf(z)*2.0,imagf(z)*2.0);}// Create a source array:varsrc=[newComplex64(1.0,-1.0),newComplex64(1.0,-1.0)];// Define an execution context:varctx={'count':0};// Create a new complex number array by scaling the source array:vararr=Complex64Array.from(src,map,ctx);// returns <Complex64Array>varlen=arr.length;// returns 2varn=ctx.count;// returns 2

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

Creates a new 64-bit complex number array from a variable number of arguments.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=Complex64Array.of(1.0,-1.0,2.0,-2.0);// returns <Complex64Array>varlen=arr.length;// returns 2varz1=newComplex64(1.0,-1.0);varz2=newComplex64(2.0,-2.0);arr=Complex64Array.of(z1,z2);// returns <Complex64Array>len=arr.length;// returns 2

Complex64Array.prototype.at( i )

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(10);// Set the first, second, and last elements:arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([9.0,-9.0],9);// Get the first element:varz=arr.at(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns -1.0// Get the last element:z=arr.at(-1);// returns <Complex64>re=realf(z);// returns 9.0im=imagf(z);// returns -9.0

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

vararr=newComplex64Array(10);varz=arr.at(100);// returns undefinedz=arr.at(-100);// returns undefined

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

Copies a sequence of elements within the array starting atstart and ending atend (non-inclusive) to the position starting attarget.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(4);// Set the array elements:arr.set(newComplex64(1.0,-1.0),0);arr.set(newComplex64(2.0,-2.0),1);arr.set(newComplex64(3.0,-3.0),2);arr.set(newComplex64(4.0,-4.0),3);// Get the first array element:varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns -1.0// Get the second array element:z=arr.get(1);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns -2.0// Copy the last two elements to the first two elements:arr.copyWithin(0,2);// Get the first array element:z=arr.get(0);// returns <Complex64>re=realf(z);// returns 3.0im=imagf(z);// returns -3.0// Get the second array element:z=arr.get(1);// returns <Complex64>re=realf(z);// returns 4.0im=imagf(z);// 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 anend argument.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(4);// Set the array elements:arr.set(newComplex64(1.0,-1.0),0);arr.set(newComplex64(2.0,-2.0),1);arr.set(newComplex64(3.0,-3.0),2);arr.set(newComplex64(4.0,-4.0),3);// Get the third array element:varz=arr.get(2);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns -3.0// Get the last array element:z=arr.get(3);// returns <Complex64>re=realf(z);// returns 4.0im=imagf(z);// returns -4.0// Copy the first two elements to the last two elements:arr.copyWithin(2,0,2);// Get the third array element:z=arr.get(2);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// returns -1.0// Get the last array element:z=arr.get(3);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns -2.0

When atarget,start, and/orend 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:

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(4);// Set the array elements:arr.set(newComplex64(1.0,-1.0),0);arr.set(newComplex64(2.0,-2.0),1);arr.set(newComplex64(3.0,-3.0),2);arr.set(newComplex64(4.0,-4.0),3);// Get the third array element:varz=arr.get(2);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns -3.0// Get the last array element:z=arr.get(3);// returns <Complex64>re=realf(z);// returns 4.0im=imagf(z);// returns -4.0// Copy the first two elements to the last two elements using negative indices:arr.copyWithin(-2,-4,-2);// Get the third array element:z=arr.get(2);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// returns -1.0// Get the last array element:z=arr.get(3);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns -2.0

Complex64Array.prototype.entries()

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=[newComplex64(1.0,-1.0),newComplex64(2.0,-2.0),newComplex64(3.0,-3.0)];arr=newComplex64Array(arr);// Create an iterator:varit=arr.entries();// Iterate over the key-value pairs...varv=it.next().value;// returns [ 0, <Complex64> ]varre=realf(v[1]);// returns 1.0varim=imagf(v[1]);// returns -1.0v=it.next().value;// returns [ 1, <Complex64> ]re=realf(v[1]);// returns 2.0im=imagf(v[1]);// returns -2.0v=it.next().value;// returns [ 2, <Complex64> ]re=realf(v[1]);// returns 3.0im=imagf(v[1]);// returns -3.0varbool=it.next().done;// returns true

The returnediterator protocol-compliant object has the following properties:

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

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

Returns a boolean indicating whether all elements pass a test.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);// Check whether all elements pass a test:varz=arr.every(predicate);// returns true

Thepredicate 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 athisArg.

functionpredicate(v,i){this.count+=1;return(i>=0);}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.every(predicate,context);// returns truevarcount=context.count;// returns 3

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

Returns a modified typed array filled with a fill value.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(3);// Set all elements to the same value:arr.fill(newComplex64(1.0,1.0));varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns 1.0z=arr.get(2);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// returns 1.0// Fill all elements starting from the second element:arr.fill(newComplex64(2.0,2.0),1);z=arr.get(1);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns 2.0z=arr.get(2);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns 2.0// Fill all elements from first element until the second-to-last element:arr.fill(newComplex64(3.0,3.0),0,2);z=arr.get(0);// returns <Complex64>re=realf(z);// returns 3.0im=imagf(z);// returns 3.0z=arr.get(1);// returns <Complex64>re=realf(z);// returns 3.0im=imagf(z);// returns 3.0

When astart and/orend index is negative, the respective index is determined relative to the last array element.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(3);// Set all array elements, except the last element, to the same value:arr.fill(newComplex64(1.0,1.0),0,-1);varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns 1.0z=arr.get(arr.length-1);// returns <Complex64>re=realf(z);// returns 0.0im=imagf(z);// returns 0.0

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,-3.0],2);varout=arr.filter(predicate);// returns <Complex64Array>varlen=out.length;// returns 1varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns 2.0

Thepredicate 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 athisArg.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v,i){this.count+=1;return(i>=0&&realf(v)===imagf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varout=arr.filter(predicate,context);// returns <Complex64Array>varlen=out.length;// returns 2varcount=context.count;// returns 3

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.find(predicate);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns 1.0

Thepredicate 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 athisArg.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v,i){this.count+=1;return(i>=0&&realf(v)===imagf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.find(predicate,context);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns 2.0varcount=context.count;// returns 2

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,3.0],2);varidx=arr.findIndex(predicate);// returns 2

Thepredicate 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 athisArg.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v,i){this.count+=1;return(i>=0&&realf(v)===imagf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);varidx=arr.findIndex(predicate,context);// returns -1varcount=context.count;// returns 3

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.findLast(predicate);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 3.0

Thepredicate 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 athisArg.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v,i){this.count+=1;return(i>=0&&realf(v)===imagf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,-3.0],2);varz=arr.findLast(predicate,context);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns 2.0varcount=context.count;// returns 2

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,-3.0],2);varidx=arr.findLastIndex(predicate);// returns 1

Thepredicate 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 athisArg.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v,i){this.count+=1;return(i>=0&&realf(v)===imagf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);varidx=arr.findLastIndex(predicate,context);// returns -1varcount=context.count;// returns 3

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

Invokes a function once for each array element.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';functionlog(v,i){console.log('%s: %s',i,v.toString());}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);arr.forEach(log);/* =>    0: 1 + 1i    1: 2 + 2i    2: 3 + 3i*/

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 athisArg.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';functionfcn(v,i){this.count+=1;console.log('%s: %s',i,v.toString());}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);arr.forEach(fcn,context);/* =>    0: 1 + 1i    1: 2 + 2i    2: 3 + 3i*/varcount=context.count;// returns 3

Complex64Array.prototype.get( i )

Returns an array element located at a nonnegative integer position (index)i.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(10);// Set the first element:arr.set([1.0,-1.0],0);// Get the first element:varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns -1.0

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

vararr=newComplex64Array(10);varz=arr.get(100);// returns undefined

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

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=newComplex64Array(5);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);arr.set([4.0,-4.0],3);arr.set([5.0,-5.0],4);varbool=arr.includes(newComplex64(3.0,-3.0));// returns truebool=arr.includes(newComplex64(3.0,-3.0),3);// returns falsebool=arr.includes(newComplex64(4.0,-4.0),-3);// returns true

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

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=newComplex64Array(5);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);arr.set([4.0,-4.0],3);arr.set([2.0,-2.0],4);varidx=arr.indexOf(newComplex64(3.0,-3.0));// returns 2idx=arr.indexOf(newComplex64(2.0,-2.0),2);// returns 4idx=arr.indexOf(newComplex64(4.0,-4.0),-3);// returns 3

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=newComplex64Array(10);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);varidx=arr.indexOf(newComplex64(3.0,-3.0));// returns -1idx=arr.indexOf(newComplex64(1.0,-1.0),1);// returns -1

Complex64Array.prototype.join( [separator] )

Returns a new string by concatenating all array elements.

vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,3.0],2);varstr=arr.join();// returns '1 + 1i,2 - 2i,3 + 3i'

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

vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,3.0],2);varstr=arr.join('/');// returns '1 + 1i/2 - 2i/3 + 3i'

Complex64Array.prototype.keys()

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

vararr=newComplex64Array(2);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);variter=arr.keys();varv=iter.next().value;// returns 0v=iter.next().value;// returns 1varbool=iter.next().done;// returns true

The returnediterator protocol-compliant object has the following properties:

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

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

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=newComplex64Array(5);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);arr.set([4.0,-4.0],3);arr.set([2.0,-2.0],4);varidx=arr.lastIndexOf(newComplex64(3.0,-3.0));// returns 2idx=arr.lastIndexOf(newComplex64(2.0,-2.0),2);// returns 1idx=arr.lastIndexOf(newComplex64(4.0,-4.0),-1);// returns 3

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=newComplex64Array(10);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);varidx=arr.lastIndexOf(newComplex64(3.0,-3.0));// returns -1idx=arr.lastIndexOf(newComplex64(2.0,-2.0),0);// returns -1

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

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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionscale(v){returnnewComplex64(2.0*realf(v),2.0*imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,-3.0],2);varout=arr.map(scale);// returns <Complex64Array>varz=out.get(0);// returns <complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns -2.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 athisArg.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionscale(v){this.count+=1;returnnewComplex64(2.0*realf(v),2.0*imagf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varout=arr.map(scale,context);// returns <Complex64Array>varcount=context.count;// returns 3

Complex64Array.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.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importcaddffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-base-add@esm/index.mjs';vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.reduce(caddf);// returns <Complex64>varre=realf(z);// returns 6.0varim=imagf(z);// returns 6.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 asvalue during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element asvalue during the first invocation of the provided callback, provide aninitialValue argument.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';functionreducer(acc,v){acc+=realf(v);returnacc;}vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.reduce(reducer,0.0);// returns 6.0

Complex64Array.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.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importcaddffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-base-add@esm/index.mjs';vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.reduceRight(caddf);// returns <Complex64>varre=realf(z);// returns 6.0varim=imagf(z);// returns 6.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 asvalue during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element asvalue during the first invocation of the provided callback, provide aninitialValue argument.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';functionreducer(acc,v){acc+=realf(v);returnacc;}vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varz=arr.reduceRight(reducer,0.0);// returns 6.0

Complex64Array.prototype.reverse()

Reverses an array in-place.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varout=arr.reverse();// returns <Complex64Array>varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 3.0z=out.get(1);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns 2.0z=out.get(2);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// returns 1.0

Complex64Array.prototype.set( z[, i] )

Sets one or more array elements.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(10);// Get the first element:varz=arr.get(0);// returns <Complex64>varre=realf(z);// returns 0.0varim=imagf(z);// returns 0.0// Set the first element:arr.set(newComplex64(1.0,-1.0));// Get the first element:z=arr.get(0);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// 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 argumenti.

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(10);// Get the fifth element:varz=arr.get(4);// returns <Complex64>varre=realf(z);// returns 0.0varim=imagf(z);// returns 0.0// Set the fifth element:arr.set(newComplex64(1.0,-1.0),4);// Get the fifth element:z=arr.get(4);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// 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

importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(10);// Define an array of complex numbers:varbuf=[newComplex64(1.0,-1.0),newComplex64(2.0,-2.0),newComplex64(3.0,-3.0)];// Set the fifth, sixth, and seventh elements:arr.set(buf,4);// Get the sixth element:varz=arr.get(5);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns -2.0

or interleaved real and imaginary components

importFloat32Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(10);// Define an interleaved array of real and imaginary components:varbuf=newFloat32Array([1.0,-1.0,2.0,-2.0,3.0,-3.0]);// Set the fifth, sixth, and seventh elements:arr.set(buf,4);// Get the sixth element:varz=arr.get(5);// returns <Complex64>varre=realf(z);// returns 2.0varim=imagf(z);// returns -2.0

A few notes:

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

Complex64Array.prototype.slice( [start[, end]] )

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]);varout=arr.slice();// returns <Complex64Array>varlen=out.length;// returns 4varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns 2.0z=out.get(len-1);// returns <Complex64>re=realf(z);// returns 7.0im=imagf(z);// 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 astart index (inclusive).

importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';vararr=newComplex64Array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]);varout=arr.slice(1);// returns <Complex64Array>varlen=out.length;// returns 3varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 4.0

By default, the method returns a typed array which includes all array elements afterstart. To limit the number of array elements afterstart, provide anend index (exclusive).

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]);varout=arr.slice(1,-1);// returns <Complex64Array>varlen=out.length;// returns 2varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 4.0z=out.get(len-1);// returns <Complex64>re=realf(z);// returns 5.0im=imagf(z);// returns 6.0

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v){return(realf(v)===imagf(v));}vararr=newComplex64Array(3);// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,-3.0],2);// Check whether at least one element passes a test:varz=arr.some(predicate);// returns true

Thepredicate 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 athisArg.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functionpredicate(v,i){this.count+=1;return(imagf(v)===realf(v));}vararr=newComplex64Array(3);varcontext={'count':0};// Set the first three elements:arr.set([1.0,-1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,-3.0],2);varz=arr.some(predicate,context);// returns truevarcount=context.count;// returns 2

Complex64Array.prototype.sort( compareFcn )

Sorts an array in-place.

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functioncompare(a,b){varre1;varre2;varim1;varim2;re1=realf(a);re2=realf(b);if(re1<re2){return-1;}if(re1>re2){return1;}im1=imagf(a);im2=imagf(b);if(im1<im2){return-1;}if(im1>im2){return1;}return0;}vararr=newComplex64Array(3);arr.set([3.0,-3.0],0);arr.set([1.0,-1.0],1);arr.set([2.0,-2.0],2);varout=arr.sort(compare);// returns <Complex64Array>varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns -1.0z=out.get(1);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns -2.0z=out.get(2);// returns <Complex64>re=realf(z);// returns 3.0im=imagf(z);// returns -3.0

ThecompareFcn 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 thata should come beforeb.
  • a positive value indicates thata should come afterb.
  • zero orNaN indicates thata andb are considered equal.

In contrast to real numbers, one cannot define a default order relation which is compatible with multiplication. Accordingly, usersmust explicitly provide acompareFcn argument and are thus responsible for specifying a complex number ordering.

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

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]);varsubarr=arr.subarray();// returns <Complex64Array>varlen=subarr.length;// returns 4varz=subarr.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns 2.0z=subarr.get(len-1);// returns <Complex64>re=realf(z);// returns 7.0im=imagf(z);// 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 abegin index (inclusive).

importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';vararr=newComplex64Array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]);varsubarr=arr.subarray(1);// returns <Complex64Array>varlen=subarr.length;// returns 3varz=subarr.get(0);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 4.0

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]);varsubarr=arr.subarray(1,-1);// returns <Complex64Array>varlen=subarr.length;// returns 2varz=subarr.get(0);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 4.0z=subarr.get(len-1);// returns <Complex64>re=realf(z);// returns 5.0im=imagf(z);// returns 6.0

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

Serializes an array as a locale-specific string.

vararr=newComplex64Array(2);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);varstr=arr.toLocaleString();// returns '1 + 1i,2 + 2i'

The method supports the following arguments:

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

Complex64Array.prototype.toReversed()

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],2);varout=arr.toReversed();// returns <Complex64Array>varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 3.0varim=imagf(z);// returns 3.0z=out.get(1);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns 2.0z=out.get(2);// returns <Complex64>re=realf(z);// returns 1.0im=imagf(z);// returns 1.0

Complex64Array.prototype.toSorted( compareFcn )

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';functioncompare(a,b){varre1;varre2;varim1;varim2;re1=realf(a);re2=realf(b);if(re1<re2){return-1;}if(re1>re2){return1;}im1=imagf(a);im2=imagf(b);if(im1<im2){return-1;}if(im1>im2){return1;}return0;}vararr=newComplex64Array(3);arr.set([3.0,-3.0],0);arr.set([1.0,-1.0],1);arr.set([2.0,-2.0],2);varout=arr.toSorted(compare);// returns <Complex64Array>varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 1.0varim=imagf(z);// returns -1.0z=out.get(1);// returns <Complex64>re=realf(z);// returns 2.0im=imagf(z);// returns -2.0z=out.get(2);// returns <Complex64>re=realf(z);// returns 3.0im=imagf(z);// returns -3.0

ThecompareFcn 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 thata should come beforeb.
  • a positive value indicates thata should come afterb.
  • zero orNaN indicates thata andb are considered equal.

In contrast to real numbers, one cannot define a default order relation which is compatible with multiplication. Accordingly, usersmust explicitly provide acompareFcn argument and are thus responsible for specifying a complex number ordering.

Complex64Array.prototype.toString()

Serializes an array as a string.

vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,-2.0],1);arr.set([3.0,3.0],2);varstr=arr.toString();// returns '1 + 1i,2 - 2i,3 + 3i'

Complex64Array.prototype.values()

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';vararr=newComplex64Array(2);arr.set([1.0,-1.0],0);arr.set([2.0,-2.0],1);variter=arr.values();varv=iter.next().value;// returns <Complex64>varre=realf(v);// returns 1.0varim=imagf(v);// returns -1.0v=iter.next().value;// returns <Complex64>re=realf(v);// returns 2.0im=imagf(v);// returns -2.0varbool=iter.next().done;// returns true

The returnediterator protocol-compliant object has the following properties:

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

Complex64Array.prototype.with( index, value )

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

importrealffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-real@esm/index.mjs';importimagffrom'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-imag@esm/index.mjs';importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';vararr=newComplex64Array(3);arr.set([1.0,1.0],0);arr.set([2.0,2.0],1);arr.set([3.0,3.0],1);varout=arr.with(0,newComplex64(4.0,4.0));// returns <Complex64Array>varz=out.get(0);// returns <Complex64>varre=realf(z);// returns 4.0varim=imagf(z);// returns 4.0

Notes

  • While aComplex64Arraystrives to maintain (but does notguarantee) consistency withtyped arrays, significant deviations from ECMAScript-definedtyped array behavior are as follows:

    • The constructor doesnot require thenew operator.
    • The constructor and associated methods support a broader variety of input argument types in order to better accommodate complex number input.
    • Accessing array elements using bracket syntax (e.g.,Z[i]) isnot supported. Instead, onemust use the.get() method which returns a value compatible with complex number output.
    • Theset method has extended behavior in order to support complex numbers.

Examples

<!DOCTYPE html><htmllang="en"><body><scripttype="module">importComplex64from'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@esm/index.mjs';importFloat32Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs';importlogEachfrom'https://cdn.jsdelivr.net/gh/stdlib-js/console-log-each@esm/index.mjs';importComplex64Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-complex64@esm/index.mjs';// Create a complex array by specifying a length:varout=newComplex64Array(3);logEach('%s',out);// Create a complex array from an array of complex numbers:vararr=[newComplex64(1.0,-1.0),newComplex64(-3.14,3.14),newComplex64(0.5,0.5)];out=newComplex64Array(arr);logEach('%s',out);// Create a complex array from an interleaved typed array:arr=newFloat32Array([1.0,-1.0,-3.14,3.14,0.5,0.5]);out=newComplex64Array(arr);logEach('%s',out);// Create a complex array from an array buffer:arr=newFloat32Array([1.0,-1.0,-3.14,3.14,0.5,0.5]);out=newComplex64Array(arr.buffer);logEach('%s',out);// Create a complex array from an array buffer view:arr=newFloat32Array([1.0,-1.0,-3.14,3.14,0.5,0.5]);out=newComplex64Array(arr.buffer,8,2);logEach('%s',out);</script></body></html>

See Also


Notice

This package is part ofstdlib, a standard library 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 developstdlib, see the main projectrepository.

Community

Chat


License

SeeLICENSE.

Copyright

Copyright © 2016-2025. The StdlibAuthors.

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp