@stdlib/complex-float32 0.2.1 → 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/README.md +45 -446
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -7
- package/dist/index.js.map +4 -4
- package/docs/types/index.d.ts +89 -41
- package/lib/index.js +86 -12
- package/package.json +17 -19
- package/include/stdlib/complex/float32.h +0 -148
- package/lib/main.js +0 -159
- package/lib/tojson.js +0 -39
- package/lib/tostring.js +0 -42
- package/manifest.json +0 -38
- package/src/main.c +0 -151
package/docs/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @license Apache-2.0
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
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,142 @@
|
|
|
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
|
-
*
|
|
33
|
+
* Interface describing the `float32` namespace.
|
|
23
34
|
*/
|
|
24
|
-
|
|
35
|
+
interface Namespace {
|
|
36
|
+
/**
|
|
37
|
+
* Base (i.e., lower-level) single-precision complex number functions.
|
|
38
|
+
*/
|
|
39
|
+
base: typeof base;
|
|
40
|
+
|
|
25
41
|
/**
|
|
26
|
-
*
|
|
42
|
+
* Returns the complex conjugate of a single-precision complex floating-point number.
|
|
27
43
|
*
|
|
28
|
-
* @param
|
|
29
|
-
* @
|
|
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
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
50
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
51
|
+
*
|
|
33
52
|
* var z = new Complex64( 5.0, 3.0 );
|
|
53
|
+
*
|
|
54
|
+
* var v = ns.conj( z );
|
|
34
55
|
* // returns <Complex64>
|
|
56
|
+
*
|
|
57
|
+
* var re = realf( v );
|
|
58
|
+
* // returns 5.0
|
|
59
|
+
*
|
|
60
|
+
* var im = imagf( v );
|
|
61
|
+
* // returns -3.0
|
|
35
62
|
*/
|
|
36
|
-
|
|
63
|
+
conj: typeof conj;
|
|
37
64
|
|
|
38
65
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @returns real component
|
|
66
|
+
* 64-bit complex number.
|
|
42
67
|
*/
|
|
43
|
-
|
|
68
|
+
Complex64: typeof Complex64;
|
|
44
69
|
|
|
45
70
|
/**
|
|
46
|
-
*
|
|
71
|
+
* Returns the imaginary component of a single-precision complex floating-point number.
|
|
47
72
|
*
|
|
73
|
+
* @param z - complex number
|
|
48
74
|
* @returns imaginary component
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
78
|
+
*
|
|
79
|
+
* var z = new Complex64( 5.0, 3.0 );
|
|
80
|
+
*
|
|
81
|
+
* var im = ns.imag( z );
|
|
82
|
+
* // returns 3.0
|
|
49
83
|
*/
|
|
50
|
-
|
|
84
|
+
imag: typeof imag;
|
|
51
85
|
|
|
52
86
|
/**
|
|
53
|
-
*
|
|
87
|
+
* Parse a string representation of a 64-bit complex number.
|
|
54
88
|
*
|
|
55
|
-
* @
|
|
89
|
+
* @param str - string representation of a complex number
|
|
90
|
+
* @returns Complex64 instance
|
|
91
|
+
* @throws must provide a string recognized as a complex number
|
|
56
92
|
*
|
|
57
93
|
* @example
|
|
58
|
-
* var
|
|
59
|
-
*
|
|
94
|
+
* var str = '5 + 3i';
|
|
95
|
+
*
|
|
96
|
+
* var z = ns.parseComplex64( str );
|
|
97
|
+
* // returns <Complex64>
|
|
60
98
|
*/
|
|
61
|
-
|
|
99
|
+
parseComplex64: typeof parseComplex64;
|
|
62
100
|
|
|
63
101
|
/**
|
|
64
|
-
*
|
|
102
|
+
* Returns the real component of a single-precision complex floating-point number.
|
|
65
103
|
*
|
|
66
|
-
* @
|
|
104
|
+
* @param z - complex number
|
|
105
|
+
* @returns real component
|
|
67
106
|
*
|
|
68
107
|
* @example
|
|
108
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
109
|
+
*
|
|
69
110
|
* var z = new Complex64( 5.0, 3.0 );
|
|
70
111
|
*
|
|
71
|
-
* var
|
|
72
|
-
* // returns
|
|
112
|
+
* var re = ns.real( z );
|
|
113
|
+
* // returns 5.0
|
|
73
114
|
*/
|
|
74
|
-
|
|
115
|
+
real: typeof real;
|
|
75
116
|
|
|
76
117
|
/**
|
|
77
|
-
*
|
|
118
|
+
* Returns the real and imaginary components of a single-precision complex floating-point number.
|
|
78
119
|
*
|
|
79
|
-
* @
|
|
120
|
+
* @param z - complex number
|
|
121
|
+
* @returns real and imaginary components
|
|
80
122
|
*
|
|
81
123
|
* @example
|
|
124
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
125
|
+
*
|
|
82
126
|
* var z = new Complex64( 5.0, 3.0 );
|
|
83
127
|
*
|
|
84
|
-
* var
|
|
85
|
-
* // returns
|
|
128
|
+
* var out = ns.reim( z );
|
|
129
|
+
* // returns <Float32Array>[ 5.0, 3.0 ]
|
|
86
130
|
*/
|
|
87
|
-
|
|
131
|
+
reim: typeof reim;
|
|
88
132
|
|
|
89
133
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* ## Notes
|
|
93
|
-
*
|
|
94
|
-
* - `JSON.stringify()` implicitly calls this method when stringifying a `Complex64` instance.
|
|
134
|
+
* Revives a JSON-serialized 64-bit complex number.
|
|
95
135
|
*
|
|
96
|
-
*
|
|
97
|
-
* @
|
|
136
|
+
* @param key - key
|
|
137
|
+
* @param value - value
|
|
138
|
+
* @returns value or 64-bit complex number
|
|
98
139
|
*
|
|
99
140
|
* @example
|
|
100
|
-
* var
|
|
141
|
+
* var parseJSON = require( '@stdlib/utils-parse-json' );
|
|
101
142
|
*
|
|
102
|
-
* var
|
|
103
|
-
*
|
|
143
|
+
* var str = '{"type":"Complex64","re":5,"im":3}';
|
|
144
|
+
*
|
|
145
|
+
* var z = parseJSON( str, ns.reviveComplex64 );
|
|
146
|
+
* // returns <Complex64>
|
|
104
147
|
*/
|
|
105
|
-
|
|
148
|
+
reviveComplex64: typeof reviveComplex64;
|
|
106
149
|
}
|
|
107
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Single-precision complex number functions.
|
|
153
|
+
*/
|
|
154
|
+
declare var ns: Namespace;
|
|
155
|
+
|
|
108
156
|
|
|
109
157
|
// EXPORTS //
|
|
110
158
|
|
|
111
|
-
export =
|
|
159
|
+
export = ns;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license Apache-2.0
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
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
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @module @stdlib/complex-float32
|
|
33
|
+
* Top-level namespace.
|
|
25
34
|
*
|
|
26
|
-
* @
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
114
|
+
module.exports = ns;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/complex-float32",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.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": "
|
|
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/
|
|
36
|
-
"@stdlib/
|
|
37
|
-
"@stdlib/
|
|
38
|
-
"@stdlib/
|
|
39
|
-
"@stdlib/
|
|
33
|
+
"@stdlib/complex-float32-base": "^0.1.0",
|
|
34
|
+
"@stdlib/complex-float32-conj": "^0.1.1",
|
|
35
|
+
"@stdlib/complex-float32-ctor": "^0.0.2",
|
|
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
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
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;
|