diff --git a/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.js b/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.js index f6d0f10a3cc0..aaff9834ef58 100644 --- a/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.js @@ -21,9 +21,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isComplex128 = require( '@stdlib/assert/is-complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var randu = require( '@stdlib/random/base/randu' ); +var isComplex128 = require( '@stdlib/assert/is-complex128' ); +var uniform = require( '@stdlib/random/base/uniform' ); var pkg = require( './../package.json' ).name; var conj = require( './../lib' ); @@ -32,25 +32,26 @@ var conj = require( './../lib' ); bench( pkg, function benchmark( b ) { var values; - var v; + var z; + var y; var i; values = [ - new Complex128( randu(), randu() ), - new Complex128( randu(), randu() ), - new Complex128( randu(), randu() ) + 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++ ) { - v = conj( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { + z = values[ i%values.length ]; + y = conj( z ); + if ( typeof y !== 'object' ) { b.fail( 'should return an object' ); } } b.toc(); - if ( !isComplex128( v ) ) { - b.fail( 'should return an object' ); + if ( !isComplex128( y ) ) { + b.fail( 'should return a Complex128' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.native.js new file mode 100644 index 000000000000..fbdefa1d4e85 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/conj/benchmark/benchmark.native.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var conj = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( conj instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var values; + var out; + 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 ]; + out = conj( z ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnan( real( out ) ) || isnan( imag( out ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/complex/float64/conj/lib/main.js b/lib/node_modules/@stdlib/complex/float64/conj/lib/main.js index 1ce9d08801c9..38ce0d676793 100644 --- a/lib/node_modules/@stdlib/complex/float64/conj/lib/main.js +++ b/lib/node_modules/@stdlib/complex/float64/conj/lib/main.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); + /** * Returns the complex conjugate of a double-precision complex floating-point number. * @@ -33,7 +39,7 @@ * // returns [ 5.0, -3.0 ] */ function conj( z ) { - return new z.constructor( z.re, -z.im ); + return new Complex128( real( z ), -imag( z ) ); } diff --git a/lib/node_modules/@stdlib/complex/float64/conj/lib/native.js b/lib/node_modules/@stdlib/complex/float64/conj/lib/native.js new file mode 100644 index 000000000000..95188c3d2964 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/conj/lib/native.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/ctor' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Returns the complex conjugate of a double-precision complex floating-point number. +* +* @private +* @param {Complex128} z - complex number +* @returns {Complex128} complex conjugate +* +* @example +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var real = require( '@stdlib/complex/float64/real' ); +* var imag = require( '@stdlib/complex/float64/imag' ); +* +* var z = new Complex128( 5.0, 3.0 ); +* +* var v = conj( z ); +* // returns +* +* var re = real( v ); +* // returns 5.0 +* +* var im = imag( v ); +* // returns -3.0 +*/ +function conj( z ) { + var v = addon( z ); + return new Complex128( v.re, v.im ); +} + + +// EXPORTS // + +module.exports = conj; diff --git a/lib/node_modules/@stdlib/complex/float64/conj/manifest.json b/lib/node_modules/@stdlib/complex/float64/conj/manifest.json index 708ab675cfde..5ce0235fd989 100644 --- a/lib/node_modules/@stdlib/complex/float64/conj/manifest.json +++ b/lib/node_modules/@stdlib/complex/float64/conj/manifest.json @@ -36,6 +36,7 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/math/base/napi/unary", "@stdlib/complex/float64/ctor" ] }, diff --git a/lib/node_modules/@stdlib/complex/float64/conj/src/Makefile b/lib/node_modules/@stdlib/complex/float64/conj/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/conj/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/complex/float64/conj/src/addon.c b/lib/node_modules/@stdlib/complex/float64/conj/src/addon.c new file mode 100644 index 000000000000..0850eb13c3dc --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/conj/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/complex/float64/conj.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_Z_Z( stdlib_complex128_neg ) diff --git a/lib/node_modules/@stdlib/complex/float64/conj/test/test.js b/lib/node_modules/@stdlib/complex/float64/conj/test/test.js index a576699e3057..9095039ad784 100644 --- a/lib/node_modules/@stdlib/complex/float64/conj/test/test.js +++ b/lib/node_modules/@stdlib/complex/float64/conj/test/test.js @@ -21,7 +21,14 @@ // MODULES // var tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); var conj = require( './../lib' ); @@ -34,13 +41,97 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function returns the complex conjugate of a complex number', function test( t ) { - var v; + var actual; var z; - z = new Complex128( 3.14, -3.14 ); - v = conj( z ); - t.strictEqual( v.re, 3.14, 'returns expected value' ); - t.strictEqual( v.im, 3.14, 'returns expected value' ); + z = new Complex128( -4.2, 5.5 ); + actual = conj( z ); + + t.strictEqual( real( actual ), -4.2, 'returns expected value' ); + t.strictEqual( imag( actual ), -5.5, 'returns expected value' ); + + z = new Complex128( 9.99999, 0.1 ); + actual = conj( z ); + + t.strictEqual( real( actual ), 9.99999, 'returns expected value' ); + t.strictEqual( imag( actual ), -0.1, 'returns expected value' ); + + z = new Complex128( 4.0, 7.0 ); + actual = conj( z ); + + t.strictEqual( real( actual ), 4.0, 'returns expected value' ); + t.strictEqual( imag( actual ), -7.0, 'returns expected value' ); + + z = new Complex128( -4.0, -7.0 ); + actual = conj( z ); + + t.strictEqual( real( actual ), -4.0, 'returns expected value' ); + t.strictEqual( imag( actual ), 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var actual; + var z; + + z = new Complex128( NaN, NaN ); + actual = conj( z ); + + t.strictEqual( isnan( real( actual ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( actual ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+0` if provided `-0`', function test( t ) { + var actual; + var z; + + z = new Complex128( -0.0, -0.0 ); + actual = conj( z ); + + t.strictEqual( isNegativeZero( real( actual ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( imag( actual ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-0` if provided `+0`', function test( t ) { + var actual; + var z; + + z = new Complex128( +0.0, +0.0 ); + actual = conj( z ); + + t.strictEqual( isPositiveZero( real( actual ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( imag( actual ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `+infinity`', function test( t ) { + var actual; + var z; + + z = new Complex128( PINF, PINF ); + actual = conj( z ); + + t.strictEqual( real( actual ), PINF, 'returns expected value' ); + t.strictEqual( imag( actual ), NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `-infinity`', function test( t ) { + var actual; + var z; + + z = new Complex128( NINF, NINF ); + actual = conj( z ); + + t.strictEqual( real( actual ), NINF, 'returns expected value' ); + t.strictEqual( imag( actual ), PINF, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/complex/float64/conj/test/test.native.js b/lib/node_modules/@stdlib/complex/float64/conj/test/test.native.js new file mode 100644 index 000000000000..74c6304d0cd0 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/conj/test/test.native.js @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var conj = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( conj instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof conj, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the complex conjugate of a complex number', opts, function test( t ) { + var actual; + var z; + + z = new Complex128( -4.2, 5.5 ); + actual = conj( z ); + + t.strictEqual( real( actual ), -4.2, 'returns expected value' ); + t.strictEqual( imag( actual ), -5.5, 'returns expected value' ); + + z = new Complex128( 9.99999, 0.1 ); + actual = conj( z ); + + t.strictEqual( real( actual ), 9.99999, 'returns expected value' ); + t.strictEqual( imag( actual ), -0.1, 'returns expected value' ); + + z = new Complex128( 4.0, 7.0 ); + actual = conj( z ); + + t.strictEqual( real( actual ), 4.0, 'returns expected value' ); + t.strictEqual( imag( actual ), -7.0, 'returns expected value' ); + + z = new Complex128( -4.0, -7.0 ); + actual = conj( z ); + + t.strictEqual( real( actual ), -4.0, 'returns expected value' ); + t.strictEqual( imag( actual ), 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var actual; + var z; + + z = new Complex128( NaN, NaN ); + actual = conj( z ); + + t.strictEqual( isnan( real( actual ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( actual ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+0` if provided `-0`', opts, function test( t ) { + var actual; + var z; + + z = new Complex128( -0.0, -0.0 ); + actual = conj( z ); + + t.strictEqual( isNegativeZero( real( actual ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( imag( actual ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-0` if provided `+0`', opts, function test( t ) { + var actual; + var z; + + z = new Complex128( +0.0, +0.0 ); + actual = conj( z ); + + t.strictEqual( isPositiveZero( real( actual ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( imag( actual ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `+infinity`', opts, function test( t ) { + var actual; + var z; + + z = new Complex128( PINF, PINF ); + actual = conj( z ); + + t.strictEqual( real( actual ), PINF, 'returns expected value' ); + t.strictEqual( imag( actual ), NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `-infinity`', opts, function test( t ) { + var actual; + var z; + + z = new Complex128( NINF, NINF ); + actual = conj( z ); + + t.strictEqual( real( actual ), NINF, 'returns expected value' ); + t.strictEqual( imag( actual ), PINF, 'returns expected value' ); + + t.end(); +});