diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/README.md b/lib/node_modules/@stdlib/math/base/special/cexp/README.md index 169f5f4afeca..327ef249bbba 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cexp/README.md @@ -65,6 +65,55 @@ v = cexp( new Complex128( 0.0, 1.0 ) ); // returns [ ~0.540, ~0.841 ] ``` +#### cexp.assign( re, im, out, strideOut, offsetOut ) + +Evaluates the [exponential][exponential-function] function for a double-precision complex floating-point number and assigns results to a provided output array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var out = new Float64Array( 2 ); +var v = cexp.assign( 0.0, 0.0, out, 1, 0 ); +// returns [ 1.0, 0.0 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **re**: real component. +- **im**: imaginary component. +- **out**: output array. +- **strideOut**: stride length for `out`. +- **offsetOut**: starting index for `out`. + +#### cexp.strided( z, sz, oz, out, so, oo ) + +Evaluates the [exponential][exponential-function] function for a double-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var z = new Float64Array( [ 0.0, 0.0 ] ); +var out = new Float64Array( 2 ); + +var v = cexp.strided( z, 1, 0, out, 1, 0 ); +// returns [ 1.0, 0.0 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **z**: complex number strided array view. +- **sz**: stride length for `z`. +- **oz**: starting index for `z`. +- **out**: output array. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + @@ -76,24 +125,16 @@ v = cexp( new Complex128( 0.0, 1.0 ) ); ```javascript -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var cexp = require( '@stdlib/math/base/special/cexp' ); -function randomComplex() { - var re = discreteUniform( -50, 50 ); - var im = discreteUniform( -50, 50 ); - return new Complex128( re, im ); -} +// Create an array of random numbers: +var arr = new Complex128Array( uniform( 200, -50.0, 50.0 ) ); -var z1; -var z2; -var i; -for ( i = 0; i < 100; i++ ) { - z1 = randomComplex(); - z2 = cexp( z1 ); - console.log( 'cexp(%s) = %s', z1.toString(), z2.toString() ); -} +// Compute the exponential function of each number in the array: +logEachMap( 'cexp(%s) = %s', arr, cexp ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..8002388198cf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.assign.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assign = require( './../lib' ).assign; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// MAIN // + +bench( format( '%s:assign', pkg ), function benchmark( b ) { + var out; + var re; + var im; + var N; + var i; + var j; + + N = 100; + re = uniform( N, -50.0, 50.0, options ); + im = uniform( N, -50.0, 50.0, options ); + + out = new Float64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % N; + out = assign( re[ j ], im[ j ], out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.js index 92cd274f5eb9..b108d24dc627 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.js @@ -21,36 +21,42 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); var real = require( '@stdlib/complex/float64/real' ); var imag = require( '@stdlib/complex/float64/imag' ); var pkg = require( './../package.json' ).name; var cexp = require( './../lib' ); +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + // MAIN // bench( pkg, function benchmark( b ) { - var values; + var zbuf; + var z; var y; var i; - values = [ - new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ), - new Complex128( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ) - ]; + zbuf = uniform( 200, -50.0, 50.0, options ); + z = new Complex128Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cexp( values[ i%values.length ] ); - if ( typeof y !== 'object' ) { - b.fail( 'should return a complex number' ); + y = cexp( z.get( i%100 ) ); + if ( isnan( real( y ) ) ) { + b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( real( y ) ) || isnan( imag( y ) ) ) { + if ( isnan( imag( y ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.native.js index c3c1119ea734..e18bbe46d612 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.native.js @@ -22,9 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); var real = require( '@stdlib/complex/float64/real' ); var imag = require( '@stdlib/complex/float64/imag' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -38,29 +38,31 @@ var cexp = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( cexp instanceof Error ) }; +var options = { + 'dtype': 'float64' +}; // MAIN // bench( format( '%s::native', pkg ), opts, function benchmark( b ) { - var values; + var zbuf; + var z; 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 ) ) - ]; + zbuf = uniform( 200, -500.0, 500.0, options ); + z = new Complex128Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cexp( values[ i%values.length ] ); - if ( typeof y !== 'object' ) { - b.fail( 'should return a complex number' ); + y = cexp( z.get( i%100 ) ); + if ( isnan( real( y ) ) ) { + b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( real( y ) ) || isnan( imag( y ) ) ) { + if ( isnan( imag( y ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.strided.js b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.strided.js new file mode 100644 index 000000000000..e4aad30a4c99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/benchmark/benchmark.strided.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var strided = require( './../lib' ).strided; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// MAIN // + +bench( format( '%s:strided', pkg ), function benchmark( b ) { + var out; + var z; + var N; + var i; + var j; + + N = 50; + z = uniform( N*2, -50.0, 50.0, options ); + + out = new Float64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = ( i % N ) * 2; + out = strided( z, 1, j, out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cexp/docs/repl.txt index 3abe4e885df1..f30cd2077de9 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/cexp/docs/repl.txt @@ -20,6 +20,77 @@ > y = {{alias}}( new {{alias:@stdlib/complex/float64/ctor}}( 0.0, 1.0 ) ) [ ~0.540, ~0.841 ] + +{{alias}}.assign( re, im, out, strideOut, offsetOut ) + Evaluates the exponential function for a double-precision complex floating- + point number and assigns results to a provided output array. + + Parameters + ---------- + re: number + Real component. + + im: number + Imaginary component. + + out: ArrayLikeObject + Output array. + + strideOut: integer + Stride length. + + offsetOut: integer + Starting index. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var out = new {{alias:@stdlib/array/float64}}( 2 ); + > {{alias}}.assign( 0.0, 0.0, out, 1, 0 ) + [ 1.0, 0.0 ] + + +{{alias}}.strided( z, sz, oz, out, so, oo ) + Evaluates the exponential function for a double-precision complex floating- + point number stored in a real-valued strided array view and assigns results + to a provided strided output array. + + Parameters + ---------- + z: ArrayLikeObject + Complex number view. + + sz: integer + Stride length for `z`. + + oz: integer + Starting index for `z`. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var z = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 2 ); + > {{alias}}.strided( z, 1, 0, out, 1, 0 ) + [ 1.0, 0.0 ] + See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/index.d.ts index d05ecb23e720..11f1ac3b8258 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/index.d.ts @@ -21,6 +21,69 @@ /// import { Complex128 } from '@stdlib/types/complex'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for evaluating the exponential function for a double-precision complex floating-point number. +*/ +interface Cexp { + /** + * Evaluates the exponential function for a double-precision complex floating-point number. + * + * @param z - complex number + * @returns result + * + * @example + * var Complex128 = require( '@stdlib/complex/float64/ctor' ); + * + * var v = cexp( new Complex128( 0.0, 0.0 ) ); + * // returns [ 1.0, 0.0 ] + */ + ( z: Complex128 ): Complex128; + + /** + * Evaluates the exponential function for a double-precision complex floating-point number and assigns results to a provided output array. + * + * @param re - real component + * @param im - imaginary component + * @param out - output array + * @param strideOut - stride length + * @param offsetOut - starting index + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var out = new Float64Array( 2 ); + * var v = cexp.assign( 0.0, 0.0, out, 1, 0 ); + * // returns [ 1.0, 0.0 ] + * + * var bool = ( out === v ); + * // returns true + */ + assign>( re: number, im: number, out: T, strideOut: number, offsetOut: number ): T; + + /** + * Evaluates the exponential function for a double-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. + * + * @param z - complex number view + * @param strideZ - stride length for `z` + * @param offsetZ - starting index for `z` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var z = new Float64Array( [ 0.0, 0.0 ] ); + * + * var out = cexp.strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); + * // returns [ 1.0, 0.0 ] + */ + strided, U extends NumericArray | Collection>( z: T, strideZ: number, offsetZ: number, out: U, strideOut: number, offsetOut: number ): U; +} /** * Evaluates the exponential function for a double-precision complex floating-point number. @@ -35,12 +98,24 @@ import { Complex128 } from '@stdlib/types/complex'; * // returns [ 1.0, 0.0 ] * * @example -* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out = new Float64Array( 2 ); +* var v = cexp.assign( 0.0, 0.0, out, 1, 0 ); +* // returns [ 1.0, 0.0 ] +* +* var bool = ( out === v ); +* // returns true +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var z = new Float64Array( [ 0.0, 0.0 ] ); * -* var v = cexp( new Complex128( 1.0, 0.0 ) ); -* // returns [ ~2.718, 0.0 ] +* var out = cexp.strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); +* // returns [ 1.0, 0.0 ] */ -declare function cexp( z: Complex128 ): Complex128; +declare var cexp: Cexp; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/test.ts index 39b195064c58..c5b6b8430da7 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/cexp/docs/types/test.ts @@ -44,3 +44,203 @@ import cexp = require( './index' ); { cexp(); // $ExpectError } + +// Attached to the main export is an `assign` method which returns a collection... +{ + cexp.assign( 1.0, 1.0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cexp.assign( 1.0, 1.0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cexp.assign( 1.0, 1.0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cexp.assign( true, 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( false, 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( null, 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( undefined, 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( '5', 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( [], 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( {}, 2.0, out, 1, 0 ); // $ExpectError + cexp.assign( ( x: number ): number => x, 2.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cexp.assign( 1.0, true, out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, false, out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, null, out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, undefined, out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, '5', out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, [], out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, {}, out, 1, 0 ); // $ExpectError + cexp.assign( 1.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a collection... +{ + cexp.assign( 1.0, 2.0, 1, 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, true, 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, false, 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, null, 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, undefined, 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, '5', 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, [ '5' ], 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, {}, 1, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cexp.assign( 1.0, 2.0, out, true, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, false, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, null, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, undefined, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, '5', 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, [], 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, {}, 0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cexp.assign( 1.0, 2.0, out, 1, true ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, false ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, null ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, undefined ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, '5' ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, [] ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, {} ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const out = new Float64Array( 2 ); + + cexp.assign(); // $ExpectError + cexp.assign( 1.0 ); // $ExpectError + cexp.assign( 1.0, 2.0 ); // $ExpectError + cexp.assign( 1.0, 2.0, out ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1 ); // $ExpectError + cexp.assign( 1.0, 2.0, out, 1, 0, {} ); // $ExpectError +} + +// Attached to the main export is a `strided` method which returns a collection... +{ + const z = new Float64Array( 2 ); + + cexp.strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cexp.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cexp.strided( z, 1, 0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `strided` method is provided a first argument which is not a collection... +{ + const out = new Float64Array( 2 ); + + cexp.strided( true, 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( false, 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( null, 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( undefined, 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( '5', 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( [ '5' ], 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( {}, 1, 0, out, 1, 0 ); // $ExpectError + cexp.strided( ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a second argument which is not a number... +{ + const z = new Float64Array( 2 ); + const out = new Float64Array( 2 ); + + cexp.strided( z, true, 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, false, 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, null, 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, undefined, 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, '5', 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, [], 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, {}, 0, out, 1, 0 ); // $ExpectError + cexp.strided( z, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a third argument which is not a number... +{ + const z = new Float64Array( 2 ); + const out = new Float64Array( 2 ); + + cexp.strided( z, 1, true, out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, false, out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, null, out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, undefined, out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, '5', out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, [], out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, {}, out, 1, 0 ); // $ExpectError + cexp.strided( z, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fourth argument which is not a collection... +{ + const z = new Float64Array( 2 ); + + cexp.strided( z, 1, 0, 1, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, true, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, false, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, null, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, undefined, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, '5', 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, [ '5' ], 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, {}, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fifth argument which is not a number... +{ + const z = new Float64Array( 2 ); + const out = new Float64Array( 2 ); + + cexp.strided( z, 1, 0, out, true, 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, false, 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, null, 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, undefined, 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, '5', 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, [], 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, {}, 0 ); // $ExpectError + cexp.strided( z, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a sixth argument which is not a number... +{ + const z = new Float64Array( 2 ); + const out = new Float64Array( 2 ); + + cexp.strided( z, 1, 0, out, 1, true ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, false ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, null ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, undefined ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, '5' ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, [] ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, {} ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an unsupported number of arguments... +{ + const z = new Float64Array( 2 ); + const out = new Float64Array( 2 ); + + cexp.strided(); // $ExpectError + cexp.strided( z ); // $ExpectError + cexp.strided( z, 1 ); // $ExpectError + cexp.strided( z, 1, 0 ); // $ExpectError + cexp.strided( z, 1, 0, out ); // $ExpectError + cexp.strided( z, 1, 0, out, 1 ); // $ExpectError + cexp.strided( z, 1, 0, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cexp/examples/index.js index 664ea15e4d3b..37b892cee106 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/examples/index.js @@ -18,21 +18,13 @@ 'use strict'; -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var cexp = require( './../lib' ); -function randomComplex() { - var re = discreteUniform( -50, 50 ); - var im = discreteUniform( -50, 50 ); - return new Complex128( re, im ); -} +// Create an array of random numbers: +var arr = new Complex128Array( uniform( 200, -50.0, 50.0 ) ); -var z1; -var z2; -var i; -for ( i = 0; i < 100; i++ ) { - z1 = randomComplex(); - z2 = cexp( z1 ); - console.log( 'cexp(%s) = %s', z1.toString(), z2.toString() ); -} +// Compute the exponential function of each number in the array: +logEachMap( 'cexp(%s) = %s', arr, cexp ); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/cexp/lib/assign.js new file mode 100644 index 000000000000..25315ba611bd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/lib/assign.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 copysign = require( '@stdlib/math/base/special/copysign' ); +var sincos = require( '@stdlib/math/base/special/sincos' ).assign; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); +var exp = require( '@stdlib/math/base/special/exp' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// VARIABLES // + +var WORKSPACE = [ 0.0, 0.0 ]; + + +// MAIN // + +/** +* Evaluates the exponential function for a double-precision complex floating-point number and assigns results to a provided output array. +* +* @param {number} re - real component +* @param {number} im - imaginary component +* @param {Collection} out - output array +* @param {integer} strideOut - stride length +* @param {NonNegativeInteger} offsetOut - starting index +* @returns {Collection} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out = assign( 0.0, 0.0, new Float64Array( 2 ), 1, 0 ); +* // returns [ 1.0, 0.0 ] +*/ +function assign( re, im, out, strideOut, offsetOut ) { + var e; + + if ( isnan( re ) ) { + out[ offsetOut ] = NaN; + out[ offsetOut+strideOut ] = ( im === 0.0 ) ? im : NaN; + return out; + } + if ( isInfinite( im ) ) { + if ( re === PINF ) { + out[ offsetOut ] = NINF; + out[ offsetOut+strideOut ] = NaN; + return out; + } + if ( re === NINF ) { + out[ offsetOut ] = -0.0; + out[ offsetOut+strideOut ] = copysign( 0.0, im ); + return out; + } + out[ offsetOut ] = NaN; + out[ offsetOut+strideOut ] = NaN; + return out; + } + e = exp( re ); + if ( im === 0.0 ) { + out[ offsetOut ] = e; + out[ offsetOut+strideOut ] = im; + return out; + } + sincos( im, WORKSPACE, 1, 0 ); + out[ offsetOut ] = WORKSPACE[ 1 ] * e; + out[ offsetOut+strideOut ] = WORKSPACE[ 0 ] * e; + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cexp/lib/index.js index 5ea9af7f7212..eab7835d3ead 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/lib/index.js @@ -33,9 +33,20 @@ // MODULES // +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); +var assign = require( './assign.js' ); +var strided = require( './strided.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); +setReadOnly( main, 'strided', strided ); // EXPORTS // module.exports = main; + +// exports: { "assign": "main.assign", "strided": "main.strided" } diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cexp/lib/main.js index 7b6bd47c7cdf..0fcff72d9a0e 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/lib/main.js @@ -21,20 +21,15 @@ // MODULES // var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var copysign = require( '@stdlib/math/base/special/copysign' ); -var sincos = require( '@stdlib/math/base/special/sincos' ).assign; -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); -var exp = require( '@stdlib/math/base/special/exp' ); -var PINF = require( '@stdlib/constants/float64/pinf' ); -var NINF = require( '@stdlib/constants/float64/ninf' ); +var Float64Array = require( '@stdlib/array/float64' ); var real = require( '@stdlib/complex/float64/real' ); var imag = require( '@stdlib/complex/float64/imag' ); +var assign = require( './assign.js' ); // VARIABLES // -var WORKSPACE = [ 0.0, 0.0 ]; +var out = new Float64Array( 2 ); // MAIN // @@ -60,38 +55,8 @@ var WORKSPACE = [ 0.0, 0.0 ]; * // returns [ ~2.718, 0.0 ] */ function cexp( z ) { - var im; - var re; - var e; - - re = real( z ); - im = imag( z ); - - if ( isnan( re ) ) { - re = NaN; - im = ( im === 0.0 ) ? im : re; - } else if ( isInfinite( im ) ) { - if ( re === PINF ) { - re = -re; - im = NaN; - } else if ( re === NINF ) { - re = -0.0; - im = copysign( 0.0, im ); - } else { - re = NaN; - im = NaN; - } - } else { - e = exp( re ); - if ( im === 0.0 ) { - re = e; - } else { - sincos( im, WORKSPACE, 1, 0 ); - re = WORKSPACE[ 1 ] * e; - im = WORKSPACE[ 0 ] * e; - } - } - return new Complex128( re, im ); + assign( real( z ), imag( z ), out, 1, 0 ); + return new Complex128( out[ 0 ], out[ 1 ] ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/lib/strided.js b/lib/node_modules/@stdlib/math/base/special/cexp/lib/strided.js new file mode 100644 index 000000000000..3ead943adfe9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/lib/strided.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 assign = require( './assign.js' ); + + +// MAIN // + +/** +* Evaluates the exponential function for a double-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. +* +* @param {Float64Array} z - complex number view +* @param {integer} strideZ - stride length for `z` +* @param {NonNegativeInteger} offsetZ - starting index for `z` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var z = new Float64Array( [ 0.0, 0.0 ] ); +* +* var out = strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); +* // returns [ 1.0, 0.0 ] +*/ +function strided( z, strideZ, offsetZ, out, strideOut, offsetOut ) { + return assign( z[ offsetZ ], z[ offsetZ+strideZ ], out, strideOut, offsetOut ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = strided; diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.assign.js new file mode 100644 index 000000000000..fc80a6af08dc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.assign.js @@ -0,0 +1,239 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isAlmostSameFloat64Array = require( '@stdlib/assert/is-almost-same-float64array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cexp = require( './../lib/assign.js' ); + + +// FIXTURES // + +var pureImaginary = require( './fixtures/julia/pure_imaginary.json' ); +var generalComplex = require( './fixtures/julia/general_complex.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cexp, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates the complex exponential', function test( t ) { + var expected; + var out; + var v; + + out = new Float64Array( 2 ); + v = cexp( 0.0, 0.0, out, 1, 0 ); + + expected = new Float64Array( [ 1.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + out = new Float64Array( 4 ); + v = cexp( 0.0, 0.0, out, 2, 0 ); + + expected = new Float64Array( [ 1.0, 0.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + out = new Float64Array( 4 ); + v = cexp( 0.0, 0.0, out, 2, 1 ); + + expected = new Float64Array( [ 0.0, 1.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + out = new Float64Array( 4 ); + v = cexp( 0.0, 0.0, out, -2, 3 ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 1.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes exp(z) for pure imaginary z', function test( t ) { + var expected; + var expre; + var expim; + var out; + var re; + var im; + var i; + + re = pureImaginary.re; + im = pureImaginary.im; + expre = pureImaginary.expre; + expim = pureImaginary.expim; + + out = new Float64Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + cexp( re[ i ], im[ i ], out, 1, 0 ); + expected = new Float64Array( [ expre[ i ], expim[ i ] ] ); + t.strictEqual( isAlmostSameFloat64Array( out, expected, 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes exp(z) for complex z', function test( t ) { + var expected; + var expre; + var expim; + var out; + var re; + var im; + var i; + + re = generalComplex.re; + im = generalComplex.im; + expre = generalComplex.expre; + expim = generalComplex.expim; + + out = new Float64Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + cexp( re[ i ], im[ i ], out, 1, 0 ); + expected = new Float64Array( [ expre[ i ], expim[ i ] ] ); + t.strictEqual( isAlmostSameFloat64Array( out, expected, 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if imaginary component is `+Infinity`, the function returns `NaN` components', function test( t ) { + var out = new Float64Array( 2 ); + + cexp( 0.0, PINF, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `-Infinity`, the function returns `NaN` components', function test( t ) { + var out = new Float64Array( 2 ); + + cexp( 0.0, NINF, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity`, the function returns both components equal to `0`', function test( t ) { + var expected; + var out; + + out = new Float64Array( 2 ); + cexp( NINF, 1.0, out, 1, 0 ); + + expected = new Float64Array( [ 0.0, 0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is `0.0`, the function returns `+Infinity` and `0.0`', function test( t ) { + var expected; + var out; + + out = new Float64Array( 2 ); + cexp( PINF, 0.0, out, 1, 0 ); + + expected = new Float64Array( [ PINF, 0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `0.0`, the function returns `NaN` and `0.0`', function test( t ) { + var out = new Float64Array( 2 ); + + cexp( NaN, 0.0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `NaN`, the function returns `NaN` components', function test( t ) { + var out = new Float64Array( 2 ); + + cexp( 5.0, NaN, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + + cexp( 0.0, NaN, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + + cexp( NaN, NaN, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is `+Infinity`, the function returns `-Infinity` and `NaN`', function test( t ) { + var out = new Float64Array( 2 ); + + cexp( PINF, PINF, out, 1, 0 ); + t.strictEqual( out[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `+Infinity`, the function returns `-0.0` and `+0.0`', function test( t ) { + var expected; + var out; + + out = new Float64Array( 2 ); + cexp( NINF, PINF, out, 1, 0 ); + + expected = new Float64Array( [ -0.0, 0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `-Infinity`, the function returns `-0.0` and `-0.0`', function test( t ) { + var expected; + var out; + + out = new Float64Array( 2 ); + cexp( NINF, NINF, out, 1, 0 ); + + expected = new Float64Array( [ -0.0, -0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.js b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.js index 6f1145bef1a2..0b0e77e8a190 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.js @@ -21,25 +21,10 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); -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/ctor' ); -var real = require( '@stdlib/complex/float64/real' ); -var imag = require( '@stdlib/complex/float64/imag' ); +var isMethod = require( '@stdlib/assert/is-method' ); var cexp = require( './../lib' ); -// FIXTURES // - -var pureImaginary = require( './fixtures/julia/pure_imaginary.json' ); -var generalComplex = require( './fixtures/julia/general_complex.json' ); - - // TESTS // tape( 'main export is a function', function test( t ) { @@ -48,214 +33,12 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns a double-precision complex floating-point number', function test( t ) { - var v; - - v = cexp( new Complex128( 0.0, 0.0 ) ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function computes exp(z) for pure imaginary z', function test( t ) { - var delta; - var expre; - var expim; - var tol; - var re; - var im; - var i; - var q; - - re = pureImaginary.re; - im = pureImaginary.im; - expre = pureImaginary.expre; - expim = pureImaginary.expim; - - for ( i = 0; i < re.length; i++ ) { - q = cexp( new Complex128( re[ i ], im[ i ] ) ); - if ( real( q ) === expre[ i ] ) { - t.strictEqual( real( q ), expre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - expre[ i ] ); - tol = EPS * abs( expre[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+expre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === expim[ i ] ) { - t.strictEqual( imag( q ), expim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - expim[ i ] ); - tol = EPS * abs( expim[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+expim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes exp(z) for complex z', function test( t ) { - var delta; - var expre; - var expim; - var tol; - var re; - var im; - var i; - var q; - - re = generalComplex.re; - im = generalComplex.im; - expre = generalComplex.expre; - expim = generalComplex.expim; - - for ( i = 0; i < re.length; i++ ) { - q = cexp( new Complex128( re[ i ], im[ i ] ) ); - if ( real( q ) === expre[ i ] ) { - t.strictEqual( real( q ), expre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - expre[ i ] ); - tol = EPS * abs( expre[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+expre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === expim[ i ] ) { - t.strictEqual( imag( q ), expim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - expim[ i ] ); - tol = EPS * abs( expim[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+expim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'if imaginary component is `+Infinity`, the function returns a complex number having `NaN` components', function test( t ) { - var v; - - v = cexp( new Complex128( 0.0, PINF ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'if imaginary component is `-Infinity`, the function returns a complex number having `NaN` components', function test( t ) { - var v; - - v = cexp( new Complex128( 0.0, NINF ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is `-Infinity`, the function returns a complex number with both components equal to `0`', function test( t ) { - var v; - - v = cexp( new Complex128( NINF, 1.0 ) ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is `+Infinity` and imaginary component is `0.0`, the function returns a complex number with the real component equal to `+Infinity` and imaginary component equal to `0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( PINF, 0.0 ) ); - t.strictEqual( real( v ), PINF, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is `NaN` and imaginary component is `0.0`, the function returns a complex number with the real component equal to `NaN` and imaginary component equal to `0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( NaN, 0.0 ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'if imaginary component is `NaN`, the function returns a complex number with both components equal to `NaN`', function test( t ) { - var v; - - v = cexp( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); - - v = cexp( new Complex128( 0.0, NaN ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); - - v = cexp( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if imaginary component is `+0.0`, the function returns a complex number with an imaginary component equal to `+0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( 3.0, 0.0 ) ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns +0.0' ); - t.end(); -}); - -tape( 'if imaginary component is `-0.0`, the function returns a complex number with an imaginary component equal to `-0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( 3.0, -0.0 ) ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns -0.0' ); - t.end(); -}); - -tape( 'if real component is `NaN` and imaginary component is nonzero, the function returns a complex number with both components equal to `NaN`', function test( t ) { - var v; - - v = cexp( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( cexp, 'assign' ), true, 'returns expected value' ); t.end(); }); -tape( 'if real component is `NaN` and imaginary component is `+0.0`, the function returns a complex number with an imaginary component equal to `+0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( NaN, 0.0 ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns +0.0' ); - t.end(); -}); - -tape( 'if real component is `NaN` and imaginary component is `-0.0`, the function returns a complex number with an imaginary component equal to `-0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( NaN, -0.0 ) ); - t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns +0.0' ); - t.end(); -}); - -tape( 'if real component is `+Infinity` and imaginary component is `+Infinity`, the function returns a complex number with the real component equal to `-Infinity` and imaginary component equal to `NaN`', function test( t ) { - var v; - - v = cexp( new Complex128( PINF, PINF ) ); - t.strictEqual( real( v ), NINF, 'returns expected value' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is `-Infinity` and imaginary component is `+Infinity`, the function returns a complex number with the real component equal to `-0.0` and imaginary component equal to `+0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( NINF, PINF ) ); - t.strictEqual( isNegativeZero( real( v ) ), true, 'returns -0.0' ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns +0.0' ); - t.end(); -}); - -tape( 'if real component is `-Infinity` and imaginary component is `-Infinity`, the function returns a complex number with the real component equal to `-0.0` and imaginary component equal to `-0.0`', function test( t ) { - var v; - - v = cexp( new Complex128( NINF, NINF ) ); - t.strictEqual( isNegativeZero( real( v ) ), true, 'returns -0.0' ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns -0.0' ); +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.strictEqual( isMethod( cexp, 'strided' ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.main.js new file mode 100644 index 000000000000..fc90e98b89b0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.main.js @@ -0,0 +1,232 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var cexp = require( './../lib' ); + + +// FIXTURES // + +var pureImaginary = require( './fixtures/julia/pure_imaginary.json' ); +var generalComplex = require( './fixtures/julia/general_complex.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cexp, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a double-precision complex floating-point number', function test( t ) { + var v; + + v = cexp( new Complex128( 0.0, 0.0 ) ); + t.strictEqual( real( v ), 1.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure imaginary z', function test( t ) { + var expre; + var expim; + var re; + var im; + var i; + var q; + + re = pureImaginary.re; + im = pureImaginary.im; + expre = pureImaginary.expre; + expim = pureImaginary.expim; + + for ( i = 0; i < re.length; i++ ) { + q = cexp( new Complex128( re[ i ], im[ i ] ) ); + t.strictEqual( isAlmostSameValue( real( q ), expre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( q ), expim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes exp(z) for complex z', function test( t ) { + var expre; + var expim; + var re; + var im; + var i; + var q; + + re = generalComplex.re; + im = generalComplex.im; + expre = generalComplex.expre; + expim = generalComplex.expim; + + for ( i = 0; i < re.length; i++ ) { + q = cexp( new Complex128( re[ i ], im[ i ] ) ); + t.strictEqual( isAlmostSameValue( real( q ), expre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( q ), expim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if imaginary component is `+Infinity`, the function returns a complex number having `NaN` components', function test( t ) { + var v; + + v = cexp( new Complex128( 0.0, PINF ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `-Infinity`, the function returns a complex number having `NaN` components', function test( t ) { + var v; + + v = cexp( new Complex128( 0.0, NINF ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity`, the function returns a complex number with both components equal to `0`', function test( t ) { + var v; + + v = cexp( new Complex128( NINF, 1.0 ) ); + t.strictEqual( real( v ), 0.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is `0.0`, the function returns a complex number with the real component equal to `+Infinity` and imaginary component equal to `0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( PINF, 0.0 ) ); + t.strictEqual( real( v ), PINF, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `0.0`, the function returns a complex number with the real component equal to `NaN` and imaginary component equal to `0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( NaN, 0.0 ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `NaN`, the function returns a complex number with both components equal to `NaN`', function test( t ) { + var v; + + v = cexp( new Complex128( 5.0, NaN ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + + v = cexp( new Complex128( 0.0, NaN ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + + v = cexp( new Complex128( NaN, NaN ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if imaginary component is `+0.0`, the function returns a complex number with an imaginary component equal to `+0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( 3.0, 0.0 ) ); + t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `-0.0`, the function returns a complex number with an imaginary component equal to `-0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( 3.0, -0.0 ) ); + t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is nonzero, the function returns a complex number with both components equal to `NaN`', function test( t ) { + var v; + + v = cexp( new Complex128( NaN, 3.0 ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `+0.0`, the function returns a complex number with an imaginary component equal to `+0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( NaN, 0.0 ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `-0.0`, the function returns a complex number with an imaginary component equal to `-0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( NaN, -0.0 ) ); + t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is `+Infinity`, the function returns a complex number with the real component equal to `-Infinity` and imaginary component equal to `NaN`', function test( t ) { + var v; + + v = cexp( new Complex128( PINF, PINF ) ); + t.strictEqual( real( v ), NINF, 'returns expected value' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `+Infinity`, the function returns a complex number with the real component equal to `-0.0` and imaginary component equal to `+0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( NINF, PINF ) ); + t.strictEqual( isNegativeZero( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `-Infinity`, the function returns a complex number with the real component equal to `-0.0` and imaginary component equal to `-0.0`', function test( t ) { + var v; + + v = cexp( new Complex128( NINF, NINF ) ); + t.strictEqual( isNegativeZero( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.native.js index bfc709c75c1a..dbc4536203ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.native.js @@ -22,11 +22,10 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); -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/ctor' ); @@ -67,10 +66,8 @@ tape( 'the function returns a double-precision complex floating-point number', o }); tape( 'the function computes exp(z) for pure imaginary z', opts, function test( t ) { - var delta; var expre; var expim; - var tol; var re; var im; var i; @@ -83,29 +80,15 @@ tape( 'the function computes exp(z) for pure imaginary z', opts, function test( for ( i = 0; i < re.length; i++ ) { q = cexp( new Complex128( re[ i ], im[ i ] ) ); - if ( real( q ) === expre[ i ] ) { - t.strictEqual( real( q ), expre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - expre[ i ] ); - tol = EPS * abs( expre[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+expre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === expim[ i ] ) { - t.strictEqual( imag( q ), expim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - expim[ i ] ); - tol = EPS * abs( expim[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+expim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( real( q ), expre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( q ), expim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes exp(z) for complex z', opts, function test( t ) { - var delta; var expre; var expim; - var tol; var re; var im; var i; @@ -118,20 +101,8 @@ tape( 'the function computes exp(z) for complex z', opts, function test( t ) { for ( i = 0; i < re.length; i++ ) { q = cexp( new Complex128( re[ i ], im[ i ] ) ); - if ( real( q ) === expre[ i ] ) { - t.strictEqual( real( q ), expre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - expre[ i ] ); - tol = EPS * abs( expre[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. real: '+real( q )+'. expected: '+expre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === expim[ i ] ) { - t.strictEqual( imag( q ), expim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - expim[ i ] ); - tol = 2.0 * EPS * abs( expim[ i ] ); - t.ok( delta <= tol, 'within tolerance. z: '+re[i]+'+ '+im[i]+'i. imag: '+imag( q )+'. expected: '+expim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( real( q ), expre[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( q ), expim[ i ], 2 ), true, 'returns expected value' ); } t.end(); }); @@ -203,7 +174,7 @@ tape( 'if imaginary component is `+0.0`, the function returns a complex number w var v; v = cexp( new Complex128( 3.0, 0.0 ) ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns +0.0' ); + t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); t.end(); }); @@ -211,7 +182,7 @@ tape( 'if imaginary component is `-0.0`, the function returns a complex number w var v; v = cexp( new Complex128( 3.0, -0.0 ) ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns -0.0' ); + t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); t.end(); }); @@ -229,7 +200,7 @@ tape( 'if real component is `NaN` and imaginary component is `+0.0`, the functio v = cexp( new Complex128( NaN, 0.0 ) ); t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns +0.0' ); + t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); t.end(); }); @@ -238,7 +209,7 @@ tape( 'if real component is `NaN` and imaginary component is `-0.0`, the functio v = cexp( new Complex128( NaN, -0.0 ) ); t.strictEqual( isnan( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns +0.0' ); + t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); t.end(); }); @@ -255,8 +226,8 @@ tape( 'if real component is `-Infinity` and imaginary component is `+Infinity`, var v; v = cexp( new Complex128( NINF, PINF ) ); - t.strictEqual( isNegativeZero( real( v ) ), true, 'returns -0.0' ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns +0.0' ); + t.strictEqual( isNegativeZero( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); t.end(); }); @@ -264,7 +235,7 @@ tape( 'if real component is `-Infinity` and imaginary component is `-Infinity`, var v; v = cexp( new Complex128( NINF, NINF ) ); - t.strictEqual( isNegativeZero( real( v ) ), true, 'returns -0.0' ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns -0.0' ); + t.strictEqual( isNegativeZero( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cexp/test/test.strided.js b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.strided.js new file mode 100644 index 000000000000..9190aa8e7523 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexp/test/test.strided.js @@ -0,0 +1,268 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isAlmostSameFloat64Array = require( '@stdlib/assert/is-almost-same-float64array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cexp = require( './../lib/strided.js' ); + + +// FIXTURES // + +var pureImaginary = require( './fixtures/julia/pure_imaginary.json' ); +var generalComplex = require( './fixtures/julia/general_complex.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cexp, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates the complex exponential', function test( t ) { + var expected; + var out; + var z; + var v; + + z = new Float64Array( [ 0.0, 0.0 ] ); + out = new Float64Array( 2 ); + v = cexp( z, 1, 0, out, 1, 0 ); + + expected = new Float64Array( [ 1.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + z = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + out = new Float64Array( 4 ); + v = cexp( z, 2, 0, out, 2, 0 ); + + expected = new Float64Array( [ 1.0, 0.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + z = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + out = new Float64Array( 4 ); + v = cexp( z, 2, 1, out, 2, 1 ); + + expected = new Float64Array( [ 0.0, 1.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + z = new Float64Array( [ 0.0, 0.0 ] ); + out = new Float64Array( 4 ); + v = cexp( z, -1, 1, out, -2, 3 ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 1.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes exp(z) for pure imaginary z', function test( t ) { + var expected; + var expre; + var expim; + var out; + var re; + var im; + var z; + var i; + + re = pureImaginary.re; + im = pureImaginary.im; + expre = pureImaginary.expre; + expim = pureImaginary.expim; + + z = new Float64Array( 2 ); + out = new Float64Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + z[ 0 ] = re[ i ]; + z[ 1 ] = im[ i ]; + cexp( z, 1, 0, out, 1, 0 ); + expected = new Float64Array( [ expre[ i ], expim[ i ] ] ); + t.strictEqual( isAlmostSameFloat64Array( out, expected, 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes exp(z) for complex z', function test( t ) { + var expected; + var expre; + var expim; + var out; + var re; + var im; + var z; + var i; + + re = generalComplex.re; + im = generalComplex.im; + expre = generalComplex.expre; + expim = generalComplex.expim; + + z = new Float64Array( 2 ); + out = new Float64Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + z[ 0 ] = re[ i ]; + z[ 1 ] = im[ i ]; + cexp( z, 1, 0, out, 1, 0 ); + expected = new Float64Array( [ expre[ i ], expim[ i ] ] ); + t.strictEqual( isAlmostSameFloat64Array( out, expected, 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if imaginary component is `+Infinity`, the function returns `NaN` components', function test( t ) { + var out = new Float64Array( 2 ); + var z = new Float64Array( [ 0.0, PINF ] ); + + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `-Infinity`, the function returns `NaN` components', function test( t ) { + var out = new Float64Array( 2 ); + var z = new Float64Array( [ 0.0, NINF ] ); + + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity`, the function returns both components equal to `0`', function test( t ) { + var expected; + var out; + var z; + + z = new Float64Array( [ NINF, 1.0 ] ); + out = new Float64Array( 2 ); + cexp( z, 1, 0, out, 1, 0 ); + + expected = new Float64Array( [ 0.0, 0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is `0.0`, the function returns `+Infinity` and `0.0`', function test( t ) { + var expected; + var out; + var z; + + z = new Float64Array( [ PINF, 0.0 ] ); + out = new Float64Array( 2 ); + cexp( z, 1, 0, out, 1, 0 ); + + expected = new Float64Array( [ PINF, 0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `0.0`, the function returns `NaN` and `0.0`', function test( t ) { + var out = new Float64Array( 2 ); + var z = new Float64Array( [ NaN, 0.0 ] ); + + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `NaN`, the function returns `NaN` components', function test( t ) { + var out = new Float64Array( 2 ); + var z; + + z = new Float64Array( [ 5.0, NaN ] ); + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + + z = new Float64Array( [ 0.0, NaN ] ); + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + + z = new Float64Array( [ NaN, NaN ] ); + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnan( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is `+Infinity`, the function returns `-Infinity` and `NaN`', function test( t ) { + var out = new Float64Array( 2 ); + var z = new Float64Array( [ PINF, PINF ] ); + + cexp( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isnan( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `+Infinity`, the function returns `-0.0` and `+0.0`', function test( t ) { + var expected; + var out; + var z; + + z = new Float64Array( [ NINF, PINF ] ); + out = new Float64Array( 2 ); + cexp( z, 1, 0, out, 1, 0 ); + + expected = new Float64Array( [ -0.0, 0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `-Infinity`, the function returns `-0.0` and `-0.0`', function test( t ) { + var expected; + var out; + var z; + + z = new Float64Array( [ NINF, NINF ] ); + out = new Float64Array( 2 ); + cexp( z, 1, 0, out, 1, 0 ); + + expected = new Float64Array( [ -0.0, -0.0 ] ); + + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + t.end(); +});