From 472be997b9596a80e07d3ded6291b529d1e4ea94 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 10 Oct 2026 11:08:08 -0700 Subject: [PATCH] feat: add `assign` and `strided` methods to `math/base/special/croundf` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/croundf/README.md | 65 +++++- .../croundf/benchmark/benchmark.assign.js | 69 ++++++ .../special/croundf/benchmark/benchmark.js | 32 +-- .../croundf/benchmark/benchmark.native.js | 25 ++- .../croundf/benchmark/benchmark.strided.js | 67 ++++++ .../special/croundf/benchmark/c/benchmark.c | 3 +- .../math/base/special/croundf/docs/repl.txt | 71 ++++++ .../special/croundf/docs/types/index.d.ts | 89 +++++++- .../base/special/croundf/docs/types/test.ts | 203 +++++++++++++++++- .../base/special/croundf/examples/index.js | 16 +- .../math/base/special/croundf/lib/assign.js | 53 +++++ .../math/base/special/croundf/lib/index.js | 11 + .../math/base/special/croundf/lib/main.js | 15 +- .../math/base/special/croundf/lib/strided.js | 54 +++++ .../math/base/special/croundf/manifest.json | 12 +- .../base/special/croundf/test/test.assign.js | 167 ++++++++++++++ .../math/base/special/croundf/test/test.js | 70 +----- .../base/special/croundf/test/test.main.js | 104 +++++++++ .../base/special/croundf/test/test.native.js | 12 +- .../base/special/croundf/test/test.strided.js | 185 ++++++++++++++++ 20 files changed, 1194 insertions(+), 129 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.strided.js create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/lib/assign.js create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/lib/strided.js create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/test/test.main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/croundf/test/test.strided.js diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/README.md b/lib/node_modules/@stdlib/math/base/special/croundf/README.md index f03c49145e9c..1287d822cd36 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/croundf/README.md @@ -69,6 +69,55 @@ v = croundf( new Complex64( NaN, NaN ) ); // returns [ NaN, NaN ] ``` +#### croundf.assign( re, im, out, strideOut, offsetOut ) + +Rounds each component of a single-precision complex floating-point number to the nearest integer and assigns results to a provided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var out = new Float32Array( 2 ); +var v = croundf.assign( -1.5, 2.5, out, 1, 0 ); +// returns [ -1.0, 3.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`. + +#### croundf.strided( z, sz, oz, out, so, oo ) + +Rounds each component of a single-precision complex floating-point number stored in a real-valued strided array view to the nearest integer and assigns results to a provided strided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var z = new Float32Array( [ -1.5, 2.5 ] ); +var out = new Float32Array( 2 ); + +var v = croundf.strided( z, 1, 0, out, 1, 0 ); +// returns [ -1.0, 3.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`. + @@ -80,18 +129,16 @@ v = croundf( new Complex64( NaN, NaN ) ); ```javascript -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var croundf = require( '@stdlib/math/base/special/croundf' ); -var rand = uniform( -50.0, 50.0 ); +// Create an array of random numbers: +var arr = new Complex64Array( uniform( 200, -50.0, 50.0 ) ); -var z; -var i; -for ( i = 0; i < 100; i++ ) { - z = new Complex64( rand(), rand() ); - console.log( 'croundf(%s) = %s', z, croundf( z ) ); -} +// Round each component of each complex number to the nearest integer: +logEachMap( 'croundf(%s) = %s', arr, croundf ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..53a7c26922da --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/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, -500.0, 500.0, options ); + im = uniform( N, -500.0, 500.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/croundf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.js index 8b39a9e95e3f..f498fabe1788 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.js @@ -21,37 +21,43 @@ // 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 real = require( '@stdlib/complex/float32/real' ); -var imag = require( '@stdlib/complex/float32/imag' ); +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 croundf = 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( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), - new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) - ]; + zbuf = uniform( 200, -500.0, 500.0, options ); + z = new Complex64Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = croundf( values[ i%values.length ] ); - if ( isnanf( real( y ) ) ) { + y = croundf( z.get( i%100 ) ); + if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnanf( imag( y ) ) ) { - b.fail( 'should not return not NaN' ); + if ( isnanf( imagf( y ) ) ) { + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.native.js index c5c923242f3c..05d0e0bc6b06 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.native.js @@ -22,10 +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 Complex64 = require( '@stdlib/complex/float32/ctor' ); -var real = require( '@stdlib/complex/float32/real' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); var tryRequire = require( '@stdlib/utils/try-require' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -37,29 +38,31 @@ var croundf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( croundf 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( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), - new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) - ]; + zbuf = uniform( 200, -500.0, 500.0, options ); + z = new Complex64Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = croundf( values[ i%values.length ] ); - if ( isnanf( real( y ) ) ) { + y = croundf( z.get( i%100 ) ); + if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnanf( real( y ) ) ) { + if ( isnanf( imagf( y ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.strided.js b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/benchmark.strided.js new file mode 100644 index 000000000000..ff94b2fd0918 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/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, -500.0, 500.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/croundf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/c/benchmark.c index d401405f833c..a51b5db5276b 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/croundf/benchmark/c/benchmark.c @@ -20,9 +20,10 @@ #include #include #include +#include #include -#define NAME "roundf" +#define NAME "croundf" #define ITERATIONS 1000000 #define REPEATS 3 diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/croundf/docs/repl.txt index faad67c41597..3c84e5482682 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/croundf/docs/repl.txt @@ -18,6 +18,77 @@ > var v = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( 5.5, 3.3 ) ) [ 6.0, 3.0 ] + +{{alias}}.assign( re, im, out, strideOut, offsetOut ) + Rounds each component of a single-precision complex floating-point number + to the nearest integer 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( -1.5, 2.5, out, 1, 0 ) + [ -1.0, 3.0 ] + + +{{alias}}.strided( z, sz, oz, out, so, oo ) + Rounds each component of a single-precision complex floating-point number + stored in a real-valued strided array view to the nearest integer 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}}( [ -1.5, 2.5 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 2 ); + > {{alias}}.strided( z, 1, 0, out, 1, 0 ) + [ -1.0, 3.0 ] + See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/index.d.ts index 48bc61462435..51471a06bf9a 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/index.d.ts @@ -21,20 +21,101 @@ /// import { Complex64 } from '@stdlib/types/complex'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for rounding each component of a single-precision complex floating-point number to the nearest integer. +*/ +interface Croundf { + /** + * Rounds each component of a single-precision complex floating-point number to the nearest integer. + * + * @param z - complex number + * @returns result + * + * @example + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * + * var v = croundf( new Complex64( -1.5, 2.5 ) ); + * // returns [ -1.0, 3.0 ] + */ + ( z: Complex64 ): Complex64; + + /** + * Rounds each component of a single-precision complex floating-point number to the nearest integer 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 = croundf.assign( -1.5, 2.5, out, 1, 0 ); + * // returns [ -1.0, 3.0 ] + * + * var bool = ( out === v ); + * // returns true + */ + assign>( re: number, im: number, out: T, strideOut: number, offsetOut: number ): T; + + /** + * Rounds each component of a single-precision complex floating-point number stored in a real-valued strided array view to the nearest integer 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( [ -1.5, 2.5 ] ); + * + * var out = croundf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); + * // returns [ -1.0, 3.0 ] + */ + strided, U extends NumericArray | Collection>( z: T, strideZ: number, offsetZ: number, out: U, strideOut: number, offsetOut: number ): U; +} /** * Rounds each component of a single-precision complex floating-point number to the nearest integer. * -* @param z - input value +* @param z - complex number * @returns result * * @example * var Complex64 = require( '@stdlib/complex/float32/ctor' ); * -* var v = croundf( new Complex64( -4.2, 5.5 ) ); -* // returns [ -4.0, 6.0 ] +* var v = croundf( new Complex64( -1.5, 2.5 ) ); +* // returns [ -1.0, 3.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var out = new Float32Array( 2 ); +* var v = croundf.assign( -1.5, 2.5, out, 1, 0 ); +* // returns [ -1.0, 3.0 ] +* +* var bool = ( out === v ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var z = new Float32Array( [ -1.5, 2.5 ] ); +* +* var out = croundf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); +* // returns [ -1.0, 3.0 ] */ -declare function croundf( z: Complex64 ): Complex64; +declare var croundf: Croundf; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/test.ts index cabd568f7ff0..f35e60ab0e86 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/croundf/docs/types/test.ts @@ -22,13 +22,14 @@ import croundf = require( './index' ); // TESTS // -// The function returns a single-precision complex floating-point number... +// The function returns a complex number... { croundf( new Complex64( 1.0, 2.0 ) ); // $ExpectType Complex64 } // The compiler throws an error if the function is provided a value other than a complex number... { + croundf( 2 ); // $ExpectError croundf( true ); // $ExpectError croundf( false ); // $ExpectError croundf( null ); // $ExpectError @@ -43,3 +44,203 @@ import croundf = require( './index' ); { croundf(); // $ExpectError } + +// Attached to the main export is an `assign` method which returns a collection... +{ + croundf.assign( 1.0, 1.0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + croundf.assign( 1.0, 1.0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + croundf.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 ); + + croundf.assign( true, 2.0, out, 1, 0 ); // $ExpectError + croundf.assign( false, 2.0, out, 1, 0 ); // $ExpectError + croundf.assign( null, 2.0, out, 1, 0 ); // $ExpectError + croundf.assign( undefined, 2.0, out, 1, 0 ); // $ExpectError + croundf.assign( '5', 2.0, out, 1, 0 ); // $ExpectError + croundf.assign( [], 2.0, out, 1, 0 ); // $ExpectError + croundf.assign( {}, 2.0, out, 1, 0 ); // $ExpectError + croundf.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 ); + + croundf.assign( 1.0, true, out, 1, 0 ); // $ExpectError + croundf.assign( 1.0, false, out, 1, 0 ); // $ExpectError + croundf.assign( 1.0, null, out, 1, 0 ); // $ExpectError + croundf.assign( 1.0, undefined, out, 1, 0 ); // $ExpectError + croundf.assign( 1.0, '5', out, 1, 0 ); // $ExpectError + croundf.assign( 1.0, [], out, 1, 0 ); // $ExpectError + croundf.assign( 1.0, {}, out, 1, 0 ); // $ExpectError + croundf.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... +{ + croundf.assign( 1.0, 2.0, 1, 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, true, 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, false, 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, null, 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, undefined, 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, '5', 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, [ '5' ], 1, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, {}, 1, 0 ); // $ExpectError + croundf.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 ); + + croundf.assign( 1.0, 2.0, out, true, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out, false, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out, null, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out, undefined, 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out, '5', 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out, [], 0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out, {}, 0 ); // $ExpectError + croundf.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 ); + + croundf.assign( 1.0, 2.0, out, 1, true ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1, false ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1, null ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1, undefined ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1, '5' ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1, [] ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1, {} ); // $ExpectError + croundf.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 ); + + croundf.assign(); // $ExpectError + croundf.assign( 1.0 ); // $ExpectError + croundf.assign( 1.0, 2.0 ); // $ExpectError + croundf.assign( 1.0, 2.0, out ); // $ExpectError + croundf.assign( 1.0, 2.0, out, 1 ); // $ExpectError + croundf.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 ); + + croundf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + croundf.strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + croundf.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 ); + + croundf.strided( true, 1, 0, out, 1, 0 ); // $ExpectError + croundf.strided( false, 1, 0, out, 1, 0 ); // $ExpectError + croundf.strided( null, 1, 0, out, 1, 0 ); // $ExpectError + croundf.strided( undefined, 1, 0, out, 1, 0 ); // $ExpectError + croundf.strided( '5', 1, 0, out, 1, 0 ); // $ExpectError + croundf.strided( [ '5' ], 1, 0, out, 1, 0 ); // $ExpectError + croundf.strided( {}, 1, 0, out, 1, 0 ); // $ExpectError + croundf.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 ); + + croundf.strided( z, true, 0, out, 1, 0 ); // $ExpectError + croundf.strided( z, false, 0, out, 1, 0 ); // $ExpectError + croundf.strided( z, null, 0, out, 1, 0 ); // $ExpectError + croundf.strided( z, undefined, 0, out, 1, 0 ); // $ExpectError + croundf.strided( z, '5', 0, out, 1, 0 ); // $ExpectError + croundf.strided( z, [], 0, out, 1, 0 ); // $ExpectError + croundf.strided( z, {}, 0, out, 1, 0 ); // $ExpectError + croundf.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 ); + + croundf.strided( z, 1, true, out, 1, 0 ); // $ExpectError + croundf.strided( z, 1, false, out, 1, 0 ); // $ExpectError + croundf.strided( z, 1, null, out, 1, 0 ); // $ExpectError + croundf.strided( z, 1, undefined, out, 1, 0 ); // $ExpectError + croundf.strided( z, 1, '5', out, 1, 0 ); // $ExpectError + croundf.strided( z, 1, [], out, 1, 0 ); // $ExpectError + croundf.strided( z, 1, {}, out, 1, 0 ); // $ExpectError + croundf.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 ); + + croundf.strided( z, 1, 0, 1, 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, true, 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, false, 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, null, 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, undefined, 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, '5', 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, [ '5' ], 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, {}, 1, 0 ); // $ExpectError + croundf.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 ); + + croundf.strided( z, 1, 0, out, true, 0 ); // $ExpectError + croundf.strided( z, 1, 0, out, false, 0 ); // $ExpectError + croundf.strided( z, 1, 0, out, null, 0 ); // $ExpectError + croundf.strided( z, 1, 0, out, undefined, 0 ); // $ExpectError + croundf.strided( z, 1, 0, out, '5', 0 ); // $ExpectError + croundf.strided( z, 1, 0, out, [], 0 ); // $ExpectError + croundf.strided( z, 1, 0, out, {}, 0 ); // $ExpectError + croundf.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 ); + + croundf.strided( z, 1, 0, out, 1, true ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, false ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, null ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, undefined ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, '5' ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, [] ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, {} ); // $ExpectError + croundf.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 ); + + croundf.strided(); // $ExpectError + croundf.strided( z ); // $ExpectError + croundf.strided( z, 1 ); // $ExpectError + croundf.strided( z, 1, 0 ); // $ExpectError + croundf.strided( z, 1, 0, out ); // $ExpectError + croundf.strided( z, 1, 0, out, 1 ); // $ExpectError + croundf.strided( z, 1, 0, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/croundf/examples/index.js index 3341c9ceeb53..cabfb2b87f03 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/examples/index.js @@ -18,15 +18,13 @@ 'use strict'; -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var croundf = require( './../lib' ); -var rand = uniform( -50.0, 50.0 ); +// Create an array of random numbers: +var arr = new Complex64Array( uniform( 200, -50.0, 50.0 ) ); -var z; -var i; -for ( i = 0; i < 100; i++ ) { - z = new Complex64( rand(), rand() ); - console.log( 'croundf(%s) = %s', z, croundf( z ) ); -} +// Round each component of each complex number to the nearest integer: +logEachMap( 'croundf(%s) = %s', arr, croundf ); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/croundf/lib/assign.js new file mode 100644 index 000000000000..8f1d407dae84 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/lib/assign.js @@ -0,0 +1,53 @@ +/** +* @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 roundf = require( '@stdlib/math/base/special/roundf' ); + + +// MAIN // + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest integer 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( -1.5, 2.5, new Float32Array( 2 ), 1, 0 ); +* // returns [ -1.0, 3.0 ] +*/ +function assign( re, im, out, strideOut, offsetOut ) { + out[ offsetOut ] = roundf( re ); + out[ offsetOut+strideOut ] = roundf( im ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/croundf/lib/index.js index 41e2d0d54245..c159082fa46b 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/lib/index.js @@ -42,9 +42,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/croundf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/croundf/lib/main.js index 6d9c282c57a9..46fb910afcf4 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/lib/main.js @@ -21,9 +21,15 @@ // MODULES // var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var roundf = require( '@stdlib/math/base/special/roundf' ); -var real = require( '@stdlib/complex/float32/real' ); -var imag = require( '@stdlib/complex/float32/imag' ); +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 out = new Float32Array( 2 ); // MAIN // @@ -50,7 +56,8 @@ var imag = require( '@stdlib/complex/float32/imag' ); * // returns [ NaN, NaN ] */ function croundf( z ) { - return new Complex64( roundf( real( z ) ), roundf( imag( z ) ) ); + 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/croundf/lib/strided.js b/lib/node_modules/@stdlib/math/base/special/croundf/lib/strided.js new file mode 100644 index 000000000000..205653f92f26 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/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 // + +/** +* Rounds each component of a single-precision complex floating-point number stored in a real-valued strided array view to the nearest integer 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( [ -1.5, 2.5 ] ); +* +* var out = strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); +* // returns [ -1.0, 3.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/croundf/manifest.json b/lib/node_modules/@stdlib/math/base/special/croundf/manifest.json index eb00756ce384..56278b3ec8cf 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/croundf/manifest.json @@ -37,9 +37,9 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/unary", - "@stdlib/math/base/special/roundf", "@stdlib/complex/float32/ctor", - "@stdlib/complex/float32/reim" + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/roundf" ] }, { @@ -53,9 +53,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/special/roundf", "@stdlib/complex/float32/ctor", - "@stdlib/complex/float32/reim" + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/roundf" ] }, { @@ -69,9 +69,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/special/roundf", "@stdlib/complex/float32/ctor", - "@stdlib/complex/float32/reim" + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/roundf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.assign.js new file mode 100644 index 000000000000..7505a1840ac7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.assign.js @@ -0,0 +1,167 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var croundf = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof croundf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function rounds each component of a single-precision complex floating-point number to the nearest integer', function test( t ) { + var expected; + var out; + var v; + + out = new Float32Array( 2 ); + v = croundf( -1.5, 2.5, out, 1, 0 ); + + expected = new Float32Array( [ -1.0, 3.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = croundf( -1.5, 2.5, out, 2, 0 ); + + expected = new Float32Array( [ -1.0, 0.0, 3.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = croundf( -1.5, 2.5, out, 2, 1 ); + + expected = new Float32Array( [ 0.0, -1.0, 0.0, 3.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = croundf( -1.5, 2.5, out, -2, 3 ); + + expected = new Float32Array( [ 0.0, 3.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 rounds real and imaginary components to the nearest integer', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + croundf( -4.2, 5.5, out, 1, 0 ); + + expected = new Float32Array( [ -4.0, 6.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + croundf( 9.99999, 0.1, out, 1, 0 ); + + expected = new Float32Array( [ 10.0, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + croundf( 0.0, 0.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 returns a `NaN` if provided a `NaN`', function test( t ) { + var out = new Float32Array( 2 ); + + croundf( 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( 'the function returns `-0` if provided `-0`', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + croundf( -0.0, -0.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 returns `+0` if provided `+0`', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + croundf( +0.0, +0.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 returns `+infinity` if provided `+infinity`', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + croundf( PINF, PINF, out, 1, 0 ); + + expected = new Float32Array( [ PINF, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + croundf( NINF, NINF, out, 1, 0 ); + + expected = new Float32Array( [ NINF, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.js b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.js index 3a93fbc46835..efb6fc0863fd 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.js @@ -21,14 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var PINF = require( '@stdlib/constants/float32/pinf' ); -var NINF = require( '@stdlib/constants/float32/ninf' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var real = require( '@stdlib/complex/float32/real' ); -var imag = require( '@stdlib/complex/float32/imag' ); +var isMethod = require( '@stdlib/assert/is-method' ); var croundf = require( './../lib' ); @@ -40,65 +33,12 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function rounds real and imaginary components to the nearest integer', function test( t ) { - var v; - - v = croundf( new Complex64( -4.2, 5.5 ) ); - t.strictEqual( real( v ), -4.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - - v = croundf( new Complex64( 9.99999, 0.1 ) ); - t.strictEqual( real( v ), 10.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - - v = croundf( new Complex64( 0.0, 0.0 ) ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( croundf, 'assign' ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns a `NaN` if provided a `NaN`', function test( t ) { - var v; - - v = croundf( new Complex64( NaN, NaN ) ); - t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `-0` if provided `-0`', function test( t ) { - var v; - - v = croundf( new Complex64( -0.0, -0.0 ) ); - t.strictEqual( isNegativeZero( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `+0` if provided `+0`', function test( t ) { - var v; - - v = croundf( new Complex64( +0.0, +0.0 ) ); - t.strictEqual( isPositiveZero( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { - var v; - - v = croundf( new Complex64( PINF, PINF ) ); - t.strictEqual( real( v ), PINF, 'returns expected value' ); - t.strictEqual( imag( v ), PINF, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { - var v; - - v = croundf( new Complex64( NINF, NINF ) ); - t.strictEqual( real( v ), NINF, 'returns expected value' ); - t.strictEqual( imag( v ), NINF, 'returns expected value' ); +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.strictEqual( isMethod( croundf, 'strided' ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.main.js new file mode 100644 index 000000000000..98c2b7d8d538 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.main.js @@ -0,0 +1,104 @@ +/** +* @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 PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var croundf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof croundf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function rounds real and imaginary components to the nearest integer', function test( t ) { + var v; + + v = croundf( new Complex64( -4.2, 5.5 ) ); + t.strictEqual( realf( v ), -4.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); + + v = croundf( new Complex64( 9.99999, 0.1 ) ); + t.strictEqual( realf( v ), 10.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + v = croundf( new Complex64( 0.0, 0.0 ) ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', function test( t ) { + var v; + + v = croundf( 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( 'the function returns `-0` if provided `-0`', function test( t ) { + var v; + + v = croundf( new Complex64( -0.0, -0.0 ) ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', function test( t ) { + var v; + + v = croundf( new Complex64( +0.0, +0.0 ) ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { + var v; + + v = croundf( new Complex64( PINF, PINF ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var v; + + v = croundf( new Complex64( NINF, NINF ) ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.native.js index e6a805414860..56a733e89087 100644 --- a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.native.js @@ -25,8 +25,8 @@ var tape = require( 'tape' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var real = require( '@stdlib/complex/float32/real' ); var imag = require( '@stdlib/complex/float32/imag' ); @@ -80,8 +80,8 @@ tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { var v; v = croundf( new Complex64( -0.0, -0.0 ) ); - t.strictEqual( isNegativeZero( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isNegativeZero( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); t.end(); }); @@ -89,8 +89,8 @@ tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { var v; v = croundf( new Complex64( +0.0, +0.0 ) ); - t.strictEqual( isPositiveZero( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZero( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/croundf/test/test.strided.js b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.strided.js new file mode 100644 index 000000000000..ef1e6d0a99c9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundf/test/test.strided.js @@ -0,0 +1,185 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var croundf = require( './../lib/strided.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof croundf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function rounds each component of a single-precision complex floating-point number to the nearest integer', function test( t ) { + var expected; + var out; + var z; + var v; + + z = new Float32Array( [ -1.5, 2.5 ] ); + out = new Float32Array( 2 ); + v = croundf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ -1.0, 3.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ -1.5, 0.0, 2.5, 0.0 ] ); + out = new Float32Array( 4 ); + v = croundf( z, 2, 0, out, 2, 0 ); + + expected = new Float32Array( [ -1.0, 0.0, 3.0, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, -1.5, 0.0, 2.5 ] ); + out = new Float32Array( 4 ); + v = croundf( z, 2, 1, out, 2, 1 ); + + expected = new Float32Array( [ 0.0, -1.0, 0.0, 3.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 2.5, -1.5 ] ); + out = new Float32Array( 4 ); + v = croundf( z, -1, 1, out, -2, 3 ); + + expected = new Float32Array( [ 0.0, 3.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 rounds real and imaginary components to the nearest integer', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ -4.2, 5.5 ] ); + out = new Float32Array( 2 ); + croundf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ -4.0, 6.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 9.99999, 0.1 ] ); + out = new Float32Array( 2 ); + croundf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 10.0, 0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 0.0 ] ); + out = new Float32Array( 2 ); + croundf( 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 returns a `NaN` if provided a `NaN`', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ NaN, NaN ] ); + + croundf( 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( 'the function returns `-0` if provided `-0`', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ -0.0, -0.0 ] ); + out = new Float32Array( 2 ); + croundf( 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 returns `+0` if provided `+0`', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ +0.0, +0.0 ] ); + out = new Float32Array( 2 ); + croundf( 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 returns `+infinity` if provided `+infinity`', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ PINF, PINF ] ); + out = new Float32Array( 2 ); + croundf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ NINF, NINF ] ); + out = new Float32Array( 2 ); + croundf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ NINF, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + t.end(); +});