Skip to content

Commit 52d07cb

Browse files
committed
Add pkg to return the real and imaginary components for a single-precision complex floating-point number
1 parent 6d832d0 commit 52d07cb

19 files changed

Lines changed: 1379 additions & 0 deletions

File tree

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# reimf
22+
23+
> Return the real and imaginary components of a single-precision complex floating-point number.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var reimf = require( '@stdlib/complex/reimf' );
41+
```
42+
43+
#### reimf( z )
44+
45+
Returns the **real** and **imaginary** components of a single-precision complex floating-point number.
46+
47+
```javascript
48+
var Complex64 = require( '@stdlib/complex/float32' );
49+
50+
var z = new Complex64( 5.0, 3.0 );
51+
var out = reimf( z );
52+
// returns <Float32Array>[ 5.0, 3.0 ]
53+
```
54+
55+
</section>
56+
57+
<!-- /.usage -->
58+
59+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
60+
61+
<section class="notes">
62+
63+
</section>
64+
65+
<!-- /.notes -->
66+
67+
<!-- Package usage examples. -->
68+
69+
<section class="examples">
70+
71+
## Examples
72+
73+
<!-- eslint no-undef: "error" -->
74+
75+
```javascript
76+
var Complex64 = require( '@stdlib/complex/float32' );
77+
var randu = require( '@stdlib/random/base/randu' );
78+
var round = require( '@stdlib/math/base/special/round' );
79+
var reimf = require( '@stdlib/complex/reimf' );
80+
81+
var out;
82+
var re;
83+
var im;
84+
var z;
85+
var i;
86+
87+
for ( i = 0; i < 100; i++ ) {
88+
re = round( (randu()*100.0) - 50.0 );
89+
im = round( (randu()*50.0) - 25.0 );
90+
z = new Complex64( re, im );
91+
out = reimf( z );
92+
console.log( '%s => %d, %d', z.toString(), out[ 0 ], out[ 1 ] );
93+
}
94+
```
95+
96+
</section>
97+
98+
<!-- /.examples -->
99+
100+
<!-- C interface documentation. -->
101+
102+
* * *
103+
104+
<section class="c">
105+
106+
## C APIs
107+
108+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
109+
110+
<section class="intro">
111+
112+
</section>
113+
114+
<!-- /.intro -->
115+
116+
<!-- C usage documentation. -->
117+
118+
<section class="usage">
119+
120+
### Usage
121+
122+
```c
123+
#include "stdlib/complex/reimf.h"
124+
```
125+
126+
#### stdlib_reimf( z, \*re, \*im )
127+
128+
Returns the real and imaginary components of a single-precision complex floating-point number.
129+
130+
```c
131+
#include "stdlib/complex/float32.h"
132+
133+
stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
134+
135+
// ...
136+
137+
float re;
138+
float im;
139+
140+
stdlib_reimf( z, &re, &im );
141+
```
142+
143+
The function accepts the following arguments:
144+
145+
- **z**: `[in] stdlib_complex64_t` single-precision complex floating-point number.
146+
- **re**: `[out] float*` destination for real component.
147+
- **im**: `[out] float*` destination for imaginary component.
148+
149+
```c
150+
void stdlib_reimf( const stdlib_complex64_t z, float *re, float *im );
151+
```
152+
153+
</section>
154+
155+
<!-- /.usage -->
156+
157+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
158+
159+
<section class="notes">
160+
161+
</section>
162+
163+
<!-- /.notes -->
164+
165+
<!-- C API usage examples. -->
166+
167+
<section class="examples">
168+
169+
### Examples
170+
171+
```c
172+
#include "stdlib/complex/reimf.h"
173+
#include "stdlib/complex/float32.h"
174+
#include <stdio.h>
175+
176+
int main() {
177+
stdlib_complex64_t x[] = {
178+
stdlib_complex64( 5.0f, 2.0f ),
179+
stdlib_complex64( -2.0f, 1.0f ),
180+
stdlib_complex64( 0.0f, -0.0f ),
181+
stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
182+
};
183+
184+
float re;
185+
float im;
186+
int i;
187+
for ( i = 0; i < 4; i++ ) {
188+
stdlib_reimf( x[ i ], &re, &im );
189+
printf( "reimf(v) = %f, %f\n", re, im );
190+
}
191+
}
192+
```
193+
194+
</section>
195+
196+
<!-- /.examples -->
197+
198+
</section>
199+
200+
<!-- /.c -->
201+
202+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
203+
204+
<section class="references">
205+
206+
</section>
207+
208+
<!-- /.references -->
209+
210+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
211+
212+
<section class="related">
213+
214+
</section>
215+
216+
<!-- /.related -->
217+
218+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
219+
220+
<section class="links">
221+
222+
</section>
223+
224+
<!-- /.links -->
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var Complex64 = require( '@stdlib/complex/float32' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var isArrayLike = require( '@stdlib/assert/is-array-like' );
27+
var pkg = require( './../package.json' ).name;
28+
var reimf = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var arr;
35+
var z;
36+
var i;
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
z = new Complex64( randu(), randu() );
41+
arr = reimf( z );
42+
if ( arr.length === 0 ) {
43+
b.fail( 'should not be empty' );
44+
}
45+
}
46+
b.toc();
47+
if ( !isArrayLike( arr ) ) {
48+
b.fail( 'should return an array' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});

0 commit comments

Comments
 (0)