Skip to content

Commit

Permalink
feat: add complex/float32/imag
Browse files Browse the repository at this point in the history
Ref: #2260
  • Loading branch information
kgryte committed Jul 16, 2024
1 parent 91256d0 commit afca2df
Show file tree
Hide file tree
Showing 21 changed files with 1,642 additions and 0 deletions.
239 changes: 239 additions & 0 deletions lib/node_modules/@stdlib/complex/float32/imag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
<!--
@license Apache-2.0
Copyright (c) 2021 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# imag

> Return the imaginary component of a single-precision complex floating-point number.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var imag = require( '@stdlib/complex/float32/imag' );
```

#### imag( z )

Returns the **imaginary** component of a single-precision complex floating-point number.

```javascript
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var z = new Complex64( 5.0, 3.0 );
var im = imag( z );
// returns 3.0
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint-disable max-len -->

<!-- eslint no-undef: "error" -->

```javascript
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var imag = require( '@stdlib/complex/float32/imag' );

function random() {
return new Complex64( discreteUniform( -10, 10 ), discreteUniform( -10, 10 ) );
}

// Generate an array of random complex numbers:
var x = filledarrayBy( 100, 'complex64', random );
// returns <Complex64Array>

// Retrieve the imaginary component of each complex number...
var z;
var i;
for ( i = 0; i < x.length; i++ ) {
z = x.get( i );
console.log( 'imag(%s) = %d', z.toString(), imag( z ) );
}
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/complex/float32/imag.h"
```

#### stdlib_complex64_imag( z )

Returns the imaginary component of a single-precision complex floating-point number.

```c
#include "stdlib/complex/float32/ctor.h"

stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );

// ...

float im = stdlib_complex64_imag( z );
// returns 2.0f
```

The function accepts the following arguments:

- **z**: `[in] stdlib_complex64_t` single-precision complex floating-point number.

```c
float stdlib_complex64_imag( const stdlib_complex64_t z );
```
</section>
<!-- /.usage -->
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="notes">
</section>
<!-- /.notes -->
<!-- C API usage examples. -->
<section class="examples">
### Examples
```c
#include "stdlib/complex/float32/imag.h"
#include "stdlib/complex/float32/ctor.h"
#include <stdio.h>
int main( void ) {
const stdlib_complex64_t x[] = {
stdlib_complex64( 5.0f, 2.0f ),
stdlib_complex64( -2.0f, 1.0f ),
stdlib_complex64( 0.0f, -0.0f ),
stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
};
int i;
for ( i = 0; i < 4; i++ ) {
printf( "imag(v) = %f\n", stdlib_complex64_imag( x[ i ] ) );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/complex/imag`][@stdlib/complex/imag]</span><span class="delimiter">: </span><span class="description">return the imaginary component of a double-precision complex floating-point number.</span>
- <span class="package-name">[`@stdlib/complex/realf`][@stdlib/complex/realf]</span><span class="delimiter">: </span><span class="description">return the real component of a single-precision complex floating-point number.</span>
- <span class="package-name">[`@stdlib/complex/float32/reim`][@stdlib/complex/float32/reim]</span><span class="delimiter">: </span><span class="description">return the real and imaginary components of a single-precision complex floating-point number.</span>

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

[@stdlib/complex/imag]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/imag

[@stdlib/complex/realf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/realf

[@stdlib/complex/float32/reim]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32/reim

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var randu = require( '@stdlib/random/base/randu' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var imag = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var im;
var i;

values = [
new Complex64( randu(), randu() ),
new Complex64( randu(), randu() ),
new Complex64( randu(), randu() )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
im = imag( values[ i%values.length ] );
if ( isnanf( im ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( im ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading

0 comments on commit afca2df

Please sign in to comment.