@stdlib/complex-float32 0.2.1 → 0.4.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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2021 The Stdlib Authors.
4
+ * Copyright (c) 2024 The Stdlib Authors.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -18,94 +18,134 @@
18
18
 
19
19
  // TypeScript Version: 4.1
20
20
 
21
+ /* eslint-disable max-lines */
22
+
23
+ import base = require( '@stdlib/complex-float32-base' );
24
+ import conj = require( '@stdlib/complex-float32-conj' );
25
+ import Complex64 = require( '@stdlib/complex-float32-ctor' );
26
+ import imag = require( '@stdlib/complex-float32-imag' );
27
+ import parseComplex64 = require( '@stdlib/complex-float32-parse' );
28
+ import real = require( '@stdlib/complex-float32-real' );
29
+ import reim = require( '@stdlib/complex-float32-reim' );
30
+ import reviveComplex64 = require( '@stdlib/complex-float32-reviver' );
31
+
21
32
  /**
22
- * 64-bit complex number.
33
+ * Interface describing the `float32` namespace.
23
34
  */
24
- declare class Complex64 {
35
+ interface Namespace {
36
+ /**
37
+ * Base (i.e., lower-level) single-precision complex number functions.
38
+ */
39
+ base: typeof base;
40
+
25
41
  /**
26
- * 64-bit complex number constructor.
42
+ * Returns the complex conjugate of a single-precision complex floating-point number.
27
43
  *
28
- * @param real - real component
29
- * @param imag - imaginary component
30
- * @returns 64-bit complex number
44
+ * @param z - complex number
45
+ * @returns complex conjugate
31
46
  *
32
47
  * @example
48
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
49
+ *
33
50
  * var z = new Complex64( 5.0, 3.0 );
34
- * // returns <Complex64>
51
+ *
52
+ * var v = ns.conj( z );
53
+ * // returns <Complex64>[ 5.0, -3.0 ]
35
54
  */
36
- constructor( real: number, imag: number );
55
+ conj: typeof conj;
37
56
 
38
57
  /**
39
- * Read-only property returning the real component.
40
- *
41
- * @returns real component
58
+ * 64-bit complex number.
42
59
  */
43
- readonly re: number;
60
+ Complex64: typeof Complex64;
44
61
 
45
62
  /**
46
- * Read-only property returning the imaginary component.
63
+ * Returns the imaginary component of a single-precision complex floating-point number.
47
64
  *
65
+ * @param z - complex number
48
66
  * @returns imaginary component
67
+ *
68
+ * @example
69
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
70
+ *
71
+ * var z = new Complex64( 5.0, 3.0 );
72
+ *
73
+ * var im = ns.imag( z );
74
+ * // returns 3.0
49
75
  */
50
- readonly im: number;
76
+ imag: typeof imag;
51
77
 
52
78
  /**
53
- * Size (in bytes) of each component.
79
+ * Parse a string representation of a 64-bit complex number.
54
80
  *
55
- * @returns size of each component
81
+ * @param str - string representation of a complex number
82
+ * @throws must provide a string recognized as a complex number
83
+ * @returns Complex64 instance
56
84
  *
57
85
  * @example
58
- * var nbytes = Complex64.BYTES_PER_ELEMENT;
59
- * // returns 4
86
+ * var str = '5 + 3i';
87
+ *
88
+ * var z = ns.parseComplex64( str );
89
+ * // returns <Complex64>
60
90
  */
61
- readonly BYTES_PER_ELEMENT: 4;
91
+ parseComplex64: typeof parseComplex64;
62
92
 
63
93
  /**
64
- * Length (in bytes) of a complex number.
94
+ * Returns the real component of a single-precision complex floating-point number.
65
95
  *
66
- * @returns byte length
96
+ * @param z - complex number
97
+ * @returns real component
67
98
  *
68
99
  * @example
100
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
101
+ *
69
102
  * var z = new Complex64( 5.0, 3.0 );
70
103
  *
71
- * var nbytes = z.byteLength;
72
- * // returns 8
104
+ * var re = ns.real( z );
105
+ * // returns 5.0
73
106
  */
74
- readonly byteLength: 8;
107
+ real: typeof real;
75
108
 
76
109
  /**
77
- * Serializes a complex number as a string.
110
+ * Returns the real and imaginary components of a single-precision complex floating-point number.
78
111
  *
79
- * @returns serialized complex number
112
+ * @param z - complex number
113
+ * @returns real and imaginary components
80
114
  *
81
115
  * @example
116
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
117
+ *
82
118
  * var z = new Complex64( 5.0, 3.0 );
83
119
  *
84
- * var str = z.toString();
85
- * // returns '5 + 3i'
120
+ * var out = ns.reim( z );
121
+ * // returns <Float32Array>[ 5.0, 3.0 ]
86
122
  */
87
- toString(): string;
123
+ reim: typeof reim;
88
124
 
89
125
  /**
90
- * Serializes a complex number as a JSON object.
91
- *
92
- * ## Notes
93
- *
94
- * - `JSON.stringify()` implicitly calls this method when stringifying a `Complex64` instance.
126
+ * Revives a JSON-serialized 64-bit complex number.
95
127
  *
96
- *
97
- * @returns serialized complex number
128
+ * @param key - key
129
+ * @param value - value
130
+ * @returns value or 64-bit complex number
98
131
  *
99
132
  * @example
100
- * var z = new Complex64( 5.0, 3.0 );
133
+ * var parseJSON = require( '@stdlib/utils-parse-json' );
101
134
  *
102
- * var obj = z.toJSON();
103
- * // returns { 'type': 'Complex64', 're': 5.0, 'im': 3.0 }
135
+ * var str = '{"type":"Complex64","re":5,"im":3}';
136
+ *
137
+ * var z = parseJSON( str, ns.reviveComplex64 );
138
+ * // returns <Complex64>
104
139
  */
105
- toJSON(): any;
140
+ reviveComplex64: typeof reviveComplex64;
106
141
  }
107
142
 
143
+ /**
144
+ * Single-precision complex number functions.
145
+ */
146
+ declare var ns: Namespace;
147
+
108
148
 
109
149
  // EXPORTS //
110
150
 
111
- export = Complex64;
151
+ export = ns;
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2018 The Stdlib Authors.
4
+ * Copyright (c) 2024 The Stdlib Authors.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -18,23 +18,97 @@
18
18
 
19
19
  'use strict';
20
20
 
21
+ /*
22
+ * When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
23
+ */
24
+
25
+ // MODULES //
26
+
27
+ var setReadOnly = require( '@stdlib/utils-define-read-only-property' );
28
+
29
+
30
+ // MAIN //
31
+
21
32
  /**
22
- * 64-bit complex number constructor.
23
- *
24
- * @module @stdlib/complex-float32
33
+ * Top-level namespace.
25
34
  *
26
- * @example
27
- * var Complex64 = require( '@stdlib/complex-float32' );
28
- *
29
- * var z = new Complex64( 5.0, 3.0 );
30
- * // returns <Complex64>
35
+ * @namespace ns
31
36
  */
37
+ var ns = {};
32
38
 
33
- // MODULES //
39
+ /**
40
+ * @name base
41
+ * @memberof ns
42
+ * @readonly
43
+ * @type {Namespace}
44
+ * @see {@link module:@stdlib/complex/float32/base}
45
+ */
46
+ setReadOnly( ns, 'base', require( '@stdlib/complex-float32-base' ) );
47
+
48
+ /**
49
+ * @name conj
50
+ * @memberof ns
51
+ * @readonly
52
+ * @type {Function}
53
+ * @see {@link module:@stdlib/complex/float32/conj}
54
+ */
55
+ setReadOnly( ns, 'conj', require( '@stdlib/complex-float32-conj' ) );
56
+
57
+ /**
58
+ * @name Complex64
59
+ * @memberof ns
60
+ * @readonly
61
+ * @constructor
62
+ * @see {@link module:@stdlib/complex/float32/ctor}
63
+ */
64
+ setReadOnly( ns, 'Complex64', require( '@stdlib/complex-float32-ctor' ) );
65
+
66
+ /**
67
+ * @name imag
68
+ * @memberof ns
69
+ * @readonly
70
+ * @type {Function}
71
+ * @see {@link module:@stdlib/complex/float32/imag}
72
+ */
73
+ setReadOnly( ns, 'imag', require( '@stdlib/complex-float32-imag' ) );
74
+
75
+ /**
76
+ * @name parseComplex64
77
+ * @memberof ns
78
+ * @readonly
79
+ * @type {Function}
80
+ * @see {@link module:@stdlib/complex/float32/parse}
81
+ */
82
+ setReadOnly( ns, 'parseComplex64', require( '@stdlib/complex-float32-parse' ) );
34
83
 
35
- var main = require( './main.js' );
84
+ /**
85
+ * @name real
86
+ * @memberof ns
87
+ * @readonly
88
+ * @type {Function}
89
+ * @see {@link module:@stdlib/complex/float32/real}
90
+ */
91
+ setReadOnly( ns, 'real', require( '@stdlib/complex-float32-real' ) );
92
+
93
+ /**
94
+ * @name reim
95
+ * @memberof ns
96
+ * @readonly
97
+ * @type {Function}
98
+ * @see {@link module:@stdlib/complex/float32/reim}
99
+ */
100
+ setReadOnly( ns, 'reim', require( '@stdlib/complex-float32-reim' ) );
101
+
102
+ /**
103
+ * @name reviveComplex64
104
+ * @memberof ns
105
+ * @readonly
106
+ * @type {Function}
107
+ * @see {@link module:@stdlib/complex/float32/reviver}
108
+ */
109
+ setReadOnly( ns, 'reviveComplex64', require( '@stdlib/complex-float32-reviver' ) );
36
110
 
37
111
 
38
112
  // EXPORTS //
39
113
 
40
- module.exports = main;
114
+ module.exports = ns;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stdlib/complex-float32",
3
- "version": "0.2.1",
4
- "description": "64-bit complex number.",
3
+ "version": "0.4.0",
4
+ "description": "Single-precision complex number functions.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
7
7
  "name": "The Stdlib Authors",
@@ -13,12 +13,10 @@
13
13
  "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
14
  }
15
15
  ],
16
- "main": "./lib",
16
+ "main": "lib/index.js",
17
17
  "directories": {
18
18
  "doc": "./docs",
19
- "include": "./include",
20
19
  "lib": "./lib",
21
- "src": "./src",
22
20
  "dist": "./dist"
23
21
  },
24
22
  "types": "./docs/types",
@@ -32,11 +30,15 @@
32
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
33
31
  },
34
32
  "dependencies": {
35
- "@stdlib/assert-is-number": "^0.2.1",
36
- "@stdlib/number-float64-base-to-float32": "^0.2.1",
37
- "@stdlib/string-format": "^0.2.1",
38
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",
39
- "@stdlib/utils-define-property": "^0.2.1"
33
+ "@stdlib/complex-float32-base": "^0.1.1",
34
+ "@stdlib/complex-float32-conj": "^0.1.1",
35
+ "@stdlib/complex-float32-ctor": "^0.1.0",
36
+ "@stdlib/complex-float32-imag": "^0.1.1",
37
+ "@stdlib/complex-float32-parse": "^0.0.2",
38
+ "@stdlib/complex-float32-real": "^0.1.1",
39
+ "@stdlib/complex-float32-reim": "^0.1.2",
40
+ "@stdlib/complex-float32-reviver": "^0.0.2",
41
+ "@stdlib/utils-define-read-only-property": "^0.2.2"
40
42
  },
41
43
  "devDependencies": {},
42
44
  "engines": {
@@ -58,16 +60,12 @@
58
60
  "stdlib",
59
61
  "stdtypes",
60
62
  "types",
61
- "data",
62
- "structure",
63
63
  "complex",
64
- "complex64",
65
- "64-bit",
66
- "float32",
67
- "float",
68
- "single",
69
- "single-precision",
70
- "ieee754"
64
+ "cmplx",
65
+ "number",
66
+ "namespace",
67
+ "ns",
68
+ "float32"
71
69
  ],
72
70
  "funding": {
73
71
  "type": "opencollective",
@@ -1,148 +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
- #ifndef STDLIB_COMPLEX_FLOAT32_H
20
- #define STDLIB_COMPLEX_FLOAT32_H
21
-
22
- #include <complex.h>
23
- #include <stdint.h>
24
-
25
- /*
26
- * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
27
- */
28
- #ifdef __cplusplus
29
- extern "C" {
30
- #endif
31
-
32
- // Check for C11 support where we can precisely define a complex number and thus avoid issues concerning infinities and NaNs as real and/or imaginary components... (TODO: revisit the following check; similar to NumPy, we may want to check for a compile time variable (e.g., STDLIB_USE_C99_COMPLEX), rather than checking for C11 support, especially if we are not using C11 functionality)
33
- #if defined(_Imaginary_I) && defined(CMPLXF)
34
-
35
- /**
36
- * An opaque type definition for a single-precision complex floating-point number.
37
- */
38
- typedef float complex stdlib_complex64_t;
39
-
40
- // If we aren't going to use the native complex number type, we need to define a complex number as an "opaque" struct (here, "opaque" meaning type consumers should **not** be accessing the components directly, but only through dedicated functions) for storing the real and imaginary components...
41
- #else
42
-
43
- /**
44
- * An opaque type definition for a single-precision complex floating-point number.
45
- *
46
- * @example
47
- * stdlib_complex64_t z;
48
- *
49
- * // Set the real component:
50
- * z.re = 5.0f;
51
- *
52
- * // Set the imaginary component:
53
- * z.im = 2.0f;
54
- */
55
- typedef struct {
56
- /**
57
- * Real component.
58
- */
59
- float re;
60
-
61
- /**
62
- * Imaginary component.
63
- */
64
- float im;
65
- } stdlib_complex64_t;
66
-
67
- #endif
68
-
69
- /**
70
- * An opaque type definition for a union for accessing the real and imaginary parts of a single-precision complex floating-point number.
71
- *
72
- * @example
73
- * float realf( const stdlib_complex64_t z ) {
74
- * stdlib_complex64_parts_t v;
75
- *
76
- * // Assign a single-precision complex floating-point number:
77
- * v.value = z;
78
- *
79
- * // Extract the real component:
80
- * float re = v.parts[ 0 ];
81
- *
82
- * return re;
83
- * }
84
- *
85
- * // ...
86
- *
87
- * // Create a complex number:
88
- * stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
89
- *
90
- * // ...
91
- *
92
- * // Access the real component:
93
- * float re = realf( z );
94
- * // returns 5.0f
95
- */
96
- typedef union {
97
- // An opaque type for the output value (e.g., could be a `struct` or a C99 complex number):
98
- stdlib_complex64_t value;
99
-
100
- // Leverage the fact that C99 specifies that complex numbers have the same representation and alignment as a two-element array (see <https://en.cppreference.com/w/c/language/arithmetic_types#Complex_floating_types>), where the first element is the real component and the second element is the imaginary component, thus allowing us to create a complex number irrespective of its native data type (e.g., `struct` vs `float complex`):
101
- float parts[ 2 ];
102
- } stdlib_complex64_parts_t;
103
-
104
- /**
105
- * Returns a single-precision complex floating-point number.
106
- */
107
- stdlib_complex64_t stdlib_complex64( const float real, const float imag );
108
-
109
- /**
110
- * Converts a single-precision floating-point number to a single-precision complex floating-point number.
111
- */
112
- stdlib_complex64_t stdlib_complex64_from_float32( const float real );
113
-
114
- /**
115
- * Converts a double-precision floating-point number to a single-precision complex floating-point number.
116
- */
117
- stdlib_complex64_t stdlib_complex64_from_float64( const double real );
118
-
119
- /**
120
- * Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number.
121
- */
122
- stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z );
123
-
124
- /**
125
- * Converts a signed 8-bit integer to a single-precision complex floating-point number.
126
- */
127
- stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real );
128
-
129
- /**
130
- * Converts an unsigned 8-bit integer to a single-precision complex floating-point number.
131
- */
132
- stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real );
133
-
134
- /**
135
- * Converts a signed 16-bit integer to a single-precision complex floating-point number.
136
- */
137
- stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real );
138
-
139
- /**
140
- * Converts an unsigned 16-bit integer to a single-precision complex floating-point number.
141
- */
142
- stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real );
143
-
144
- #ifdef __cplusplus
145
- }
146
- #endif
147
-
148
- #endif // !STDLIB_COMPLEX_FLOAT32_H
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;