diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/README.md b/lib/node_modules/@stdlib/math/base/special/cexpf/README.md index bf2ded3c1fb6..3f2a92963625 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/README.md @@ -65,6 +65,55 @@ v = cexpf( new Complex64( 0.0, 1.0 ) ); // returns [ ~0.540, ~0.841 ] ``` +#### cexpf.assign( re, im, out, strideOut, offsetOut ) + +Evaluates the [exponential][exponential-function] function for a single-precision complex floating-point number and assigns results to a provided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var out = new Float32Array( 2 ); +var v = cexpf.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`. + +#### cexpf.strided( z, sz, oz, out, so, oo ) + +Evaluates the [exponential][exponential-function] function for a single-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var z = new Float32Array( [ 0.0, 0.0 ] ); +var out = new Float32Array( 2 ); + +var v = cexpf.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`. + diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..65711468e289 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assign = require( './../lib' ).assign; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// 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 Float32Array( 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 ( isnanf( out[ 0 ] ) || isnanf( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.js index b216588ab8ba..9a8f47623026 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.js @@ -21,30 +21,36 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); var pkg = require( './../package.json' ).name; var cexpf = require( './../lib' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // MAIN // bench( pkg, function benchmark( b ) { - var values; + var zbuf; + var z; var y; var i; - values = [ - new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ), - new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ) - ]; + zbuf = uniform( 200, -50.0, 50.0, options ); + z = new Complex64Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cexpf( values[ i%values.length ] ); + y = cexpf( z.get( i%100 ) ); if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.native.js index ad651b3e1aee..5e75183cac0a 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.native.js @@ -22,11 +22,11 @@ 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); var tryRequire = require( '@stdlib/utils/try-require' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -38,23 +38,25 @@ var cexpf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( cexpf instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // MAIN // bench( format( '%s::native', pkg ), opts, function benchmark( b ) { - var values; + var zbuf; + var z; var y; var i; - values = [ - new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ), - new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ) - ]; + zbuf = uniform( 200, -50.0, 50.0, options ); + z = new Complex64Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cexpf( values[ i%values.length ] ); + y = cexpf( z.get( i%100 ) ); if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.strided.js b/lib/node_modules/@stdlib/math/base/special/cexpf/benchmark/benchmark.strided.js new file mode 100644 index 000000000000..8d9708629992 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var strided = require( './../lib' ).strided; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// 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 Float32Array( 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 ( isnanf( out[ 0 ] ) || isnanf( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cexpf/docs/repl.txt index 2a1fea7b335d..aea13c87293d 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/docs/repl.txt @@ -20,6 +20,77 @@ > y = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( 0.0, 1.0 ) ) [ ~0.540, ~0.841 ] + +{{alias}}.assign( re, im, out, strideOut, offsetOut ) + Evaluates the exponential function for a single-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/float32}}( 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 single-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/float32}}( [ 0.0, 0.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 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/cexpf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/index.d.ts index 445a251aefb6..6d90b9c32055 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/index.d.ts @@ -21,6 +21,69 @@ /// import { Complex64 } from '@stdlib/types/complex'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for evaluating the exponential function for a single-precision complex floating-point number. +*/ +interface Cexpf { + /** + * Evaluates the exponential function for a single-precision complex floating-point number. + * + * @param z - complex number + * @returns result + * + * @example + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * + * var v = cexpf( new Complex64( 0.0, 0.0 ) ); + * // returns [ 1.0, 0.0 ] + */ + ( z: Complex64 ): Complex64; + + /** + * Evaluates the exponential function for a single-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 Float32Array = require( '@stdlib/array/float32' ); + * + * var out = new Float32Array( 2 ); + * var v = cexpf.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 single-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 Float32Array = require( '@stdlib/array/float32' ); + * + * var z = new Float32Array( [ 0.0, 0.0 ] ); + * + * var out = cexpf.strided( z, 1, 0, new Float32Array( 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 single-precision complex floating-point number. @@ -35,12 +98,24 @@ import { Complex64 } from '@stdlib/types/complex'; * // returns [ 1.0, 0.0 ] * * @example -* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var out = new Float32Array( 2 ); +* var v = cexpf.assign( 0.0, 0.0, out, 1, 0 ); +* // returns [ 1.0, 0.0 ] +* +* var bool = ( out === v ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var z = new Float32Array( [ 0.0, 0.0 ] ); * -* var v = cexpf( new Complex64( 1.0, 0.0 ) ); -* // returns [ ~2.718, 0.0 ] +* var out = cexpf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); +* // returns [ 1.0, 0.0 ] */ -declare function cexpf( z: Complex64 ): Complex64; +declare var cexpf: Cexpf; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/test.ts index 8d042f85f9ec..5dcde0bd992d 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/docs/types/test.ts @@ -44,3 +44,203 @@ import cexpf = require( './index' ); { cexpf(); // $ExpectError } + +// Attached to the main export is an `assign` method which returns a collection... +{ + cexpf.assign( 1.0, 1.0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cexpf.assign( 1.0, 1.0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cexpf.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 Float32Array( 2 ); + + cexpf.assign( true, 2.0, out, 1, 0 ); // $ExpectError + cexpf.assign( false, 2.0, out, 1, 0 ); // $ExpectError + cexpf.assign( null, 2.0, out, 1, 0 ); // $ExpectError + cexpf.assign( undefined, 2.0, out, 1, 0 ); // $ExpectError + cexpf.assign( '5', 2.0, out, 1, 0 ); // $ExpectError + cexpf.assign( [], 2.0, out, 1, 0 ); // $ExpectError + cexpf.assign( {}, 2.0, out, 1, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + + cexpf.assign( 1.0, true, out, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, false, out, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, null, out, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, undefined, out, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, '5', out, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, [], out, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, {}, out, 1, 0 ); // $ExpectError + cexpf.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... +{ + cexpf.assign( 1.0, 2.0, 1, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, true, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, false, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, null, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, undefined, 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, '5', 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, [ '5' ], 1, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, {}, 1, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + + cexpf.assign( 1.0, 2.0, out, true, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, false, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, null, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, undefined, 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, '5', 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, [], 0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, {}, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + + cexpf.assign( 1.0, 2.0, out, 1, true ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1, false ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1, null ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1, undefined ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1, '5' ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1, [] ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1, {} ); // $ExpectError + cexpf.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 Float32Array( 2 ); + + cexpf.assign(); // $ExpectError + cexpf.assign( 1.0 ); // $ExpectError + cexpf.assign( 1.0, 2.0 ); // $ExpectError + cexpf.assign( 1.0, 2.0, out ); // $ExpectError + cexpf.assign( 1.0, 2.0, out, 1 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + + cexpf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cexpf.strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cexpf.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 Float32Array( 2 ); + + cexpf.strided( true, 1, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( false, 1, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( null, 1, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( undefined, 1, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( '5', 1, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( [ '5' ], 1, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( {}, 1, 0, out, 1, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cexpf.strided( z, true, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( z, false, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( z, null, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( z, undefined, 0, out, 1, 0 ); // $ExpectError + cexpf.strided( z, '5', 0, out, 1, 0 ); // $ExpectError + cexpf.strided( z, [], 0, out, 1, 0 ); // $ExpectError + cexpf.strided( z, {}, 0, out, 1, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cexpf.strided( z, 1, true, out, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, false, out, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, null, out, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, undefined, out, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, '5', out, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, [], out, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, {}, out, 1, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + + cexpf.strided( z, 1, 0, 1, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, true, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, false, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, null, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, undefined, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, '5', 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, [ '5' ], 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, {}, 1, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cexpf.strided( z, 1, 0, out, true, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out, false, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out, null, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out, undefined, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out, '5', 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out, [], 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out, {}, 0 ); // $ExpectError + cexpf.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 Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cexpf.strided( z, 1, 0, out, 1, true ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, false ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, null ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, undefined ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, '5' ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, [] ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, {} ); // $ExpectError + cexpf.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 Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cexpf.strided(); // $ExpectError + cexpf.strided( z ); // $ExpectError + cexpf.strided( z, 1 ); // $ExpectError + cexpf.strided( z, 1, 0 ); // $ExpectError + cexpf.strided( z, 1, 0, out ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1 ); // $ExpectError + cexpf.strided( z, 1, 0, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/assign.js new file mode 100644 index 000000000000..c764bbf2f49d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/assign.js @@ -0,0 +1,94 @@ +/** +* @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 copysignf = require( '@stdlib/math/base/special/copysignf' ); +var sincosf = require( '@stdlib/math/base/special/sincosf' ).assign; +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' ); +var expf = require( '@stdlib/math/base/special/expf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); + + +// VARIABLES // + +var WORKSPACE = [ 0.0, 0.0 ]; + + +// MAIN // + +/** +* Evaluates the exponential function for a single-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 Float32Array = require( '@stdlib/array/float32' ); +* +* var out = assign( 0.0, 0.0, new Float32Array( 2 ), 1, 0 ); +* // returns [ 1.0, 0.0 ] +*/ +function assign( re, im, out, strideOut, offsetOut ) { + var e; + + if ( isnanf( re ) ) { + out[ offsetOut ] = NaN; + out[ offsetOut+strideOut ] = ( im === 0.0 ) ? im : NaN; + return out; + } + if ( isInfinitef( im ) ) { + if ( re === PINF ) { + out[ offsetOut ] = NINF; + out[ offsetOut+strideOut ] = NaN; + return out; + } + if ( re === NINF ) { + out[ offsetOut ] = -0.0; + out[ offsetOut+strideOut ] = copysignf( 0.0, im ); + return out; + } + out[ offsetOut ] = NaN; + out[ offsetOut+strideOut ] = NaN; + return out; + } + e = expf( re ); + if ( im === 0.0 ) { + out[ offsetOut ] = e; + out[ offsetOut+strideOut ] = im; + return out; + } + sincosf( im, WORKSPACE, 1, 0 ); + out[ offsetOut ] = f32( WORKSPACE[ 1 ] * e ); + out[ offsetOut+strideOut ] = f32( WORKSPACE[ 0 ] * e ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/index.js index 6d9aa39a88fd..75f1ef4f7f43 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/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/cexpf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/main.js index ed9dfa50b683..584c7b0e5339 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/main.js @@ -21,21 +21,15 @@ // MODULES // var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var copysignf = require( '@stdlib/math/base/special/copysignf' ); -var sincosf = require( '@stdlib/math/base/special/sincosf' ).assign; -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' ); -var expf = require( '@stdlib/math/base/special/expf' ); -var f32 = require( '@stdlib/number/float64/base/to-float32' ); -var PINF = require( '@stdlib/constants/float32/pinf' ); -var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); +var assign = require( './assign.js' ); // VARIABLES // -var WORKSPACE = [ 0.0, 0.0 ]; +var out = new Float32Array( 2 ); // MAIN // @@ -61,38 +55,8 @@ var WORKSPACE = [ 0.0, 0.0 ]; * // returns [ ~2.718, 0.0 ] */ function cexpf( z ) { - var im; - var re; - var e; - - re = realf( z ); - im = imagf( z ); - - if ( isnanf( re ) ) { - re = NaN; - im = ( im === 0.0 ) ? im : re; - } else if ( isInfinitef( im ) ) { - if ( re === PINF ) { - re = -re; - im = NaN; - } else if ( re === NINF ) { - re = -0.0; - im = copysignf( 0.0, im ); - } else { - re = NaN; - im = NaN; - } - } else { - e = expf( re ); - if ( im === 0.0 ) { - re = e; - } else { - sincosf( im, WORKSPACE, 1, 0 ); - re = f32( WORKSPACE[ 1 ] * e ); - im = f32( WORKSPACE[ 0 ] * e ); - } - } - return new Complex64( re, im ); + assign( realf( z ), imagf( z ), out, 1, 0 ); + return new Complex64( out[ 0 ], out[ 1 ] ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/native.js index c4429c4bc428..11f53ab0e61e 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/native.js @@ -35,14 +35,12 @@ var addon = require( './../src/addon.node' ); * * @example * var Complex64 = require( '@stdlib/complex/float32/ctor' ); -* var cexpf = require( '@stdlib/math/base/special/cexpf' ); * * var v = cexpf( new Complex64( 0.0, 0.0 ) ); * // returns [ 1.0, 0.0 ] * * @example * var Complex64 = require( '@stdlib/complex/float32/ctor' ); -* var cexpf = require( '@stdlib/math/base/special/cexpf' ); * * var v = cexpf( new Complex64( 1.0, 0.0 ) ); * // returns [ ~2.718, 0.0 ] diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/lib/strided.js b/lib/node_modules/@stdlib/math/base/special/cexpf/lib/strided.js new file mode 100644 index 000000000000..fb08b21fe997 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/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 single-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. +* +* @param {Float32Array} 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 Float32Array = require( '@stdlib/array/float32' ); +* +* var z = new Float32Array( [ 0.0, 0.0 ] ); +* +* var out = strided( z, 1, 0, new Float32Array( 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/cexpf/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.assign.js new file mode 100644 index 000000000000..dd3f9742154f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.assign.js @@ -0,0 +1,338 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var cexpf = 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 cexpf, '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 Float32Array( 2 ); + v = cexpf( 0.0, 0.0, out, 1, 0 ); + + expected = new Float32Array( [ 1.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = cexpf( 0.0, 0.0, out, 2, 0 ); + + expected = new Float32Array( [ 1.0, 0.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = cexpf( 0.0, 0.0, out, 2, 1 ); + + expected = new Float32Array( [ 0.0, 1.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = cexpf( 0.0, 0.0, out, -2, 3 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0, 1.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( 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 Float32Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + cexpf( f32( re[ i ] ), f32( im[ i ] ), out, 1, 0 ); + expected = new Float32Array( [ expre[ i ], expim[ i ] ] ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes exp(z) for complex z', function test( t ) { + 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 Float32Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + cexpf( f32( re[ i ] ), f32( im[ i ] ), out, 1, 0 ); + t.strictEqual( isAlmostSameValuef( out[ 0 ], f32( expre[ i ] ), 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( out[ 1 ], f32( expim[ i ] ), 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if imaginary component is `+Infinity`, the function returns `NaN` components', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( 0.0, PINF, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( 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 Float32Array( 2 ); + + cexpf( 0.0, NINF, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( 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 Float32Array( 2 ); + cexpf( NINF, 1.0, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( 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 Float32Array( 2 ); + cexpf( PINF, 0.0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( 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 Float32Array( 2 ); + + cexpf( NaN, 0.0, out, 1, 0 ); + t.strictEqual( isnanf( 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 Float32Array( 2 ); + + cexpf( 5.0, NaN, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + cexpf( 0.0, NaN, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + cexpf( NaN, NaN, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if imaginary component is `+0.0`, the function returns an imaginary component equal to `+0.0`', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( 3.0, 0.0, out, 1, 0 ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `-0.0`, the function returns an imaginary component equal to `-0.0`', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( 3.0, -0.0, out, 1, 0 ); + t.strictEqual( isNegativeZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is nonzero, the function returns `NaN` components', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( NaN, 3.0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `+0.0`, the function returns an imaginary component equal to `+0.0`', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( NaN, 0.0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `-0.0`, the function returns an imaginary component equal to `-0.0`', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( NaN, -0.0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( 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 Float32Array( 2 ); + + cexpf( PINF, PINF, out, 1, 0 ); + t.strictEqual( out[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isnanf( 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 Float32Array( 2 ); + cexpf( NINF, PINF, out, 1, 0 ); + + expected = new Float32Array( [ -0.0, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( 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 Float32Array( 2 ); + cexpf( NINF, NINF, out, 1, 0 ); + + expected = new Float32Array( [ -0.0, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure real z (positive)', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( 1.0, 0.0, out, 1, 0 ); + t.strictEqual( out[ 0 ], 2.7182817459106445, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure real z (negative)', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( -1.0, 0.0, out, 1, 0 ); + t.strictEqual( out[ 0 ], 0.3678794503211975, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is a large positive value and imaginary component is `0.0`, the function returns `+Infinity`', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( 89.0, 0.0, out, 1, 0 ); + t.strictEqual( out[ 0 ], PINF, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is finite and nonzero, the function returns infinite components', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( PINF, 1.0, out, 1, 0 ); + t.strictEqual( out[ 0 ], PINF, 'returns expected value' ); + t.strictEqual( out[ 1 ], PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `0.0`, the function returns both components equal to `+0.0`', function test( t ) { + var out = new Float32Array( 2 ); + + cexpf( NINF, 0.0, out, 1, 0 ); + t.strictEqual( isPositiveZerof( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( 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 Float32Array( 2 ); + + cexpf( PINF, NINF, out, 1, 0 ); + t.strictEqual( out[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.js b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.js index 2a4bdb703006..dd03a11b7e61 100644 --- a/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.js @@ -21,25 +21,10 @@ // MODULES // var tape = require( 'tape' ); -var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var f32 = require( '@stdlib/number/float64/base/to-float32' ); -var PINF = require( '@stdlib/constants/float32/pinf' ); -var NINF = require( '@stdlib/constants/float32/ninf' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var realf = require( '@stdlib/complex/float32/real' ); -var imagf = require( '@stdlib/complex/float32/imag' ); +var isMethod = require( '@stdlib/assert/is-method' ); var cexpf = 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,240 +33,12 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns a single-precision complex floating-point number', function test( t ) { - var v; - - v = cexpf( new Complex64( 0.0, 0.0 ) ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( 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 = cexpf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( realf( q ), f32( expre[ i ] ), 'returns expected value' ); - t.strictEqual( imagf( q ), f32( expim[ i ] ), '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 = cexpf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValuef( realf( q ), f32( expre[ i ] ), 2 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValuef( imagf( q ), f32( expim[ i ] ), 2 ), 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 = cexpf( new Complex64( 0.0, PINF ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( 0.0, NINF ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( NINF, 1.0 ) ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( 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 = cexpf( new Complex64( PINF, 0.0 ) ); - t.strictEqual( realf( v ), PINF, 'returns expected value' ); - t.strictEqual( imagf( 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 = cexpf( new Complex64( NaN, 0.0 ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( imagf( 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 = cexpf( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); - - v = cexpf( new Complex64( 0.0, NaN ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); - - v = cexpf( new Complex64( NaN, NaN ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( 3.0, 0.0 ) ); - t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( 3.0, -0.0 ) ); - t.strictEqual( isNegativeZerof( imagf( 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 = cexpf( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( NaN, 0.0 ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( NaN, -0.0 ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isNegativeZerof( imagf( 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 = cexpf( new Complex64( PINF, PINF ) ); - t.strictEqual( realf( v ), NINF, 'returns expected value' ); - t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( NINF, PINF ) ); - t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( cexpf, 'assign' ), 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 = cexpf( new Complex64( NINF, NINF ) ); - t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function computes exp(z) for pure real z (positive)', function test( t ) { - var v; - - v = cexpf( new Complex64( 1.0, 0.0 ) ); - t.strictEqual( realf( v ), 2.7182817459106445, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function computes exp(z) for pure real z (negative)', function test( t ) { - var v; - - v = cexpf( new Complex64( -1.0, 0.0 ) ); - t.strictEqual( realf( v ), 0.3678794503211975, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is a large positive value and imaginary component is `0.0`, the function returns `+Infinity`', function test( t ) { - var v; - - v = cexpf( new Complex64( 89.0, 0.0 ) ); - t.strictEqual( realf( v ), PINF, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is `+Infinity` and imaginary component is finite and nonzero, the function returns infinite components', function test( t ) { - var v; - - v = cexpf( new Complex64( PINF, 1.0 ) ); - t.strictEqual( realf( v ), PINF, 'returns expected value' ); - t.strictEqual( imagf( v ), PINF, 'returns expected value' ); - t.end(); -}); - -tape( 'if real component is `-Infinity` and imaginary component is `0.0`, the function returns a complex number with both components equal to `+0.0`', function test( t ) { - var v; - - v = cexpf( new Complex64( NINF, 0.0 ) ); - t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( PINF, NINF ) ); - t.strictEqual( realf( v ), NINF, 'returns expected value' ); - t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.strictEqual( isMethod( cexpf, 'strided' ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.main.js new file mode 100644 index 000000000000..2a4bdb703006 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.main.js @@ -0,0 +1,287 @@ +/** +* @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 isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var cexpf = 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 cexpf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a single-precision complex floating-point number', function test( t ) { + var v; + + v = cexpf( new Complex64( 0.0, 0.0 ) ); + t.strictEqual( realf( v ), 1.0, 'returns expected value' ); + t.strictEqual( imagf( 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 = cexpf( new Complex64( re[ i ], im[ i ] ) ); + t.strictEqual( realf( q ), f32( expre[ i ] ), 'returns expected value' ); + t.strictEqual( imagf( q ), f32( expim[ i ] ), '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 = cexpf( new Complex64( re[ i ], im[ i ] ) ); + t.strictEqual( isAlmostSameValuef( realf( q ), f32( expre[ i ] ), 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), f32( expim[ i ] ), 2 ), 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 = cexpf( new Complex64( 0.0, PINF ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( 0.0, NINF ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( NINF, 1.0 ) ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( 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 = cexpf( new Complex64( PINF, 0.0 ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( 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 = cexpf( new Complex64( NaN, 0.0 ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( imagf( 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 = cexpf( new Complex64( 5.0, NaN ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + v = cexpf( new Complex64( 0.0, NaN ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + v = cexpf( new Complex64( NaN, NaN ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( 3.0, 0.0 ) ); + t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( 3.0, -0.0 ) ); + t.strictEqual( isNegativeZerof( imagf( 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 = cexpf( new Complex64( NaN, 3.0 ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( NaN, 0.0 ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( NaN, -0.0 ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( 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 = cexpf( new Complex64( PINF, PINF ) ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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 = cexpf( new Complex64( NINF, PINF ) ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( NINF, NINF ) ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure real z (positive)', function test( t ) { + var v; + + v = cexpf( new Complex64( 1.0, 0.0 ) ); + t.strictEqual( realf( v ), 2.7182817459106445, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure real z (negative)', function test( t ) { + var v; + + v = cexpf( new Complex64( -1.0, 0.0 ) ); + t.strictEqual( realf( v ), 0.3678794503211975, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is a large positive value and imaginary component is `0.0`, the function returns `+Infinity`', function test( t ) { + var v; + + v = cexpf( new Complex64( 89.0, 0.0 ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is finite and nonzero, the function returns infinite components', function test( t ) { + var v; + + v = cexpf( new Complex64( PINF, 1.0 ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `0.0`, the function returns a complex number with both components equal to `+0.0`', function test( t ) { + var v; + + v = cexpf( new Complex64( NINF, 0.0 ) ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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 = cexpf( new Complex64( PINF, NINF ) ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.strided.js b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.strided.js new file mode 100644 index 000000000000..e389330dc9d1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cexpf/test/test.strided.js @@ -0,0 +1,378 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var cexpf = 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 cexpf, '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 Float32Array( [ 0.0, 0.0 ] ); + out = new Float32Array( 2 ); + v = cexpf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 1.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + out = new Float32Array( 4 ); + v = cexpf( z, 2, 0, out, 2, 0 ); + + expected = new Float32Array( [ 1.0, 0.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + out = new Float32Array( 4 ); + v = cexpf( z, 2, 1, out, 2, 1 ); + + expected = new Float32Array( [ 0.0, 1.0, 0.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 0.0 ] ); + out = new Float32Array( 4 ); + v = cexpf( z, -1, 1, out, -2, 3 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0, 1.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( 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 Float32Array( 2 ); + out = new Float32Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + z[ 0 ] = re[ i ]; + z[ 1 ] = im[ i ]; + cexpf( z, 1, 0, out, 1, 0 ); + expected = new Float32Array( [ expre[ i ], expim[ i ] ] ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes exp(z) for complex z', function test( t ) { + 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 Float32Array( 2 ); + out = new Float32Array( 2 ); + + for ( i = 0; i < re.length; i++ ) { + z[ 0 ] = re[ i ]; + z[ 1 ] = im[ i ]; + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isAlmostSameValuef( out[ 0 ], f32( expre[ i ] ), 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( out[ 1 ], f32( expim[ i ] ), 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if imaginary component is `+Infinity`, the function returns `NaN` components', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ 0.0, PINF ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( 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 Float32Array( 2 ); + var z = new Float32Array( [ 0.0, NINF ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( 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 Float32Array( [ NINF, 1.0 ] ); + out = new Float32Array( 2 ); + cexpf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( 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 Float32Array( [ PINF, 0.0 ] ); + out = new Float32Array( 2 ); + cexpf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( 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 Float32Array( 2 ); + var z = new Float32Array( [ NaN, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( 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 Float32Array( 2 ); + var z; + + z = new Float32Array( [ 5.0, NaN ] ); + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, NaN ] ); + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + z = new Float32Array( [ NaN, NaN ] ); + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if imaginary component is `+0.0`, the function returns an imaginary component equal to `+0.0`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ 3.0, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if imaginary component is `-0.0`, the function returns an imaginary component equal to `-0.0`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ 3.0, -0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isNegativeZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is nonzero, the function returns `NaN` components', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ NaN, 3.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `+0.0`, the function returns an imaginary component equal to `+0.0`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ NaN, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `NaN` and imaginary component is `-0.0`, the function returns an imaginary component equal to `-0.0`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ NaN, -0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( 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 Float32Array( 2 ); + var z = new Float32Array( [ PINF, PINF ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isnanf( 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 Float32Array( [ NINF, PINF ] ); + out = new Float32Array( 2 ); + cexpf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ -0.0, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( 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 Float32Array( [ NINF, NINF ] ); + out = new Float32Array( 2 ); + cexpf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ -0.0, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure real z (positive)', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ 1.0, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], 2.7182817459106445, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes exp(z) for pure real z (negative)', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ -1.0, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], 0.3678794503211975, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is a large positive value and imaginary component is `0.0`, the function returns `+Infinity`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ 89.0, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], PINF, 'returns expected value' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `+Infinity` and imaginary component is finite and nonzero, the function returns infinite components', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ PINF, 1.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], PINF, 'returns expected value' ); + t.strictEqual( out[ 1 ], PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'if real component is `-Infinity` and imaginary component is `0.0`, the function returns both components equal to `+0.0`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ NINF, 0.0 ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isPositiveZerof( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( 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 Float32Array( 2 ); + var z = new Float32Array( [ PINF, NINF ] ); + + cexpf( z, 1, 0, out, 1, 0 ); + t.strictEqual( out[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + t.end(); +});