@stdlib/complex-float32 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/main.js DELETED
@@ -1,159 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
24
- var defineProperty = require( '@stdlib/utils-define-property' );
25
- var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
26
- var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
27
- var format = require( '@stdlib/string-format' );
28
- var toStr = require( './tostring.js' );
29
- var toJSON = require( './tojson.js' );
30
-
31
-
32
- // MAIN //
33
-
34
- /**
35
- * 64-bit complex number constructor.
36
- *
37
- * @constructor
38
- * @param {number} real - real component
39
- * @param {number} imag - imaginary component
40
- * @throws {TypeError} must invoke using the `new` keyword
41
- * @throws {TypeError} real component must be a number
42
- * @throws {TypeError} imaginary component must be a number
43
- * @returns {Complex64} 64-bit complex number
44
- *
45
- * @example
46
- * var z = new Complex64( 5.0, 3.0 );
47
- * // returns <Complex64>
48
- */
49
- function Complex64( real, imag ) {
50
- if ( !( this instanceof Complex64 ) ) {
51
- throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' );
52
- }
53
- if ( !isNumber( real ) ) {
54
- throw new TypeError( format( 'invalid argument. Real component must be a number. Value: `%s`.', real ) );
55
- }
56
- if ( !isNumber( imag ) ) {
57
- throw new TypeError( format( 'invalid argument. Imaginary component must be a number. Value: `%s`.', imag ) );
58
- }
59
- defineProperty( this, 're', {
60
- 'configurable': false,
61
- 'enumerable': true,
62
- 'writable': false,
63
- 'value': float64ToFloat32( real )
64
- });
65
- defineProperty( this, 'im', {
66
- 'configurable': false,
67
- 'enumerable': true,
68
- 'writable': false,
69
- 'value': float64ToFloat32( imag )
70
- });
71
- return this;
72
- }
73
-
74
- /**
75
- * Size (in bytes) of each component.
76
- *
77
- * @name BYTES_PER_ELEMENT
78
- * @memberof Complex64
79
- * @type {integer}
80
- * @returns {integer} size of each component
81
- *
82
- * @example
83
- * var nbytes = Complex64.BYTES_PER_ELEMENT;
84
- * // returns 4
85
- */
86
- setReadOnly( Complex64, 'BYTES_PER_ELEMENT', 4 );
87
-
88
- /**
89
- * Size (in bytes) of each component.
90
- *
91
- * @name BYTES_PER_ELEMENT
92
- * @memberof Complex64.prototype
93
- * @type {integer}
94
- * @returns {integer} size of each component
95
- *
96
- * @example
97
- * var z = new Complex64( 5.0, 3.0 );
98
- *
99
- * var nbytes = z.BYTES_PER_ELEMENT;
100
- * // returns 4
101
- */
102
- setReadOnly( Complex64.prototype, 'BYTES_PER_ELEMENT', 4 );
103
-
104
- /**
105
- * Length (in bytes) of a complex number.
106
- *
107
- * @name byteLength
108
- * @memberof Complex64.prototype
109
- * @type {integer}
110
- * @returns {integer} byte length
111
- *
112
- * @example
113
- * var z = new Complex64( 5.0, 3.0 );
114
- *
115
- * var nbytes = z.byteLength;
116
- * // returns 8
117
- */
118
- setReadOnly( Complex64.prototype, 'byteLength', 8 );
119
-
120
- /**
121
- * Serializes a complex number as a string.
122
- *
123
- * @name toString
124
- * @memberof Complex64.prototype
125
- * @type {Function}
126
- * @returns {string} serialized complex number
127
- *
128
- * @example
129
- * var z = new Complex64( 5.0, 3.0 );
130
- *
131
- * var str = z.toString();
132
- * // returns '5 + 3i'
133
- */
134
- setReadOnly( Complex64.prototype, 'toString', toStr );
135
-
136
- /**
137
- * Serializes a complex number as a JSON object.
138
- *
139
- * ## Notes
140
- *
141
- * - `JSON.stringify()` implicitly calls this method when stringifying a `Complex64` instance.
142
- *
143
- * @name toJSON
144
- * @memberof Complex64.prototype
145
- * @type {Function}
146
- * @returns {Object} serialized complex number
147
- *
148
- * @example
149
- * var z = new Complex64( 5.0, 3.0 );
150
- *
151
- * var obj = z.toJSON();
152
- * // returns { 'type': 'Complex64', 're': 5.0, 'im': 3.0 }
153
- */
154
- setReadOnly( Complex64.prototype, 'toJSON', toJSON );
155
-
156
-
157
- // EXPORTS //
158
-
159
- module.exports = Complex64;
package/lib/tojson.js DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 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
- * Serializes a complex number as a JSON object.
23
- *
24
- * @private
25
- * @returns {Object} JSON representation
26
- */
27
- function toJSON() {
28
- /* eslint-disable no-invalid-this */
29
- var out = {};
30
- out.type = 'Complex64';
31
- out.re = this.re;
32
- out.im = this.im;
33
- return out;
34
- }
35
-
36
-
37
- // EXPORTS //
38
-
39
- module.exports = toJSON;
package/lib/tostring.js DELETED
@@ -1,42 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 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
- * Serializes a complex number as a string.
23
- *
24
- * @private
25
- * @returns {string} serialized complex number
26
- */
27
- function toString() { // eslint-disable-line stdlib/no-redeclare
28
- /* eslint-disable no-invalid-this */
29
- var str = '' + this.re;
30
- if ( this.im < 0 ) {
31
- str += ' - ' + (-this.im);
32
- } else {
33
- str += ' + ' + this.im;
34
- }
35
- str += 'i';
36
- return str;
37
- }
38
-
39
-
40
- // EXPORTS //
41
-
42
- module.exports = toString;
package/manifest.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [
28
- "./src/main.c"
29
- ],
30
- "include": [
31
- "./include"
32
- ],
33
- "libraries": [],
34
- "libpath": [],
35
- "dependencies": []
36
- }
37
- ]
38
- }
package/src/main.c DELETED
@@ -1,151 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2021 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
- #include "stdlib/complex/float32.h"
20
- #include <stdint.h>
21
-
22
- /**
23
- * Returns a single-precision complex floating-point number.
24
- *
25
- * @param real real component
26
- * @param imag imaginary component
27
- * @return single-precision complex floating-point number
28
- *
29
- * @example
30
- * stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
31
- */
32
- stdlib_complex64_t stdlib_complex64( const float real, const float imag ) {
33
- stdlib_complex64_parts_t z;
34
- z.parts[ 0 ] = real;
35
- z.parts[ 1 ] = imag; // cppcheck-suppress unreadVariable
36
- return z.value;
37
- }
38
-
39
- /**
40
- * Converts a single-precision floating-point number to a single-precision complex floating-point number.
41
- *
42
- * @param real real component
43
- * @return single-precision complex floating-point number
44
- *
45
- * @example
46
- * stdlib_complex64_t z = stdlib_complex64_from_float32( 5.0f );
47
- */
48
- stdlib_complex64_t stdlib_complex64_from_float32( const float real ) {
49
- stdlib_complex64_parts_t z;
50
- z.parts[ 0 ] = real;
51
- z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable
52
- return z.value;
53
- }
54
-
55
- /**
56
- * Converts a double-precision floating-point number to a single-precision complex floating-point number.
57
- *
58
- * @param real real component
59
- * @return single-precision complex floating-point number
60
- *
61
- * @example
62
- * stdlib_complex64_t z = stdlib_complex64_from_float64( 5.0 );
63
- */
64
- stdlib_complex64_t stdlib_complex64_from_float64( const double real ) {
65
- stdlib_complex64_parts_t z;
66
- z.parts[ 0 ] = (float)real;
67
- z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable
68
- return z.value;
69
- }
70
-
71
- /**
72
- * Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number.
73
- *
74
- * @param z single-precision complex floating-point number
75
- * @return single-precision complex floating-point number
76
- *
77
- * @example
78
- * stdlib_complex64_t z1 = stdlib_complex64( 5.0f, 3.0f );
79
- * stdlib_complex64_t z2 = stdlib_complex64_from_complex64( z1 );
80
- */
81
- stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z ) {
82
- stdlib_complex64_parts_t v1 = { z };
83
- stdlib_complex64_parts_t v2;
84
- v2.parts[ 0 ] = v1.parts[ 0 ];
85
- v2.parts[ 1 ] = v1.parts[ 1 ]; // cppcheck-suppress unreadVariable
86
- return v2.value;
87
- }
88
-
89
- /**
90
- * Converts a signed 8-bit integer to a single-precision complex floating-point number.
91
- *
92
- * @param real real component
93
- * @return single-precision complex floating-point number
94
- *
95
- * @example
96
- * stdlib_complex64_t z = stdlib_complex64_from_int8( 5 );
97
- */
98
- stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real ) {
99
- stdlib_complex64_parts_t z;
100
- z.parts[ 0 ] = (float)real;
101
- z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable
102
- return z.value;
103
- }
104
-
105
- /**
106
- * Converts an unsigned 8-bit integer to a single-precision complex floating-point number.
107
- *
108
- * @param real real component
109
- * @return single-precision complex floating-point number
110
- *
111
- * @example
112
- * stdlib_complex64_t z = stdlib_complex64_from_uint8( 5 );
113
- */
114
- stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real ) {
115
- stdlib_complex64_parts_t z;
116
- z.parts[ 0 ] = (float)real;
117
- z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable
118
- return z.value;
119
- }
120
-
121
- /**
122
- * Converts a signed 16-bit integer to a single-precision complex floating-point number.
123
- *
124
- * @param real real component
125
- * @return single-precision complex floating-point number
126
- *
127
- * @example
128
- * stdlib_complex64_t z = stdlib_complex64_from_int16( 5 );
129
- */
130
- stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real ) {
131
- stdlib_complex64_parts_t z;
132
- z.parts[ 0 ] = (float)real;
133
- z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable
134
- return z.value;
135
- }
136
-
137
- /**
138
- * Converts an unsigned 16-bit integer to a single-precision complex floating-point number.
139
- *
140
- * @param real real component
141
- * @return single-precision complex floating-point number
142
- *
143
- * @example
144
- * stdlib_complex64_t z = stdlib_complex64_from_uint16( 5 );
145
- */
146
- stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real ) {
147
- stdlib_complex64_parts_t z;
148
- z.parts[ 0 ] = (float)real;
149
- z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable
150
- return z.value;
151
- }