Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 21, 2023
1 parent 0f6ab97 commit a2c7a29
Show file tree
Hide file tree
Showing 25 changed files with 1,728 additions and 324 deletions.
172 changes: 139 additions & 33 deletions base/special/ccis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ limitations under the License.
-->

# cis
# ccis

> Compute the [cis][cis] function of a complex number.
> Evaluate the [cis][cis] function for a double-precision complex floating-point number.
<section class="intro">
<section class="intro">

The [cis][cis] function is defined as

Expand All @@ -48,33 +48,39 @@ The [cis][cis] function is defined as
## Usage

```javascript
var cis = require( '@stdlib/math/base/special/ccis' );
var ccis = require( '@stdlib/math/base/special/ccis' );
```

#### cis( \[out,] re, im )
#### ccis( z )

Evaluates the [cis][cis] function with a `complex` argument comprised of a **real** component `re` and an **imaginary** component `im`.
Evaluates the [cis][cis] function for a double-precision complex floating-point number.

```javascript
var v = cis( 0.0, 0.0 );
// returns [ 1.0, 0.0 ]
var Complex128 = require( '@stdlib/complex/float64' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );

v = cis( 1.0, 0.0 );
// returns [ ~0.540, ~0.841 ]
```
var z = new Complex128( 0.0, 0.0 );

By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object.
var v = ccis( z );
// returns <Complex128>

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var re = real( v );
// returns 1.0

var im = imag( v );
// returns 0.0

var out = new Float64Array( 2 );
z = new Complex128( 1.0, 0.0 );

var v = cis( out, 1.0, 0.0 );
// returns <Float64Array>[ ~0.540, ~0.841 ]
v = ccis( z );
// returns <Complex128>

var bool = ( v === out );
// returns true
re = real( v );
// returns ~0.540

im = imag( v );
// returns ~0.841
```

</section>
Expand All @@ -89,35 +95,135 @@ var bool = ( v === out );

```javascript
var Complex128 = require( '@stdlib/complex/float64' );
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );
var cis = require( '@stdlib/math/base/special/ccis' );
var uniform = require( '@stdlib/random/base/uniform' );
var ccis = require( '@stdlib/math/base/special/ccis' );

var re;
var im;
var z1;
var z2;
var o;
var i;

for ( i = 0; i < 100; i++ ) {
re = round( randu()*100.0 ) - 50.0;
im = round( randu()*100.0 ) - 50.0;
z1 = new Complex128( re, im );
z1 = new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) );
z2 = ccis( z1 );
console.log( 'ccis(%s) = %s', z1.toString(), z2.toString() );
}
```

</section>

<!-- /.examples -->

o = cis( [ 0.0, 0.0 ], real(z1), imag(z1) );
z2 = new Complex128( o[ 0 ], o[ 1 ] );
<!-- C interface documentation. -->

console.log( 'cis(%s) = %s', z1.toString(), z2.toString() );
* * *

<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/math/base/special/ccis.h"
```

#### stdlib_base_ccis( z )

Evaluates the [cis][cis] function for a double-precision complex floating-point number.

```c
#include "stdlib/complex/float64.h"
#include "stdlib/complex/real.h"
#include "stdlib/complex/imag.h"

stdlib_complex128_t z = stdlib_complex128( 0.0, 0.0 );

stdlib_complex128_t out = stdlib_base_ccis( z );

double re = stdlib_real( out );
// returns 1.0

double im = stdlib_imag( out );
// returns 0.0
```

The function accepts the following arguments:

- **z**: `[in] stdlib_complex128_t` input value.

```c
stdlib_complex128_t stdlib_base_ccis( const stdlib_complex128_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/math/base/special/ccis.h"
#include "stdlib/complex/float64.h"
#include "stdlib/complex/reim.h"
#include <stdio.h>
int main() {
const stdlib_complex128_t x[] = {
stdlib_complex128( 3.14, 1.5 ),
stdlib_complex128( -3.14, 1.5 ),
stdlib_complex128( 0.0, -0.0 ),
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
};
stdlib_complex128_t v;
stdlib_complex128_t y;
double re;
double im;
int i;
for ( i = 0; i < 4; i++ ) {
v = x[ i ];
stdlib_reim( v, &re, &im );
printf( "z = %lf + %lfi\n", re, im );
y = stdlib_base_ccis( v );
stdlib_reim( y, &re, &im );
printf( "ccis(z) = %lf + %lfi\n", re, im );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

<section class="related">
Expand Down
53 changes: 16 additions & 37 deletions base/special/ccis/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,37 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isArray = require( '@stdlib/assert/is-array' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );
var Complex128 = require( '@stdlib/complex/float64' );
var pkg = require( './../package.json' ).name;
var cis = require( './../lib' );
var ccis = require( './../lib' );


// MAIN //

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
re = ( randu()*100.0 ) - 50.0;
im = ( randu()*100.0 ) - 50.0;
y = cis( re, im );
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::memory_reuse', function benchmark( b ) {
var out;
var re;
var im;
var y;
var i;

out = [ 0.0, 0.0 ];
values = [
new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ),
new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
re = ( randu()*100.0 ) - 50.0;
im = ( randu()*100.0 ) - 50.0;
y = cis( out, re, im );
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
y = ccis( values[ i%values.length ] );
if ( isnan( real( y ) ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
if ( isnan( imag( y ) ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
Expand Down
69 changes: 69 additions & 0 deletions base/special/ccis/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );
var Complex128 = require( '@stdlib/complex/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var ccis = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( ccis instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var values;
var y;
var z;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

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

0 comments on commit a2c7a29

Please sign in to comment.