Skip to content

Commit 2f2dd8f

Browse files
committed
feat: temp commit
1 parent 43cbf2d commit 2f2dd8f

File tree

27 files changed

+2337
-0
lines changed

27 files changed

+2337
-0
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# cpolarf
22+
23+
> Compute the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var cpolarf = require( '@stdlib/math/base/special/cpolarf' );
37+
```
38+
39+
#### cpolarf( z )
40+
41+
Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number.
42+
43+
```javascript
44+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
45+
46+
var o = cpolarf( new Complex64( 5.0, 3.0 ) );
47+
// returns [ ~5.83, ~0.5404 ]
48+
```
49+
50+
#### cpolarf.assign( z, out, stride, offset )
51+
52+
Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number and assigns results to a provided output array.
53+
54+
```javascript
55+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
56+
var Float32Array = require( '@stdlib/array/float32' );
57+
58+
var out = new Float32Array( 2 );
59+
60+
var v = cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0 );
61+
// returns <Float32Array>[ ~5.83, ~0.5404 ]
62+
63+
var bool = ( v === out );
64+
// returns true
65+
```
66+
67+
</section>
68+
69+
<!-- /.usage -->
70+
71+
<section class="examples">
72+
73+
## Examples
74+
75+
<!-- eslint no-undef: "error" -->
76+
77+
```javascript
78+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
79+
var randu = require( '@stdlib/random/base/randu' );
80+
var round = require( '@stdlib/math/base/special/round' );
81+
var real = require( '@stdlib/complex/float32/real' );
82+
var imag = require( '@stdlib/complex/float32/imag' );
83+
var cpolarf = require( '@stdlib/math/base/special/cpolarf' );
84+
85+
var re;
86+
var im;
87+
var z;
88+
var o;
89+
var i;
90+
91+
for ( i = 0; i < 100; i++ ) {
92+
re = round( randu()*100.0 ) - 50.0;
93+
im = round( randu()*100.0 ) - 50.0;
94+
z = new Complex64( re, im );
95+
o = cpolarf( z );
96+
z = z.toString();
97+
console.log( 'abs(%s) = %d. arg(%s) = %d', z, o[0], z, o[1] );
98+
}
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- C interface documentation. -->
106+
107+
* * *
108+
109+
<section class="c">
110+
111+
## C APIs
112+
113+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
114+
115+
<section class="intro">
116+
117+
</section>
118+
119+
<!-- /.intro -->
120+
121+
<!-- C usage documentation. -->
122+
123+
<section class="usage">
124+
125+
### Usage
126+
127+
```c
128+
#include "stdlib/math/base/special/cpolarf.h"
129+
```
130+
131+
#### stdlib_base_cpolarf( z, cabsf, cphasef )
132+
133+
Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number.
134+
135+
```c
136+
#include "stdlib/complex/float32/ctor.h"
137+
#include "stdlib/complex/float32/real.h"
138+
#include "stdlib/complex/float32/imag.h"
139+
140+
stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 );
141+
double cabsf;
142+
double cphasef;
143+
stdlib_base_cpolarf( z, &cabsf, &cphasef );
144+
```
145+
146+
The function accepts the following arguments:
147+
148+
- **z**: `[in] stdlib_complex128_t` input value.
149+
- **cabsf**: `[out] double*` destination for the absolute value.
150+
- **cphasef**: `[out] double*` destination for the phase value in radians.
151+
152+
```c
153+
double stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double *cphasef );
154+
```
155+
156+
</section>
157+
158+
<!-- /.usage -->
159+
160+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
161+
162+
<section class="notes">
163+
164+
</section>
165+
166+
<!-- /.notes -->
167+
168+
<!-- C API usage examples. -->
169+
170+
<section class="examples">
171+
172+
### Examples
173+
174+
```c
175+
#include "stdlib/math/base/special/cpolarf.h"
176+
#include "stdlib/complex/float32/ctor.h"
177+
#include "stdlib/complex/float32/reim.h"
178+
#include <stdio.h>
179+
180+
int main( void ) {
181+
const stdlib_complex128_t x[] = {
182+
stdlib_complex128( 3.14, 1.0 ),
183+
stdlib_complex128( -3.14, -1.0 ),
184+
stdlib_complex128( 0.0, 0.0 ),
185+
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
186+
};
187+
188+
double cphasef;
189+
double cabsf;
190+
double re;
191+
double im;
192+
int i;
193+
for ( i = 0; i < 4; i++ ) {
194+
stdlib_base_cpolarf( x[i], &cabsf, &cphasef );
195+
stdlib_complex128_reim( x[i], &re, &im );
196+
printf( "cpolarf(%lf + %lfi) => cabsf: %lf, cphasef: %lf\n", re, im, cabsf, cphasef );
197+
}
198+
}
199+
```
200+
201+
</section>
202+
203+
<!-- /.examples -->
204+
205+
</section>
206+
207+
<!-- /.c -->
208+
209+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
210+
211+
<section class="related">
212+
213+
* * *
214+
215+
## See Also
216+
217+
- <span class="package-name">[`@stdlib/math/base/special/cabsf`][@stdlib/math/base/special/cabsf]</span><span class="delimiter">: </span><span class="description">compute the absolute value of a single-precision complex floating-point number.</span>
218+
- <span class="package-name">[`@stdlib/math/base/special/cphasef`][@stdlib/math/base/special/cphasef]</span><span class="delimiter">: </span><span class="description">compute the argument of a single-precision complex floating-point number in radians.</span>
219+
220+
</section>
221+
222+
<!-- /.related -->
223+
224+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
225+
226+
<section class="links">
227+
228+
[@stdlib/math/base/special/cabsf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cabsf
229+
230+
[@stdlib/math/base/special/cphasef]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cphasef
231+
232+
<!-- <related-links> -->
233+
234+
<!-- </related-links> -->
235+
236+
</section>
237+
238+
<!-- /.links -->
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var isArray = require( '@stdlib/assert/is-array' );
26+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
27+
var pkg = require( './../package.json' ).name;
28+
var cpolarf = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var values;
35+
var y;
36+
var i;
37+
38+
values = [
39+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
40+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
41+
];
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
y = cpolarf( values[ i%values.length ] );
46+
if ( y.length === 0 ) {
47+
b.fail( 'should not be empty' );
48+
}
49+
}
50+
b.toc();
51+
if ( !isArray( y ) ) {
52+
b.fail( 'should return an array' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});
57+
58+
bench( pkg+':assign', function benchmark( b ) {
59+
var values;
60+
var y;
61+
var i;
62+
63+
values = [
64+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
65+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
66+
];
67+
68+
y = [ 0.0, 0.0 ];
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
cpolarf.assign( values[ i%values.length ], y, 1, 0 );
73+
if ( y[ 0 ] !== y[ 0 ] || y[ 1 ] !== y[ 1 ] ) {
74+
b.fail( 'should not be empty' );
75+
}
76+
}
77+
b.toc();
78+
if ( !isArray( y ) ) {
79+
b.fail( 'should return an array' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var isArray = require( '@stdlib/assert/is-array' );
27+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var cpolarf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( cpolarf instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var values;
44+
var y;
45+
var i;
46+
47+
values = [
48+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
49+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
50+
];
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
y = cpolarf( values[ i%values.length ] );
55+
if ( y.length === 0 ) {
56+
b.fail( 'should not be empty' );
57+
}
58+
}
59+
b.toc();
60+
if ( !isArray( y ) ) {
61+
b.fail( 'should return an array' );
62+
}
63+
b.pass( 'benchmark finished' );
64+
b.end();
65+
});

0 commit comments

Comments
 (0)