diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/README.md b/lib/node_modules/@stdlib/math/base/special/cinv/README.md
index 4ebd86f606e..5f3c95f18e6 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/README.md
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/README.md
@@ -18,9 +18,9 @@ limitations under the License.
-->
-# inv
+# cinv
-> Compute the inverse of a complex number.
+> Compute the inverse of a double-precision complex floating-point number.
@@ -47,27 +47,23 @@ The inverse (or reciprocal) of a non-zero complex number `z = a + bi` is defined
var cinv = require( '@stdlib/math/base/special/cinv' );
```
-#### cinv( \[out,] re1, im1 )
+#### cinv( z )
-Computes the inverse of a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`.
+Computes the inverse of a double-precision complex floating-point number.
```javascript
-var v = cinv( 2.0, 4.0 );
-// returns [ 0.1, -0.2 ]
-```
-
-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.
-
-```javascript
-var Float64Array = require( '@stdlib/array/float64' );
+var Complex128 = require( '@stdlib/complex/float64' );
+var real = require( '@stdlib/complex/real' );
+var imag = require( '@stdlib/complex/imag' );
-var out = new Float64Array( 2 );
+var v = cinv( new Complex128( 2.0, 4.0 ) );
+// returns
-var v = cinv( out, 2.0, 4.0 );
-// returns [ 0.1, -0.2 ]
+var re = real( v );
+// returns 0.1
-var bool = ( v === out );
-// returns true
+var im = imag( v );
+// returns -0.2
```
@@ -82,26 +78,16 @@ 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 uniform = require( '@stdlib/random/base/uniform' );
var cinv = require( '@stdlib/math/base/special/cinv' );
-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 );
-
- o = cinv( real(z1), imag(z1) );
- z2 = new Complex128( o[ 0 ], o[ 1 ] );
+ z1 = new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) );
+ z2 = cinv( z1 );
console.log( '1.0 / (%s) = %s', z1.toString(), z2.toString() );
}
@@ -111,6 +97,117 @@ for ( i = 0; i < 100; i++ ) {
+
+
+* * *
+
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/math/base/special/cinv.h"
+```
+
+#### stdlib_base_cinv( z )
+
+Computes the inverse of 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( 2.0, 4.0 );
+
+stdlib_complex128_t out = stdlib_base_cinv( z );
+
+double re = stdlib_real( out );
+// returns 0.1
+
+double im = stdlib_imag( out );
+// returns -0.2
+```
+
+The function accepts the following arguments:
+
+- **z**: `[in] stdlib_complex128_t` input value.
+
+```c
+stdlib_complex128_t stdlib_base_cinv( const stdlib_complex128_t z );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/math/base/special/cinv.h"
+#include "stdlib/complex/float64.h"
+#include "stdlib/complex/reim.h"
+#include
+
+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 re1;
+ double im1;
+ double re2;
+ double im2;
+ int i;
+ for ( i = 0; i < 4; i++ ) {
+ v = x[ i ];
+ y = stdlib_base_cinv( v );
+ stdlib_reim( v, &re1, &im1 );
+ stdlib_reim( y, &re2, &im2 );
+ printf( "cinv(%lf + %lfi) = %lf + %lfi\n", re1, im1, re2, im2 );
+ }
+}
+```
+
+
+
+
+
+
+
+
+
* * *
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.js
index 00051efe87e..b1ae301a3dc 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.js
@@ -21,8 +21,11 @@
// 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( '@stdlib/math/base/assert/is-nan' );
+var Complex128 = require( '@stdlib/complex/float64' );
+var real = require( '@stdlib/complex/real' );
+var imag = require( '@stdlib/complex/imag' );
var pkg = require( './../package.json' ).name;
var cinv = require( './../lib' );
@@ -30,49 +33,25 @@ var cinv = 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()*1000.0 ) - 500.0;
- im = ( randu()*1000.0 ) - 500.0;
- y = cinv( 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 = new Array( 2 );
+ 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++ ) {
- re = ( randu()*1000.0 ) - 500.0;
- im = ( randu()*1000.0 ) - 500.0;
- y = cinv( out, re, im );
- if ( y.length === 0 ) {
- b.fail( 'should not be empty' );
+ y = cinv( 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 not NaN' );
}
b.pass( 'benchmark finished' );
b.end();
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.native.js
new file mode 100644
index 00000000000..4d5d94df1bc
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/benchmark.native.js
@@ -0,0 +1,67 @@
+/**
+* @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( '@stdlib/math/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 cinv = tryRequire( resolve( __dirname, './../lib/native.js' ) );
+var opts = {
+ 'skip': ( cinv instanceof Error )
+};
+
+
+// MAIN //
+
+bench( pkg+'::native', opts, function benchmark( b ) {
+ var values;
+ var y;
+ 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++ ) {
+ y = cinv( values[ i%values.length ] );
+ 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();
+});
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/c/native/Makefile
new file mode 100644
index 00000000000..7f6bbc4c205
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/c/native/Makefile
@@ -0,0 +1,146 @@
+#/
+# @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.
+#/
+
+# VARIABLES #
+
+ifndef VERBOSE
+ QUIET := @
+else
+ QUIET :=
+endif
+
+# Determine the OS ([1][1], [2][2]).
+#
+# [1]: https://en.wikipedia.org/wiki/Uname#Examples
+# [2]: http://stackoverflow.com/a/27776822/2225624
+OS ?= $(shell uname)
+ifneq (, $(findstring MINGW,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring MSYS,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring CYGWIN,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring Windows_NT,$(OS)))
+ OS := WINNT
+endif
+endif
+endif
+endif
+
+# Define the program used for compiling C source files:
+ifdef C_COMPILER
+ CC := $(C_COMPILER)
+else
+ CC := gcc
+endif
+
+# Define the command-line options when compiling C files:
+CFLAGS ?= \
+ -std=c99 \
+ -O3 \
+ -Wall \
+ -pedantic
+
+# Determine whether to generate position independent code ([1][1], [2][2]).
+#
+# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
+# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
+ifeq ($(OS), WINNT)
+ fPIC ?=
+else
+ fPIC ?= -fPIC
+endif
+
+# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
+INCLUDE ?=
+
+# List of source files:
+SOURCE_FILES ?=
+
+# List of libraries (e.g., `-lopenblas -lpthread`):
+LIBRARIES ?=
+
+# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
+LIBPATH ?=
+
+# List of C targets:
+c_targets := benchmark.out
+
+
+# RULES #
+
+#/
+# Compiles source files.
+#
+# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
+# @param {string} [CFLAGS] - C compiler options
+# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
+# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
+# @param {string} [SOURCE_FILES] - list of source files
+# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
+# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
+#
+# @example
+# make
+#
+# @example
+# make all
+#/
+all: $(c_targets)
+
+.PHONY: all
+
+#/
+# Compiles C source files.
+#
+# @private
+# @param {string} CC - C compiler (e.g., `gcc`)
+# @param {string} CFLAGS - C compiler options
+# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
+# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
+# @param {string} SOURCE_FILES - list of source files
+# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
+# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
+#/
+$(c_targets): %.out: %.c
+ $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
+
+#/
+# Runs compiled benchmarks.
+#
+# @example
+# make run
+#/
+run: $(c_targets)
+ $(QUIET) ./$<
+
+.PHONY: run
+
+#/
+# Removes generated files.
+#
+# @example
+# make clean
+#/
+clean:
+ $(QUIET) -rm -f *.o *.out
+
+.PHONY: clean
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/c/native/benchmark.c
new file mode 100644
index 00000000000..1617c2c0faf
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/benchmark/c/native/benchmark.c
@@ -0,0 +1,144 @@
+/**
+* @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.
+*/
+
+/**
+* Benchmark `cinv`.
+*/
+#include "stdlib/math/base/special/cinv.h"
+#include "stdlib/complex/float64.h"
+#include "stdlib/complex/reim.h"
+#include
+#include
+#include
+#include
+#include
+
+#define NAME "cinv"
+#define ITERATIONS 1000000
+#define REPEATS 3
+
+/**
+* Prints the TAP version.
+*/
+void print_version() {
+ printf( "TAP version 13\n" );
+}
+
+/**
+* Prints the TAP summary.
+*
+* @param total total number of tests
+* @param passing total number of passing tests
+*/
+void print_summary( int total, int passing ) {
+ printf( "#\n" );
+ printf( "1..%d\n", total ); // TAP plan
+ printf( "# total %d\n", total );
+ printf( "# pass %d\n", passing );
+ printf( "#\n" );
+ printf( "# ok\n" );
+}
+
+/**
+* Prints benchmarks results.
+*
+* @param elapsed elapsed time in seconds
+*/
+void print_results( double elapsed ) {
+ double rate = (double)ITERATIONS / elapsed;
+ printf( " ---\n" );
+ printf( " iterations: %d\n", ITERATIONS );
+ printf( " elapsed: %0.9f\n", elapsed );
+ printf( " rate: %0.9f\n", rate );
+ printf( " ...\n" );
+}
+
+/**
+* Returns a clock time.
+*
+* @return clock time
+*/
+double tic() {
+ struct timeval now;
+ gettimeofday( &now, NULL );
+ return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
+}
+
+/**
+* Generates a random number on the interval [0,1].
+*
+* @return random number
+*/
+double rand_double() {
+ int r = rand();
+ return (double)r / ( (double)RAND_MAX + 1.0 );
+}
+
+/**
+* Runs a benchmark.
+*
+* @return elapsed time in seconds
+*/
+double benchmark() {
+ double elapsed;
+ double re;
+ double im;
+ double t;
+ double v;
+ int i;
+
+ stdlib_complex128_t x;
+ stdlib_complex128_t y;
+
+ t = tic();
+ for ( i = 0; i < ITERATIONS; i++ ) {
+ v = ( 1000.0*rand_double() ) - 500.0;
+ x = stdlib_complex128( v, v );
+ y = stdlib_base_cinv( x );
+ stdlib_reim( y, &re, &im );
+ if ( re != re ) {
+ printf( "unexpected result\n" );
+ break;
+ }
+ }
+ elapsed = tic() - t;
+ if ( im != im ) {
+ printf( "unexpected result\n" );
+ }
+ return elapsed;
+}
+
+/**
+* Main execution sequence.
+*/
+int main( void ) {
+ double elapsed;
+ int i;
+
+ // Use the current time to seed the random number generator:
+ srand( time( NULL ) );
+
+ print_version();
+ for ( i = 0; i < REPEATS; i++ ) {
+ printf( "# c::native::%s\n", NAME );
+ elapsed = benchmark();
+ print_results( elapsed );
+ printf( "ok %d benchmark finished\n", i+1 );
+ }
+ print_summary( REPEATS, REPEATS );
+}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cinv/binding.gyp
new file mode 100644
index 00000000000..f2b466aef5c
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/binding.gyp
@@ -0,0 +1,170 @@
+# @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.
+
+# A `.gyp` file for building a Node.js native add-on.
+#
+# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
+# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
+{
+ # List of files to include in this file:
+ 'includes': [
+ './include.gypi',
+ ],
+
+ # Define variables to be used throughout the configuration for all targets:
+ 'variables': {
+ # Target name should match the add-on export name:
+ 'addon_target_name%': 'addon',
+
+ # Set variables based on the host OS:
+ 'conditions': [
+ [
+ 'OS=="win"',
+ {
+ # Define the object file suffix:
+ 'obj': 'obj',
+ },
+ {
+ # Define the object file suffix:
+ 'obj': 'o',
+ }
+ ], # end condition (OS=="win")
+ ], # end conditions
+ }, # end variables
+
+ # Define compile targets:
+ 'targets': [
+
+ # Target to generate an add-on:
+ {
+ # The target name should match the add-on export name:
+ 'target_name': '<(addon_target_name)',
+
+ # Define dependencies:
+ 'dependencies': [],
+
+ # Define directories which contain relevant include headers:
+ 'include_dirs': [
+ # Local include directory:
+ '<@(include_dirs)',
+ ],
+
+ # List of source files:
+ 'sources': [
+ '<@(src_files)',
+ ],
+
+ # Settings which should be applied when a target's object files are used as linker input:
+ 'link_settings': {
+ # Define libraries:
+ 'libraries': [
+ '<@(libraries)',
+ ],
+
+ # Define library directories:
+ 'library_dirs': [
+ '<@(library_dirs)',
+ ],
+ },
+
+ # C/C++ compiler flags:
+ 'cflags': [
+ # Enable commonly used warning options:
+ '-Wall',
+
+ # Aggressive optimization:
+ '-O3',
+ ],
+
+ # C specific compiler flags:
+ 'cflags_c': [
+ # Specify the C standard to which a program is expected to conform:
+ '-std=c99',
+ ],
+
+ # C++ specific compiler flags:
+ 'cflags_cpp': [
+ # Specify the C++ standard to which a program is expected to conform:
+ '-std=c++11',
+ ],
+
+ # Linker flags:
+ 'ldflags': [],
+
+ # Apply conditions based on the host OS:
+ 'conditions': [
+ [
+ 'OS=="mac"',
+ {
+ # Linker flags:
+ 'ldflags': [
+ '-undefined dynamic_lookup',
+ '-Wl,-no-pie',
+ '-Wl,-search_paths_first',
+ ],
+ },
+ ], # end condition (OS=="mac")
+ [
+ 'OS!="win"',
+ {
+ # C/C++ flags:
+ 'cflags': [
+ # Generate platform-independent code:
+ '-fPIC',
+ ],
+ },
+ ], # end condition (OS!="win")
+ ], # end conditions
+ }, # end target <(addon_target_name)
+
+ # Target to copy a generated add-on to a standard location:
+ {
+ 'target_name': 'copy_addon',
+
+ # Declare that the output of this target is not linked:
+ 'type': 'none',
+
+ # Define dependencies:
+ 'dependencies': [
+ # Require that the add-on be generated before building this target:
+ '<(addon_target_name)',
+ ],
+
+ # Define a list of actions:
+ 'actions': [
+ {
+ 'action_name': 'copy_addon',
+ 'message': 'Copying addon...',
+
+ # Explicitly list the inputs in the command-line invocation below:
+ 'inputs': [],
+
+ # Declare the expected outputs:
+ 'outputs': [
+ '<(addon_output_dir)/<(addon_target_name).node',
+ ],
+
+ # Define the command-line invocation:
+ 'action': [
+ 'cp',
+ '<(PRODUCT_DIR)/<(addon_target_name).node',
+ '<(addon_output_dir)/<(addon_target_name).node',
+ ],
+ },
+ ], # end actions
+ }, # end target copy_addon
+ ], # end targets
+}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cinv/docs/repl.txt
index 47416943e6d..1d74a24e85c 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/docs/repl.txt
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/docs/repl.txt
@@ -1,33 +1,25 @@
-{{alias}}( [out,] re, im )
- Computes the inverse of a complex number.
+{{alias}}( z )
+ Computes the inverse of a double-precision complex floating-point number.
Parameters
----------
- out: Array|TypedArray|Object (optional)
- Output array.
-
- re: number
- Real component.
-
- im: number
- Imaginary component.
+ z: Complex128
+ Complex number.
Returns
-------
- out: Array|TypedArray|Object
- Real and imaginary components.
+ out: Complex128
+ Result.
Examples
--------
- > var y = {{alias}}( 2.0, 4.0 )
- [ 0.1, -0.2 ]
-
- > var out = new {{alias:@stdlib/array/float64}}( 2 );
- > var v = {{alias}}( out, 2.0, 4.0 )
- [ 0.1, -0.2 ]
- > var bool = ( v === out )
- true
+ > var v = {{alias}}( new {{alias:@stdlib/complex/float64}}( 2.0, 4.0 ) )
+
+ > var re = {{alias:@stdlib/complex/real}}( v )
+ 0.1
+ > var im = {{alias:@stdlib/complex/imag}}( v )
+ -0.2
See Also
--------
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/index.d.ts
index fabad5fa2dc..ddc8ab864f2 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/index.d.ts
@@ -20,41 +20,29 @@
///
-import { ArrayLike } from '@stdlib/types/array';
+import { Complex128 } from '@stdlib/types/object';
/**
-* Computes the inverse of a complex number.
+* Computes the inverse of a double-precision complex floating-point number.
*
-* @param out - output array
-* @param re - real component
-* @param im - imaginary component
-* @returns real and imaginary components
+* @param z - input value
+* @returns result
*
* @example
-* var Float32Array = require( `@stdlib/array/float32` );
+* var Complex128 = require( `@stdlib/complex/float64` );
+* var real = require( `@stdlib/complex/real` );
+* var imag = require( `@stdlib/complex/imag` );
*
-* var out = new Float32Array( 2 );
+* var v = cinv( new Complex128( 2.0, 4.0 ) );
+* // returns
*
-* var v = cinv( out, 2.0, 4.0 );
-* // returns [ 0.1, -0.2 ]
+* var re = real( v );
+* // returns 0.1
*
-* var bool = ( v === out );
-* // returns true
+* var im = imag( v );
+* // returns -0.2
*/
-declare function cinv( out: ArrayLike, re: number, im: number ): ArrayLike; // tslint-disable-line max-line-length
-
-/**
-* Computes the inverse of a complex number.
-*
-* @param re - real component
-* @param im - imaginary component
-* @returns real and imaginary components
-*
-* @example
-* var v = cinv( 2.0, 4.0 );
-* // returns [ 0.1, -0.2 ]
-*/
-declare function cinv( re: number, im: number ): ArrayLike;
+declare function cinv( z: Complex128 ): Complex128;
// EXPORTS //
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/test.ts
index d9c02e933a1..b4b234e29e9 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/test.ts
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/docs/types/test.ts
@@ -16,53 +16,30 @@
* limitations under the License.
*/
+import Complex128 = require( '@stdlib/complex/float64' );
import cinv = require( './index' );
// TESTS //
-// The function returns an array of numbers...
+// The function returns a double-precision complex floating-point number...
{
- cinv( 5, 3 ); // $ExpectType ArrayLike
- cinv( [], 5, 3 ); // $ExpectType ArrayLike
+ cinv( new Complex128( 1.0, 2.0 ) ); // $ExpectType Complex128
}
-// The compiler throws an error if the function is provided a real component which is not a number...
+// The compiler throws an error if the function is provided a value other than a complex number...
{
- cinv( true, 3 ); // $ExpectError
- cinv( false, 3 ); // $ExpectError
- cinv( null, 3 ); // $ExpectError
- cinv( undefined, 3 ); // $ExpectError
- cinv( '5', 3 ); // $ExpectError
- cinv( [], 3 ); // $ExpectError
- cinv( {}, 3 ); // $ExpectError
- cinv( ( x: number ): number => x, 3 ); // $ExpectError
+ cinv( true ); // $ExpectError
+ cinv( false ); // $ExpectError
+ cinv( null ); // $ExpectError
+ cinv( undefined ); // $ExpectError
+ cinv( '5' ); // $ExpectError
+ cinv( [] ); // $ExpectError
+ cinv( {} ); // $ExpectError
+ cinv( ( x: number ): number => x ); // $ExpectError
}
-// The compiler throws an error if the function is provided an imaginary component which is not a number...
-{
- cinv( 5, true ); // $ExpectError
- cinv( 5, false ); // $ExpectError
- cinv( 5, null ); // $ExpectError
- cinv( 5, undefined ); // $ExpectError
- cinv( 5, '5' ); // $ExpectError
- cinv( 5, [] ); // $ExpectError
- cinv( 5, {} ); // $ExpectError
- cinv( 5, ( x: number ): number => x ); // $ExpectError
-}
-
-// The compiler throws an error if the function is provided an output array which is not array-like...
-{
- cinv( true, 5, 3 ); // $ExpectError
- cinv( false, 5, 3 ); // $ExpectError
- cinv( 'abc', 5, 3 ); // $ExpectError
- cinv( {}, 5, 3 ); // $ExpectError
- cinv( ( x: number ): number => x, 5, 3 ); // $ExpectError
- cinv( 123, 5, 3 ); // $ExpectError
-}
-
-// The compiler throws an error if the function is provided insufficient arguments...
+// The compiler throws an error if the function is provided an unsupported number of arguments...
{
cinv(); // $ExpectError
- cinv( 2 ); // $ExpectError
}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cinv/examples/c/Makefile
new file mode 100644
index 00000000000..f0ae66fecf0
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/examples/c/Makefile
@@ -0,0 +1,146 @@
+#/
+# @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.
+#/
+
+# VARIABLES #
+
+ifndef VERBOSE
+ QUIET := @
+else
+ QUIET :=
+endif
+
+# Determine the OS ([1][1], [2][2]).
+#
+# [1]: https://en.wikipedia.org/wiki/Uname#Examples
+# [2]: http://stackoverflow.com/a/27776822/2225624
+OS ?= $(shell uname)
+ifneq (, $(findstring MINGW,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring MSYS,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring CYGWIN,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring Windows_NT,$(OS)))
+ OS := WINNT
+endif
+endif
+endif
+endif
+
+# Define the program used for compiling C source files:
+ifdef C_COMPILER
+ CC := $(C_COMPILER)
+else
+ CC := gcc
+endif
+
+# Define the command-line options when compiling C files:
+CFLAGS ?= \
+ -std=c99 \
+ -O3 \
+ -Wall \
+ -pedantic
+
+# Determine whether to generate position independent code ([1][1], [2][2]).
+#
+# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
+# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
+ifeq ($(OS), WINNT)
+ fPIC ?=
+else
+ fPIC ?= -fPIC
+endif
+
+# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
+INCLUDE ?=
+
+# List of source files:
+SOURCE_FILES ?=
+
+# List of libraries (e.g., `-lopenblas -lpthread`):
+LIBRARIES ?=
+
+# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
+LIBPATH ?=
+
+# List of C targets:
+c_targets := example.out
+
+
+# RULES #
+
+#/
+# Compiles source files.
+#
+# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
+# @param {string} [CFLAGS] - C compiler options
+# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
+# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
+# @param {string} [SOURCE_FILES] - list of source files
+# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
+# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
+#
+# @example
+# make
+#
+# @example
+# make all
+#/
+all: $(c_targets)
+
+.PHONY: all
+
+#/
+# Compiles C source files.
+#
+# @private
+# @param {string} CC - C compiler (e.g., `gcc`)
+# @param {string} CFLAGS - C compiler options
+# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
+# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
+# @param {string} SOURCE_FILES - list of source files
+# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
+# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
+#/
+$(c_targets): %.out: %.c
+ $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
+
+#/
+# Runs compiled examples.
+#
+# @example
+# make run
+#/
+run: $(c_targets)
+ $(QUIET) ./$<
+
+.PHONY: run
+
+#/
+# Removes generated files.
+#
+# @example
+# make clean
+#/
+clean:
+ $(QUIET) -rm -f *.o *.out
+
+.PHONY: clean
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cinv/examples/c/example.c
new file mode 100644
index 00000000000..39a04a9a6bb
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/examples/c/example.c
@@ -0,0 +1,46 @@
+/**
+* @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.
+*/
+
+#include "stdlib/math/base/special/cinv.h"
+#include "stdlib/complex/float64.h"
+#include "stdlib/complex/reim.h"
+#include
+
+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 re1;
+ double im1;
+ double re2;
+ double im2;
+ int i;
+ for ( i = 0; i < 4; i++ ) {
+ v = x[ i ];
+ y = stdlib_base_cinv( v );
+ stdlib_reim( v, &re1, &im1 );
+ stdlib_reim( y, &re2, &im2 );
+ printf( "cinv(%lf + %lfi) = %lf + %lfi\n", re1, im1, re2, im2 );
+ }
+}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cinv/examples/index.js
index 6e56472efc7..aa9803874e6 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/examples/index.js
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/examples/index.js
@@ -19,26 +19,16 @@
'use strict';
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 uniform = require( '@stdlib/random/base/uniform' );
var cinv = require( './../lib' );
-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 );
-
- o = cinv( [], real(z1), imag(z1) );
- z2 = new Complex128( o[ 0 ], o[ 1 ] );
+ z1 = new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) );
+ z2 = cinv( z1 );
console.log( '1.0 / (%s) = %s', z1.toString(), z2.toString() );
}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/include.gypi b/lib/node_modules/@stdlib/math/base/special/cinv/include.gypi
new file mode 100644
index 00000000000..78db9faf8c7
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/include.gypi
@@ -0,0 +1,53 @@
+# @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.
+
+# A GYP include file for building a Node.js native add-on.
+#
+# Main documentation:
+#
+# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
+# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
+{
+ # Define variables to be used throughout the configuration for all targets:
+ 'variables': {
+ # Source directory:
+ 'src_dir': './src',
+
+ # Include directories:
+ 'include_dirs': [
+ '= LARGE_THRESHOLD ) {
- re *= 0.5;
- im *= 0.5;
- s *= 0.5;
- } else if ( ab <= SMALL_THRESHOLD ) {
- re *= RECIP_EPS_SQR;
- im *= RECIP_EPS_SQR;
- s *= RECIP_EPS_SQR;
- }
- if ( abs( im ) <= abs( re ) ) {
- r = im / re;
- t = 1.0 / ( re + (im*r) );
- out[ 0 ] = t;
- out[ 1 ] = -r * t;
- } else {
- r = re / im;
- t = 1.0 / ( im + (re*r) );
- out[ 0 ] = r * t;
- out[ 1 ] = -t;
- }
- out[ 0 ] *= s;
- out[ 1 ] *= s;
- return out;
-}
-
-
-// EXPORTS //
-
-module.exports = cinv;
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cinv/lib/index.js
index e5b472fd1be..3769a9635ba 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/lib/index.js
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/lib/index.js
@@ -19,26 +19,24 @@
'use strict';
/**
-* Compute the inverse of a complex number.
+* Compute the inverse of a double-precision complex floating-point number.
*
* @module @stdlib/math/base/special/cinv
*
* @example
+* var Complex128 = require( '@stdlib/complex/float64' );
+* var real = require( '@stdlib/complex/real' );
+* var imag = require( '@stdlib/complex/imag' );
* var cinv = require( '@stdlib/math/base/special/cinv' );
*
-* var v = cinv( 2.0, 4.0 );
-* // returns [ 0.1, -0.2 ]
+* var v = cinv( new Complex128( 2.0, 4.0 ) );
+* // returns
*
-* @example
-* var cinv = require( '@stdlib/math/base/special/cinv' );
-*
-* var out = new Array( 2 );
-*
-* var v = cinv( out, 2.0, 4.0 );
-* // returns [ 0.1, -0.2 ]
+* var re = real( v );
+* // returns 0.1
*
-* var bool = ( v === out );
-* // returns true
+* var im = imag( v );
+* // returns -0.2
*/
// MODULES //
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cinv/lib/main.js
index aac4e1fd68c..93dc44327d6 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/lib/main.js
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/lib/main.js
@@ -20,42 +20,85 @@
// MODULES //
-var inverse = require( './cinv.js' );
+var abs = require( '@stdlib/math/base/special/abs' );
+var max = require( '@stdlib/math/base/special/max' );
+var FLOAT64_BIGGEST = require( '@stdlib/constants/float64/max' );
+var FLOAT64_SMALLEST = require( '@stdlib/constants/float64/smallest-normal' );
+var EPS = require( '@stdlib/constants/float64/eps' );
+var Complex128 = require( '@stdlib/complex/float64' );
+var real = require( '@stdlib/complex/real' );
+var imag = require( '@stdlib/complex/imag' );
+
+
+// VARIABLES //
+
+var LARGE_THRESHOLD = FLOAT64_BIGGEST * 0.5;
+var SMALL_THRESHOLD = FLOAT64_SMALLEST * ( 2.0 / EPS );
+var RECIP_EPS_SQR = 2.0 / ( EPS * EPS );
// MAIN //
/**
-* Computes the inverse of a complex number.
+* Computes the inverse of a double-precision complex floating-point number.
*
* ## References
*
* - Baudin, Michael, and Robert L. Smith. 2012. "A Robust Complex Division in Scilab." _arXiv_ abs/1210.4539 \[cs.MS\] (October): 1–25. .
*
*
-* @param {(Array|TypedArray|Object)} [out] - output array
-* @param {number} re - real component
-* @param {number} im - imaginary component
-* @returns {(Array|TypedArray|Object)} output array
+* @param {Complex128} z - complex number
+* @returns {Complex128} result
*
* @example
-* var v = cinv( 2.0, 4.0 );
-* // returns [ 0.1, -0.2 ]
+* var Complex128 = require( '@stdlib/complex/float64' );
+* var real = require( '@stdlib/complex/real' );
+* var imag = require( '@stdlib/complex/imag' );
*
-* @example
-* var out = new Array( 2 );
+* var v = cinv( new Complex128( 2.0, 4.0 ) );
+* // returns
*
-* var v = cinv( out, 2.0, 4.0 );
-* // returns [ 0.1, -0.2 ]
+* var re = real( v );
+* // returns 0.1
*
-* var bool = ( v === out );
-* // returns true
+* var im = imag( v );
+* // returns -0.2
*/
-function cinv( out, re, im ) {
- if ( arguments.length === 2 ) {
- return inverse( [ 0.0, 0.0 ], out, re );
+function cinv( z ) {
+ var ab;
+ var re;
+ var im;
+ var s;
+ var r;
+ var t;
+
+ re = real( z );
+ im = imag( z );
+ ab = max( abs(re), abs(im) );
+ s = 1.0;
+ if ( ab >= LARGE_THRESHOLD ) {
+ re *= 0.5;
+ im *= 0.5;
+ s *= 0.5;
+ } else if ( ab <= SMALL_THRESHOLD ) {
+ re *= RECIP_EPS_SQR;
+ im *= RECIP_EPS_SQR;
+ s *= RECIP_EPS_SQR;
+ }
+ if ( abs( im ) <= abs( re ) ) {
+ r = im / re;
+ t = 1.0 / ( re + (im*r) );
+ re = t;
+ im = -r * t;
+ } else {
+ r = re / im;
+ t = 1.0 / ( im + (re*r) );
+ re = r * t;
+ im = -t;
}
- return inverse( out, re, im );
+ re *= s;
+ im *= s;
+ return new Complex128( re, im);
}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cinv/lib/native.js
new file mode 100644
index 00000000000..10b9acb231b
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/lib/native.js
@@ -0,0 +1,58 @@
+/**
+* @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 Complex128 = require( '@stdlib/complex/float64' );
+var addon = require( './../src/addon.node' );
+
+
+// MAIN //
+
+/**
+* Computes the inverse of a double-precision complex floating-point number.
+*
+* @private
+* @param {Complex128} z - complex number
+* @returns {Complex128} result
+*
+* @example
+* var Complex128 = require( '@stdlib/complex/float64' );
+* var real = require( '@stdlib/complex/real' );
+* var imag = require( '@stdlib/complex/imag' );
+*
+* var v = cinv( new Complex128( 2.0, 4.0 ) );
+* // returns
+*
+* var re = real( v );
+* // returns 0.1
+*
+* var im = imag( v );
+* // returns -0.2
+*/
+function cinv( z ) {
+ var v = addon( z );
+ return new Complex128( v.re, v.im );
+}
+
+
+// EXPORTS //
+
+module.exports = cinv;
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/manifest.json b/lib/node_modules/@stdlib/math/base/special/cinv/manifest.json
new file mode 100644
index 00000000000..d0f5faffa60
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/manifest.json
@@ -0,0 +1,88 @@
+{
+ "options": {
+ "task": "build"
+ },
+ "fields": [
+ {
+ "field": "src",
+ "resolve": true,
+ "relative": true
+ },
+ {
+ "field": "include",
+ "resolve": true,
+ "relative": true
+ },
+ {
+ "field": "libraries",
+ "resolve": false,
+ "relative": false
+ },
+ {
+ "field": "libpath",
+ "resolve": true,
+ "relative": false
+ }
+ ],
+ "confs": [
+ {
+ "task": "build",
+ "src": [
+ "./src/main.c"
+ ],
+ "include": [
+ "./include"
+ ],
+ "libraries": [],
+ "libpath": [],
+ "dependencies": [
+ "@stdlib/math/base/napi/unary",
+ "@stdlib/complex/float64",
+ "@stdlib/complex/reim",
+ "@stdlib/math/base/special/abs",
+ "@stdlib/constants/float64/max",
+ "@stdlib/constants/float64/eps",
+ "@stdlib/constants/float64/smallest-normal"
+ ]
+ },
+ {
+ "task": "benchmark",
+ "src": [
+ "./src/main.c"
+ ],
+ "include": [
+ "./include"
+ ],
+ "libraries": [],
+ "libpath": [],
+ "dependencies": [
+ "@stdlib/complex/float64",
+ "@stdlib/complex/reim",
+ "@stdlib/math/base/special/abs",
+ "@stdlib/constants/float64/max",
+ "@stdlib/constants/float64/eps",
+ "@stdlib/constants/float64/smallest-normal"
+ ]
+ },
+ {
+ "task": "examples",
+ "src": [
+ "./src/main.c"
+ ],
+ "include": [
+ "./include"
+ ],
+ "libraries": [],
+ "libpath": [],
+ "dependencies": [
+ "@stdlib/complex/float64",
+ "@stdlib/complex/reim",
+ "@stdlib/math/base/special/abs",
+ "@stdlib/constants/float64/max",
+ "@stdlib/constants/float64/eps",
+ "@stdlib/constants/float64/smallest-normal"
+ ]
+ }
+ ]
+}
+
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/package.json b/lib/node_modules/@stdlib/math/base/special/cinv/package.json
index 084ac84cfe0..42c4ab584c5 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/package.json
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/package.json
@@ -1,7 +1,7 @@
{
"name": "@stdlib/math/base/special/cinv",
"version": "0.0.0",
- "description": "Compute the inverse of a complex number.",
+ "description": "Compute the inverse of a double-precision complex floating-point number.",
"license": "Apache-2.0",
"author": {
"name": "The Stdlib Authors",
@@ -14,6 +14,7 @@
}
],
"main": "./lib",
+ "gypfile": true,
"directories": {
"benchmark": "./benchmark",
"doc": "./docs",
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cinv/src/Makefile
new file mode 100644
index 00000000000..904c7dc4bd7
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/src/Makefile
@@ -0,0 +1,70 @@
+#/
+# @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.
+#/
+
+# VARIABLES #
+
+ifndef VERBOSE
+ QUIET := @
+else
+ QUIET :=
+endif
+
+# Determine the OS ([1][1], [2][2]).
+#
+# [1]: https://en.wikipedia.org/wiki/Uname#Examples
+# [2]: http://stackoverflow.com/a/27776822/2225624
+OS ?= $(shell uname)
+ifneq (, $(findstring MINGW,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring MSYS,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring CYGWIN,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring Windows_NT,$(OS)))
+ OS := WINNT
+endif
+endif
+endif
+endif
+
+
+# RULES #
+
+#/
+# Removes generated files for building an add-on.
+#
+# @example
+# make clean-addon
+#/
+clean-addon:
+ $(QUIET) -rm -f *.o *.node
+
+.PHONY: clean-addon
+
+#/
+# Removes generated files.
+#
+# @example
+# make clean
+#/
+clean: clean-addon
+
+.PHONY: clean
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cinv/src/addon.c
new file mode 100644
index 00000000000..b3cae9ced65
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/src/addon.c
@@ -0,0 +1,23 @@
+/**
+* @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.
+*/
+
+#include "stdlib/math/base/special/cinv.h"
+#include "stdlib/math/base/napi/unary.h"
+
+// cppcheck-suppress shadowFunction
+STDLIB_MATH_BASE_NAPI_MODULE_Z_Z( stdlib_base_cinv )
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/src/main.c b/lib/node_modules/@stdlib/math/base/special/cinv/src/main.c
new file mode 100644
index 00000000000..45a55cbc9f9
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/src/main.c
@@ -0,0 +1,100 @@
+/**
+* @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.
+*/
+
+#include "stdlib/math/base/special/cinv.h"
+#include "stdlib/math/base/special/abs.h"
+#include "stdlib/constants/float64/max.h"
+#include "stdlib/constants/float64/eps.h"
+#include "stdlib/constants/float64/smallest_normal.h"
+#include "stdlib/complex/float64.h"
+#include "stdlib/complex/reim.h"
+#include
+
+
+// VARIABLES //
+
+static const double LARGE_THRESHOLD = STDLIB_CONSTANT_FLOAT64_MAX * 0.5;
+static const double SMALL_THRESHOLD = STDLIB_CONSTANT_FLOAT64_SMALLEST_NORMAL * ( 2.0 / STDLIB_CONSTANT_FLOAT64_EPS );
+static const double RECIP_EPS_SQR = 2.0 / ( STDLIB_CONSTANT_FLOAT64_EPS * STDLIB_CONSTANT_FLOAT64_EPS );
+
+
+// MAIN //
+
+/**
+Computes the inverse of a double-precision complex floating-point number.
+*
+* ## References
+*
+* - Baudin, Michael, and Robert L. Smith. 2012. "A Robust Complex Division in Scilab." _arXiv_ abs/1210.4539 \[cs.MS\] (October): 1–25. .
+*
+* @param z input value
+* @return result
+*
+* @example
+* #include "stdlib/complex/float64.h"
+* #include "stdlib/complex/real.h"
+* #include "stdlib/complex/imag.h"
+*
+* stdlib_complex128_t z = stdlib_complex128( 2.0, 4.0 );
+*
+* stdlib_complex128_t out = stdlib_base_cinv( z );
+*
+* double re = stdlib_real( out );
+* // returns 0.1
+*
+* double im = stdlib_imag( out );
+* // returns -0.2
+*/
+stdlib_complex128_t stdlib_base_cinv( const stdlib_complex128_t z ) {
+ double re;
+ double im;
+ double ab;
+ double s;
+ double r;
+ double t;
+
+ stdlib_reim( z, &re, &im );
+
+ // TODO: replace `fmax` with stdlib max implementation once available
+ ab = fmax( stdlib_base_abs( re ), stdlib_base_abs( im ) );
+ s = 1.0;
+ if ( ab >= LARGE_THRESHOLD ) {
+ re *= 0.5;
+ im *= 0.5;
+ s *= 0.5;
+ }
+ else if ( ab <= SMALL_THRESHOLD ) {
+ re *= RECIP_EPS_SQR;
+ im *= RECIP_EPS_SQR;
+ s *= RECIP_EPS_SQR;
+ }
+ if ( stdlib_base_abs( im ) <= stdlib_base_abs( re ) ) {
+ r = im / re;
+ t = 1.0 / ( re + (im * r) );
+ re = t;
+ im = -r * t;
+ } else {
+ r = re / im;
+ t = 1.0 / ( im + (re * r) );
+ re = r * t;
+ im = -t;
+ }
+ re *= s;
+ im *= s;
+ return stdlib_complex128( re, im );
+}
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/test/test.js b/lib/node_modules/@stdlib/math/base/special/cinv/test/test.js
index f2e80b885cd..3683e3f2c00 100644
--- a/lib/node_modules/@stdlib/math/base/special/cinv/test/test.js
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/test/test.js
@@ -28,6 +28,9 @@ var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
+var Complex128 = require( '@stdlib/complex/float64' );
+var real = require( '@stdlib/complex/real' );
+var imag = require( '@stdlib/complex/imag' );
var cinv = require( './../lib' );
@@ -52,20 +55,12 @@ tape( 'main export is a function', function test( t ) {
t.end();
});
-tape( 'the function accepts an optional output array', function test( t ) {
- var result;
- var out;
-
- out = new Array( 2 );
- result = cinv( out, 2.0, 4.0 );
- t.deepEqual( out, [ 0.1, -0.2 ], 'values are correct' );
- t.equal( out, result, 'array reference is identical' );
- t.end();
-});
+tape( 'the function computes the inverse of a double-precision complex floating-point number', function test( t ) {
+ var v;
-tape( 'the function works without output array specified', function test( t ) {
- var result = cinv( 2.0, 4.0 );
- t.deepEqual( result, [ 0.1, -0.2 ], 'values are correct' );
+ v = cinv( new Complex128( 2.0, 4.0 ) );
+ t.strictEqual( real( v ), 0.1, 'returns expected value' );
+ t.strictEqual( imag( v ), -0.2, 'returns expected value' );
t.end();
});
@@ -85,21 +80,21 @@ tape( 'the function computes a complex inverse', function test( t ) {
qim = data.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -121,21 +116,21 @@ tape( 'the function computes a complex inverse (large negative imaginary compone
qim = largeNegativeImaginaryComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -157,21 +152,21 @@ tape( 'the function computes a complex inverse (large negative real components)'
qim = largeNegativeRealComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -193,21 +188,21 @@ tape( 'the function computes a complex inverse (large positive imaginary compone
qim = largePositiveImaginaryComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -229,21 +224,21 @@ tape( 'the function computes a complex inverse (large positive real components)'
qim = largePositiveRealComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -265,21 +260,21 @@ tape( 'the function computes a complex inverse (tiny negative imaginary componen
qim = tinyNegativeImaginaryComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -301,21 +296,21 @@ tape( 'the function computes a complex inverse (tiny negative real components)',
qim = tinyNegativeRealComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -337,21 +332,21 @@ tape( 'the function computes a complex inverse (tiny positive imaginary componen
qim = tinyPositiveImaginaryComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -373,21 +368,21 @@ tape( 'the function computes a complex inverse (tiny positive real components)',
qim = tinyPositiveRealComponents.qim;
for ( i = 0; i < re.length; i++ ) {
- q = cinv( re[ i ], im[ i ] );
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
- if ( q[ 0 ] === qre[ i ] ) {
- t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' );
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
} else {
- delta = abs( q[ 0 ] - qre[ i ] );
+ delta = abs( real( q ) - qre[ i ] );
tol = EPS * abs( qre[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
- if ( q[ 1 ] === qim[ i ] ) {
- t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' );
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
} else {
- delta = abs( q[ 1 ] - qim[ i ] );
+ delta = abs( imag( q ) - qim[ i ] );
tol = EPS * abs( qim[ i ] );
- t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
@@ -396,37 +391,37 @@ tape( 'the function computes a complex inverse (tiny positive real components)',
tape( 'the function may overflow', function test( t ) {
var v;
- v = cinv( 5.0e-324, 5.0e-324 );
- t.strictEqual( v[ 0 ], PINF, 'real component is +infinity' );
- t.strictEqual( v[ 1 ], NINF, 'imaginary component is -infinity' );
+ v = cinv( new Complex128( 5.0e-324, 5.0e-324 ) );
+ t.strictEqual( real( v ), PINF, 'real component is +infinity' );
+ t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
- v = cinv( -5.0e-324, 5.0e-324 );
- t.strictEqual( v[ 0 ], NINF, 'real component is -infinity' );
- t.strictEqual( v[ 1 ], NINF, 'imaginary component is -infinity' );
+ v = cinv( new Complex128( -5.0e-324, 5.0e-324 ) );
+ t.strictEqual( real( v ), NINF, 'real component is -infinity' );
+ t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
- v = cinv( -5.0e-324, -5.0e-324 );
- t.strictEqual( v[ 0 ], NINF, 'real component is -infinity' );
- t.strictEqual( v[ 1 ], PINF, 'imaginary component is +infinity' );
+ v = cinv( new Complex128( -5.0e-324, -5.0e-324 ) );
+ t.strictEqual( real( v ), NINF, 'real component is -infinity' );
+ t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
- v = cinv( 5.0e-324, -5.0e-324 );
- t.strictEqual( v[ 0 ], PINF, 'real component is +infinity' );
- t.strictEqual( v[ 1 ], PINF, 'imaginary component is +infinity' );
+ v = cinv( new Complex128( 5.0e-324, -5.0e-324 ) );
+ t.strictEqual( real( v ), PINF, 'real component is +infinity' );
+ t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
- v = cinv( 0.0, 5.0e-324 );
- t.strictEqual( v[ 0 ], 0.0, 'real component is 0' );
- t.strictEqual( v[ 1 ], NINF, 'imaginary component is -infinity' );
+ v = cinv( new Complex128( 0.0, 5.0e-324 ) );
+ t.strictEqual( real( v ), 0.0, 'real component is 0' );
+ t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
- v = cinv( 0.0, -5.0e-324 );
- t.strictEqual( v[ 0 ], 0.0, 'real component is 0' );
- t.strictEqual( v[ 1 ], PINF, 'imaginary component is +infinity' );
+ v = cinv( new Complex128( 0.0, -5.0e-324 ) );
+ t.strictEqual( real( v ), 0.0, 'real component is 0' );
+ t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
- v = cinv( 5.0e-324, 0.0 );
- t.strictEqual( v[ 0 ], PINF, 'real component is +infinity' );
- t.strictEqual( v[ 1 ], 0.0, 'imaginary component is 0' );
+ v = cinv( new Complex128( 5.0e-324, 0.0 ) );
+ t.strictEqual( real( v ), PINF, 'real component is +infinity' );
+ t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
- v = cinv( -5.0e-324, 0.0 );
- t.strictEqual( v[ 0 ], NINF, 'real component is -infinity' );
- t.strictEqual( v[ 1 ], 0.0, 'imaginary component is 0' );
+ v = cinv( new Complex128( -5.0e-324, 0.0 ) );
+ t.strictEqual( real( v ), NINF, 'real component is -infinity' );
+ t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
t.end();
});
@@ -434,17 +429,17 @@ tape( 'the function may overflow', function test( t ) {
tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) {
var v;
- v = cinv( NaN, 3.0 );
- t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' );
- t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' );
+ v = cinv( new Complex128( NaN, 3.0 ) );
+ t.strictEqual( isnan( real( v ) ), true, 'returns NaN' );
+ t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' );
- v = cinv( 5.0, NaN );
- t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' );
- t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' );
+ v = cinv( new Complex128( 5.0, NaN ) );
+ t.strictEqual( isnan( real( v ) ), true, 'returns NaN' );
+ t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' );
- v = cinv( NaN, NaN );
- t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' );
- t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' );
+ v = cinv( new Complex128( NaN, NaN ) );
+ t.strictEqual( isnan( real( v ) ), true, 'returns NaN' );
+ t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' );
t.end();
});
diff --git a/lib/node_modules/@stdlib/math/base/special/cinv/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cinv/test/test.native.js
new file mode 100644
index 00000000000..22dabf1751d
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/cinv/test/test.native.js
@@ -0,0 +1,454 @@
+/**
+* @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.
+*/
+
+/* eslint-disable id-length */
+
+'use strict';
+
+// MODULES //
+
+var resolve = require( 'path' ).resolve;
+var tape = require( 'tape' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var abs = require( '@stdlib/math/base/special/abs' );
+var EPS = require( '@stdlib/constants/float64/eps' );
+var PINF = require( '@stdlib/constants/float64/pinf' );
+var NINF = require( '@stdlib/constants/float64/ninf' );
+var Complex128 = require( '@stdlib/complex/float64' );
+var real = require( '@stdlib/complex/real' );
+var imag = require( '@stdlib/complex/imag' );
+var tryRequire = require( '@stdlib/utils/try-require' );
+
+
+// VARIABLES //
+
+var cinv = tryRequire( resolve( __dirname, './../lib/native.js' ) );
+var opts = {
+ 'skip': ( cinv instanceof Error )
+};
+
+
+// FIXTURES //
+
+var data = require( './fixtures/julia/data.json' );
+var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' );
+var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' );
+var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' );
+var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' );
+var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' );
+var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' );
+var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' );
+var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' );
+
+
+// TESTS //
+
+tape( 'main export is a function', opts, function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof cinv, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function computes the inverse of a double-precision complex floating-point number', opts, function test( t ) {
+ var v;
+
+ v = cinv( new Complex128( 2.0, 4.0 ) );
+ t.strictEqual( real( v ), 0.1, 'returns expected value' );
+ t.strictEqual( imag( v ), -0.2, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function computes a complex inverse', opts, function test( t ) {
+ var delta;
+ var qre;
+ var qim;
+ var tol;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = data.re;
+ im = data.im;
+ qre = data.qre;
+ qim = data.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (large negative imaginary components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = largeNegativeImaginaryComponents.re;
+ im = largeNegativeImaginaryComponents.im;
+ qre = largeNegativeImaginaryComponents.qre;
+ qim = largeNegativeImaginaryComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (large negative real components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = largeNegativeRealComponents.re;
+ im = largeNegativeRealComponents.im;
+ qre = largeNegativeRealComponents.qre;
+ qim = largeNegativeRealComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (large positive imaginary components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = largePositiveImaginaryComponents.re;
+ im = largePositiveImaginaryComponents.im;
+ qre = largePositiveImaginaryComponents.qre;
+ qim = largePositiveImaginaryComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (large positive real components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = largePositiveRealComponents.re;
+ im = largePositiveRealComponents.im;
+ qre = largePositiveRealComponents.qre;
+ qim = largePositiveRealComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (tiny negative imaginary components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = tinyNegativeImaginaryComponents.re;
+ im = tinyNegativeImaginaryComponents.im;
+ qre = tinyNegativeImaginaryComponents.qre;
+ qim = tinyNegativeImaginaryComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (tiny negative real components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = tinyNegativeRealComponents.re;
+ im = tinyNegativeRealComponents.im;
+ qre = tinyNegativeRealComponents.qre;
+ qim = tinyNegativeRealComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (tiny positive imaginary components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = tinyPositiveImaginaryComponents.re;
+ im = tinyPositiveImaginaryComponents.im;
+ qre = tinyPositiveImaginaryComponents.qre;
+ qim = tinyPositiveImaginaryComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function computes a complex inverse (tiny positive real components)', opts, function test( t ) {
+ var delta;
+ var tol;
+ var qre;
+ var qim;
+ var re;
+ var im;
+ var i;
+ var q;
+
+ re = tinyPositiveRealComponents.re;
+ im = tinyPositiveRealComponents.im;
+ qre = tinyPositiveRealComponents.qre;
+ qim = tinyPositiveRealComponents.qim;
+
+ for ( i = 0; i < re.length; i++ ) {
+ q = cinv( new Complex128( re[ i ], im[ i ] ) );
+
+ if ( real( q ) === qre[ i ] ) {
+ t.strictEqual( real( q ), qre[ i ], 'returns expected real component' );
+ } else {
+ delta = abs( real( q ) - qre[ i ] );
+ tol = EPS * abs( qre[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ if ( imag( q ) === qim[ i ] ) {
+ t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' );
+ } else {
+ delta = abs( imag( q ) - qim[ i ] );
+ tol = EPS * abs( qim[ i ] );
+ t.ok( delta <= tol, 'within tolerance. x: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function may overflow', opts, function test( t ) {
+ var v;
+
+ v = cinv( new Complex128( 5.0e-324, 5.0e-324 ) );
+ t.strictEqual( real( v ), PINF, 'real component is +infinity' );
+ t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
+
+ v = cinv( new Complex128( -5.0e-324, 5.0e-324 ) );
+ t.strictEqual( real( v ), NINF, 'real component is -infinity' );
+ t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
+
+ v = cinv( new Complex128( -5.0e-324, -5.0e-324 ) );
+ t.strictEqual( real( v ), NINF, 'real component is -infinity' );
+ t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
+
+ v = cinv( new Complex128( 5.0e-324, -5.0e-324 ) );
+ t.strictEqual( real( v ), PINF, 'real component is +infinity' );
+ t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
+
+ v = cinv( new Complex128( 0.0, 5.0e-324 ) );
+ t.strictEqual( real( v ), 0.0, 'real component is 0' );
+ t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
+
+ v = cinv( new Complex128( 0.0, -5.0e-324 ) );
+ t.strictEqual( real( v ), 0.0, 'real component is 0' );
+ t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
+
+ v = cinv( new Complex128( 5.0e-324, 0.0 ) );
+ t.strictEqual( real( v ), PINF, 'real component is +infinity' );
+ t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
+
+ v = cinv( new Complex128( -5.0e-324, 0.0 ) );
+ t.strictEqual( real( v ), NINF, 'real component is -infinity' );
+ t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
+
+ t.end();
+});
+
+tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', opts, function test( t ) {
+ var v;
+
+ v = cinv( new Complex128( NaN, 3.0 ) );
+ t.strictEqual( isnan( real( v ) ), true, 'returns NaN' );
+ t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' );
+
+ v = cinv( new Complex128( 5.0, NaN ) );
+ t.strictEqual( isnan( real( v ) ), true, 'returns NaN' );
+ t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' );
+
+ v = cinv( new Complex128( NaN, NaN ) );
+ t.strictEqual( isnan( real( v ) ), true, 'returns NaN' );
+ t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' );
+
+ t.end();
+});