Skip to content

Commit b73e897

Browse files
committed
feat: add complex/float32/base/scale
1 parent 4d38ce8 commit b73e897

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
// MODULES //
22+
23+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Scales a single-precision complex floating-point number by a real-valued single-precision floating-point scalar constant and assigns results to a provided output array.
30+
*
31+
* @param {number} alpha - scalar constant
32+
* @param {number} re - real component of the complex number
33+
* @param {number} im - imaginary component of the complex number
34+
* @param {Collection} out - output array
35+
* @param {integer} strideOut - stride length
36+
* @param {NonNegativeInteger} offsetOut - starting index
37+
* @returns {Collection} output array
38+
*
39+
* @example
40+
* var Float32Array = require( '@stdlib/array/float32' );
41+
*
42+
* var out = assign( 5.0, 5.0, 3.0, new Float32Array( 2 ), 1, 0 );
43+
* // returns <Float32Array>[ 25.0, 15.0 ]
44+
*/
45+
function assign( alpha, re, im, out, strideOut, offsetOut ) {
46+
out[ offsetOut ] = float64ToFloat32( re * alpha );
47+
out[ offsetOut+strideOut ] = float64ToFloat32( im * alpha );
48+
return out;
49+
}
50+
51+
52+
// EXPORTS //
53+
54+
module.exports = assign;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
/**
22+
* Scale a single-precision complex floating-point number by a real-valued single-precision floating-point scalar constant.
23+
*
24+
* @module @stdlib/complex/float32/base/scale
25+
*
26+
* @example
27+
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
* var real = require( '@stdlib/complex/float32/real' );
29+
* var imag = require( '@stdlib/complex/float32/imag' );
30+
* var scale = require( '@stdlib/complex/float32/base/scale' );
31+
*
32+
* var z = new Complex64( 5.0, 3.0 );
33+
* // returns <Complex64>
34+
*
35+
* var out = scale( scalar, z );
36+
* // returns <Complex64>
37+
*
38+
* var re = real( out );
39+
* // returns 25.0
40+
*
41+
* var im = imag( out );
42+
* // returns 15.0
43+
*/
44+
45+
// MODULES //
46+
47+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
48+
var main = require( './main.js' );
49+
var assign = require( './assign.js' );
50+
var strided = require( './strided.js' );
51+
52+
53+
// MAIN //
54+
55+
setReadOnly( main, 'assign', assign );
56+
setReadOnly( main, 'strided', strided );
57+
58+
59+
// EXPORTS //
60+
61+
module.exports = main;
62+
63+
// exports: { "assign": "main.assign", "strided": "main.strided" }
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
// MODULES //
22+
23+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
24+
var real = require( '@stdlib/complex/float32/real' );
25+
var imag = require( '@stdlib/complex/float32/imag' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Scales a single-precision complex floating-point number by a real-valued single-precision floating-point scalar constant.
32+
*
33+
* @param {number} alpha - scalar constant
34+
* @param {Complex64} z - complex number
35+
* @returns {Complex64} result
36+
*
37+
* @example
38+
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
39+
* var real = require( '@stdlib/complex/float32/real' );
40+
* var imag = require( '@stdlib/complex/float32/imag' );
41+
*
42+
* var z = new Complex64( 5.0, 3.0 );
43+
* // returns <Complex64>
44+
*
45+
* var out = scale( 5.0, z );
46+
* // returns <Complex64>
47+
*
48+
* var re = real( out );
49+
* // returns 25.0
50+
*
51+
* var im = imag( out );
52+
* // returns 15.0
53+
*/
54+
function scale( alpha, z ) {
55+
return new Complex64( real( z ) * alpha, imag( z ) * alpha );
56+
}
57+
58+
59+
// EXPORTS //
60+
61+
module.exports = scale;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
// MODULES //
22+
23+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
24+
var addon = require( './../src/addon.node' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Scales a single-precision complex floating-point number by a real-valued single-precision floating-point scalar constant.
31+
*
32+
* @private
33+
* @param {number} alpha - scalar constant
34+
* @param {Complex64} z - complex number
35+
* @returns {Complex64} result
36+
*
37+
* @example
38+
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
39+
* var real = require( '@stdlib/complex/float32/real' );
40+
* var imag = require( '@stdlib/complex/float32/imag' );
41+
*
42+
* var z = new Complex64( 5.0, 3.0 );
43+
* // returns <Complex64>
44+
*
45+
* var out = scale( 5.0, z );
46+
* // returns <Complex64>
47+
*
48+
* var re = real( out );
49+
* // returns 25.0
50+
*
51+
* var im = imag( out );
52+
* // returns 15.0
53+
*/
54+
function scale( alpha, z ) {
55+
var v = addon( alpha, z );
56+
return new Complex64( v.re, v.im );
57+
}
58+
59+
60+
// EXPORTS //
61+
62+
module.exports = scale;

0 commit comments

Comments
 (0)