Skip to content

Commit ed20cbf

Browse files
committed
feat: add /complex/float32/base/add
1 parent 8785e54 commit ed20cbf

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Adds two single-precision complex floating-point numbers and assigns results to a provided output array.
25+
*
26+
* @param {number} re1 - real component of the first complex number
27+
* @param {number} im1 - imaginary component of the first complex number
28+
* @param {number} re2 - real component of the second complex number
29+
* @param {number} im2 - imaginary component of the second complex number
30+
* @param {Collection} out - output array
31+
* @param {integer} strideOut - stride length
32+
* @param {NonNegativeInteger} offsetOut - starting index
33+
* @returns {Collection} output array
34+
*
35+
* @example
36+
* var Float32Array = require( '@stdlib/array/float32' );
37+
*
38+
* var out = assign( 5.0, 3.0, -2.0, 1.0, new Float32Array( 2 ), 1, 0 );
39+
* // returns <Float32Array>[ 3.0, 4.0 ]
40+
*/
41+
function assign( re1, im1, re2, im2, out, strideOut, offsetOut ) {
42+
out[ offsetOut ] = re1 + re2;
43+
out[ offsetOut+strideOut ] = im1 + im2;
44+
return out;
45+
}
46+
47+
48+
// EXPORTS //
49+
50+
module.exports = assign;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Adds two single-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array.
25+
*
26+
* @param {Float64Array} z1 - first complex number view
27+
* @param {integer} strideZ1 - stride length for `z1`
28+
* @param {NonNegativeInteger} offsetZ1 - starting index for `z1`
29+
* @param {Float64Array} z2 - second complex number view
30+
* @param {integer} strideZ2 - stride length for `z2`
31+
* @param {NonNegativeInteger} offsetZ2 - starting index for `z2`
32+
* @param {Collection} out - output array
33+
* @param {integer} strideOut - stride length for `out`
34+
* @param {NonNegativeInteger} offsetOut - starting index for `out`
35+
* @returns {Collection} output array
36+
*
37+
* @example
38+
* var Float32Array = require( '@stdlib/array/float32' );
39+
*
40+
* var z1 = new Float32Array( [ 5.0, 3.0 ] );
41+
* var z2 = new Float32Array( [ -2.0, 1.0 ] );
42+
*
43+
* var out = strided( z1, 1, 0, z2, 1, 0, new Float32Array( 2 ), 1, 0 );
44+
* // returns <Float32Array>[ 3.0, 4.0 ]
45+
*/
46+
function strided( z1, strideZ1, offsetZ1, z2, strideZ2, offsetZ2, out, strideOut, offsetOut ) { // eslint-disable-line max-len
47+
out[ offsetOut ] = z1[ offsetZ1 ] + z2[ offsetZ2 ];
48+
out[ offsetOut+strideOut ] = z1[ offsetZ1+strideZ1 ] + z2[ offsetZ2+strideZ2 ]; // eslint-disable-line max-len
49+
return out;
50+
}
51+
52+
53+
// EXPORTS //
54+
55+
module.exports = strided;

0 commit comments

Comments
 (0)