diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/README.md b/lib/node_modules/@stdlib/math/base/special/croundnf/README.md new file mode 100644 index 000000000000..195ae9e914f7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/README.md @@ -0,0 +1,241 @@ + + +# croundnf + +> Round each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. + +
+ +## Usage + +```javascript +var croundnf = require( '@stdlib/math/base/special/croundnf' ); +``` + +#### croundnf( z, n ) + +Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); + +var v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); +// returns [ ~-3.14, ~3.14 ] + +v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), 0 ); +// returns [ -3.0, 3.0 ] + +v = croundnf( new Complex64( -12368.0, 12368.0 ), 3 ); +// returns [ ~-12000.0, ~12000.0 ] + +v = croundnf( new Complex64( NaN, NaN ), 3 ); +// returns [ NaN, NaN ] +``` + +
+ + + +
+ +## Notes + +- When operating on [floating-point numbers][ieee754] in bases other than `2`, rounding to specified digits can be **inexact**. For example, + + ```javascript + var Complex64 = require( '@stdlib/complex/float32/ctor' ); + + var x = 0.2 + 0.1; + // returns 0.30000000000000004 + + // Should round components to 0.3: + var v = croundnf( new Complex64( x, x ), -7 ); + // returns [ 0.30000001192092896, 0.30000001192092896 ] + ``` + +- Ties are rounded toward positive infinity. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var croundnf = require( '@stdlib/math/base/special/croundnf' ); + +var rand1 = uniform( -5.0, 0.0 ); +var rand2 = uniform( -50.0, 50.0 ); + +var z; +var i; +var n; +for ( i = 0; i < 100; i++ ) { + z = new Complex64( rand2(), rand2() ); + n = floor( rand1() ); + console.log( 'croundnf(%s, %s) = %s', z, n, croundnf( z, n ) ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/croundnf.h" +``` + +#### stdlib_base_croundnf( z, n ) + +Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. + +```c +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/real.h" +#include "stdlib/complex/float32/imag.h" + +stdlib_complex64_t z = stdlib_complex64( -3.141592653589793f, 3.141592653589793f ); + +stdlib_complex64_t out = stdlib_base_croundnf( z, -2 ); + +float re = stdlib_complex64_real( out ); +// returns ~-3.14f + +float im = stdlib_complex64_imag( out ); +// returns ~3.14f +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex64_t` input value. +- **n**: `[in] int32_t` integer power of 10. + +```c +stdlib_complex64_t stdlib_base_croundnf( const stdlib_complex64_t z, const int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/croundnf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +int main( void ) { + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.5f ), + stdlib_complex64( -3.14f, -1.5f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + stdlib_complex64_t y; + float re1; + float im1; + float re2; + float im2; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + y = stdlib_base_croundnf( v, -2 ); + stdlib_complex64_reim( v, &re1, &im1 ); + stdlib_complex64_reim( y, &re2, &im2 ); + printf( "croundnf(%f + %fi, -2) = %f + %fi\n", re1, im1, re2, im2 ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/benchmark.js new file mode 100644 index 000000000000..64cfe889af55 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var croundnf = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xre; + var xim; + var n; + + xre = uniform( len, -500.0, 500.0, { + 'dtype': 'float32' + }); + xim = uniform( len, -500.0, 500.0, { + 'dtype': 'float32' + }); + n = filledarrayBy( len, 'generic', discreteUniform ); + + return benchmark; + + /** + * Returns a pseudorandom integer. + * + * @private + * @returns {integer} pseudorandom integer + */ + function discreteUniform() { + return floor( ( randu()*10.0 ) - 5.0 ); + } + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = croundnf( + new Complex64( xre[ i%len ], xim[ i%len ] ), n[ i%len ] + ); + if ( isnanf( realf( y ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( realf( y ) ) || isnanf( imagf( y ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +bench( pkg, createBenchmark( 10 ) ); + +bench( format( '%s::len=%d', pkg, 100 ), createBenchmark( 100 ) ); diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..d4c438d8e13f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/benchmark.native.js @@ -0,0 +1,111 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +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; + + +// VARIABLES // + +var croundnf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( croundnf instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xre; + var xim; + var n; + + xre = uniform( len, -500.0, 500.0, { + 'dtype': 'float32' + }); + xim = uniform( len, -500.0, 500.0, { + 'dtype': 'float32' + }); + n = filledarrayBy( len, 'generic', discreteUniform ); + + return benchmark; + + /** + * Returns a pseudorandom integer. + * + * @private + * @returns {integer} pseudorandom integer + */ + function discreteUniform() { + return floor( ( randu()*10.0 ) - 5.0 ); + } + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = croundnf( new Complex64( xre[ i%len ], xim[ i%len ] ), n[ i%len ] ); + if ( isnanf( realf( y ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( realf( y ) ) || isnanf( imagf( y ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, createBenchmark( 10 ) ); + +bench( format( '%s::native:len=%d', pkg, 100 ), opts, createBenchmark( 100 ) ); diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..bb8f7887af9d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/c/native/Makefile @@ -0,0 +1,162 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: benchmark + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {string} fPIC - compiler flag indicating whether to generate position independent code +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make benchmark +#/ +benchmark: $(c_targets) + +.PHONY: benchmark + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: benchmark + $(QUIET) ./$(c_targets) + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..d5353b7fe6fa --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/benchmark/c/native/benchmark.c @@ -0,0 +1,158 @@ +/** +* @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. +*/ + +#include "stdlib/math/base/special/croundnf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/real.h" +#include "stdlib/complex/float32/imag.h" +#include +#include +#include +#include +#include + +#define NAME "croundnf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); +} + +/** +* Generates a random integer on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random integer +*/ +static int32_t random_int( const int32_t min, const int32_t max ) { + int v = rand(); + return min + ( v % (max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + stdlib_complex64_t z[ 100 ]; + int32_t n[ 100 ]; + double elapsed; + double t; + float re; + float im; + int i; + + for ( i = 0; i < 100; i++ ) { + re = random_uniform( -500.0f, 500.0f ); + im = random_uniform( -500.0f, 500.0f ); + z[ i ] = stdlib_complex64( re, im ); + n[ i ] = random_int( -5, 5 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + z[ 0 ] = stdlib_base_croundnf( z[ i%100 ], n[ i%100 ] ); + if ( stdlib_complex64_real( z[ 0 ] ) != stdlib_complex64_real( z[ 0 ] ) ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( stdlib_complex64_real( z[ 0 ] ) != stdlib_complex64_real( z[ 0 ] ) || stdlib_complex64_imag( z[ 0 ] ) != stdlib_complex64_imag( z[ 0 ] ) ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/croundnf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/binding.gyp @@ -0,0 +1,170 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/croundnf/docs/repl.txt new file mode 100644 index 000000000000..df32810f8573 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/docs/repl.txt @@ -0,0 +1,65 @@ + +{{alias}}( z, n ) + Rounds each component of a single-precision complex floating-point number + to the nearest multiple of `10^n`. + + When operating on floating-point numbers in bases other than `2`, rounding + to specified digits can be inexact. + + Parameters + ---------- + z: Complex64 + Complex number. + + n: integer + Integer power of 10. + + Returns + ------- + out: Complex64 + Result. + + Examples + -------- + > var z = new {{alias:@stdlib/complex/float32/ctor}}( 5.555, -3.333 ); + > var v = {{alias}}( z, -2 ) + + > var re = {{alias:@stdlib/complex/float32/real}}( v ) + 5.559999942779541 + > var im = {{alias:@stdlib/complex/float32/imag}}( v ) + -3.3299999237060547 + + > z = new {{alias:@stdlib/complex/float32/ctor}}( -3.14, 3.14 ); + > v = {{alias}}( z, -2 ) + + > re = {{alias:@stdlib/complex/float32/real}}( v ) + -3.140000104904175 + > im = {{alias:@stdlib/complex/float32/imag}}( v ) + 3.140000104904175 + + > z = new {{alias:@stdlib/complex/float32/ctor}}( -3.14, 3.14 ); + > v = {{alias}}( z, 0 ) + + > re = {{alias:@stdlib/complex/float32/real}}( v ) + -3.0 + > im = {{alias:@stdlib/complex/float32/imag}}( v ) + 3.0 + + > z = new {{alias:@stdlib/complex/float32/ctor}}( 12368.0, -12368.0 ); + > v = {{alias}}( z, 3 ) + + > re = {{alias:@stdlib/complex/float32/real}}( v ) + 11999.9990234375 + > im = {{alias:@stdlib/complex/float32/imag}}( v ) + -11999.9990234375 + + > v = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( NaN, NaN ), 0 ) + + > re = {{alias:@stdlib/complex/float32/real}}( v ) + NaN + > im = {{alias:@stdlib/complex/float32/imag}}( v ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/croundnf/docs/types/index.d.ts new file mode 100644 index 000000000000..c39a1e721bdb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/docs/types/index.d.ts @@ -0,0 +1,97 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. +* +* ## Notes +* +* - When operating on floating-point numbers in bases other than `2`, rounding to specified digits can be inexact. +* +* @param z - input value +* @param n - integer power of 10 +* @returns result +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var v = croundnf( new Complex64( 5.555, -3.333 ), -2 ); +* // returns +* +* var re = realf( v ); +* // returns ~5.56 +* +* var im = imagf( v ); +* // returns ~-3.33 +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); +* // returns +* +* var re = realf( v ); +* // returns ~-3.14 +* +* var im = imagf( v ); +* // returns ~3.14 +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), 0 ); +* // returns +* +* var re = realf( v ); +* // returns -3.0 +* +* var im = imagf( v ); +* // returns 3.0 +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var v = croundnf( new Complex64( 12368.0, -12368.0 ), 3 ); +* // returns +* +* var re = realf( v ); +* // returns 11999.9990234375 +* +* var im = imagf( v ); +* // returns -11999.9990234375 +*/ +declare function croundnf( z: Complex64, n: number ): Complex64; + + +// EXPORTS // + +export = croundnf; diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/croundnf/docs/types/test.ts new file mode 100644 index 000000000000..32e6edb887ee --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/docs/types/test.ts @@ -0,0 +1,59 @@ +/* +* @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. +*/ + +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import croundnf = require( './index' ); + + +// TESTS // + +// The function returns a Complex64 number... +{ + croundnf( new Complex64( 5.0, 3.0 ), -2 ); // $ExpectType Complex64 +} + +// The compiler throws an error if the function is provided a first argument that is not a Complex64 number... +{ + croundnf( true, -2 ); // $ExpectError + croundnf( false, -2 ); // $ExpectError + croundnf( null, -2 ); // $ExpectError + croundnf( undefined, -2 ); // $ExpectError + croundnf( '5', -2 ); // $ExpectError + croundnf( [], -2 ); // $ExpectError + croundnf( {}, -2 ); // $ExpectError + croundnf( ( x: number ): number => x, -2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + const z = new Complex64( 5.0, 3.0 ); + croundnf( z, true ); // $ExpectError + croundnf( z, false ); // $ExpectError + croundnf( z, null ); // $ExpectError + croundnf( z, undefined ); // $ExpectError + croundnf( z, '5' ); // $ExpectError + croundnf( z, [] ); // $ExpectError + croundnf( z, {} ); // $ExpectError + croundnf( z, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an insufficient number of arguments... +{ + croundnf(); // $ExpectError + croundnf( new Complex64( 5.0, 3.0 ) ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/croundnf/examples/c/Makefile new file mode 100644 index 000000000000..bc24ca300633 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/examples/c/Makefile @@ -0,0 +1,145 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := MINGW +else +ifneq (, $(findstring MSYS,$(OS))) + OS := MSYS +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := CYGWIN +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {string} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/croundnf/examples/c/example.c new file mode 100644 index 000000000000..8c11ce2f9de4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/examples/c/example.c @@ -0,0 +1,46 @@ +/** +* @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. +*/ + +#include "stdlib/math/base/special/croundnf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +int main( void ) { + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.5f ), + stdlib_complex64( -3.14f, -1.5f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + stdlib_complex64_t y; + float re1; + float im1; + float re2; + float im2; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + y = stdlib_base_croundnf( v, -2 ); + stdlib_complex64_reim( v, &re1, &im1 ); + stdlib_complex64_reim( y, &re2, &im2 ); + printf( "croundnf(%f + %fi, -2) = %f + %fi\n", re1, im1, re2, im2 ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/croundnf/examples/index.js new file mode 100644 index 000000000000..1f8f3a05f050 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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'; + +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var croundnf = require( './../lib' ); + +var rand1 = uniform( -5.0, 0.0 ); +var rand2 = uniform( -50.0, 50.0 ); + +var z; +var i; +var n; +for ( i = 0; i < 100; i++ ) { + z = new Complex64( rand2(), rand2() ); + n = floor( rand1() ); + console.log( 'croundnf(%s, %s) = %s', z, n, croundnf( z, n ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/include.gypi b/lib/node_modules/@stdlib/math/base/special/croundnf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/include.gypi @@ -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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. +*/ +stdlib_complex64_t stdlib_base_croundnf( const stdlib_complex64_t z, const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_CROUNDNF_H diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/croundnf/lib/index.js new file mode 100644 index 000000000000..f2832271c923 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/lib/index.js @@ -0,0 +1,70 @@ +/** +* @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'; + +/** +* Round each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. +* +* @module @stdlib/math/base/special/croundnf +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* var croundnf = require( '@stdlib/math/base/special/croundnf' ); +* +* // Round a value to 2 decimal places: +* var v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); +* // returns +* +* var re = realf( v ); +* // returns ~-3.14 +* +* var im = imagf( v ); +* // returns ~3.14 +* +* // If n = 0, `croundnf` behaves like `croundf`: +* v = croundnf( new Complex64( 9.99999, 0.1 ), 0 ); +* // returns +* +* re = realf( v ); +* // returns 10.0 +* +* im = imagf( v ); +* // returns 0.0 +* +* // Round components to the nearest thousand: +* v = croundnf( new Complex64( 12368.0, -12368.0 ), 3 ); +* // returns +* +* re = realf( v ); +* // returns ~12000.0 +* +* im = imagf( v ); +* // returns ~-12000.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/croundnf/lib/main.js new file mode 100644 index 000000000000..a01d06094be1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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 Complex64 = require( '@stdlib/complex/float32/ctor' ); +var roundnf = require( '@stdlib/math/base/special/roundnf' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); + + +// MAIN // + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. +* +* @param {Complex64} z - complex number +* @param {integer} n - integer power of 10 +* @returns {Complex64} result +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); +* // returns [ ~-3.14, ~3.14 ] +* +* // If n = 0, `croundnf` behaves like `croundf`: +* v = croundnf( new Complex64( 9.99999, 0.1 ), 0 ); +* // returns [ 10.0, 0.0 ] +* +* // Round components to the nearest thousand: +* v = croundnf( new Complex64( 12368.0, -12368.0 ), 3 ); +* // returns [ ~12000.0, ~-12000.0 ] +* +* v = croundnf( new Complex64( NaN, NaN ), 2 ); +* // returns [ NaN, NaN ] +*/ +function croundnf( z, n ) { + return new Complex64( roundnf( real( z ), n ), roundnf( imag( z ), n ) ); +} + + +// EXPORTS // + +module.exports = croundnf; diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/croundnf/lib/native.js new file mode 100644 index 000000000000..7970fd2a666f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/lib/native.js @@ -0,0 +1,56 @@ +/** +* @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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of \\(10^n\\). +* +* @private +* @param {Complex64} z - input value +* @param {integer} n - integer power of 10 +* @returns {Complex64} rounded value +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var v = croundnf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); +* +* var re = realf( v ); +* // returns ~-3.14 +* +* var im = imagf( v ); +* // returns ~3.14 +*/ +function croundnf( z, n ) { + return addon( z, n ); +} + + +// EXPORTS // + +module.exports = croundnf; diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/manifest.json b/lib/node_modules/@stdlib/math/base/special/croundnf/manifest.json new file mode 100644 index 000000000000..12af45aa682d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/manifest.json @@ -0,0 +1,87 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/special/roundnf", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/real", + "@stdlib/complex/float32/imag" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/roundnf", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", + "@stdlib/complex/float32/real", + "@stdlib/complex/float32/imag" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/roundnf", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/package.json b/lib/node_modules/@stdlib/math/base/special/croundnf/package.json new file mode 100644 index 000000000000..2bc59a326afc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/math/base/special/croundnf", + "version": "0.0.0", + "description": "Round each component of a single-precision complex floating-point number to the nearest multiple of 10^n.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "math.round", + "round", + "roundnf", + "croundnf", + "integer", + "nearest", + "value", + "fix", + "tofixed", + "complex", + "cmplx", + "number", + "float32", + "single", + "precision" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/croundnf/src/Makefile new file mode 100644 index 000000000000..726af722c372 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/src/Makefile @@ -0,0 +1,145 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := MINGW +else +ifneq (, $(findstring MSYS,$(OS))) + OS := MSYS +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := CYGWIN +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {string} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/croundnf/src/addon.c new file mode 100644 index 000000000000..1634debc7d10 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @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. +*/ + +#include "stdlib/math/base/special/croundnf.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_CI_C( stdlib_base_croundnf ) diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/src/main.c b/lib/node_modules/@stdlib/math/base/special/croundnf/src/main.c new file mode 100644 index 000000000000..d6ce3ff82793 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/src/main.c @@ -0,0 +1,55 @@ +/** +* @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. +*/ + +#include "stdlib/math/base/special/croundnf.h" +#include "stdlib/math/base/special/roundnf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n`. +* +* @param z input value +* @param n integer power of 10 +* @return result +* +* @example +* #include "stdlib/complex/float32/ctor.h" +* #include "stdlib/complex/float32/real.h" +* #include "stdlib/complex/float32/imag.h" +* +* stdlib_complex64_t z = stdlib_complex64( -3.141592653589793f, 3.141592653589793f ); +* +* stdlib_complex64_t out = stdlib_base_croundnf( z, -2 ); +* +* float re = stdlib_complex64_real( out ); +* // returns ~-3.14f +* +* float im = stdlib_complex64_imag( out ); +* // returns ~3.14f +*/ +stdlib_complex64_t stdlib_base_croundnf( const stdlib_complex64_t z, const int32_t n ) { + float re; + float im; + + stdlib_complex64_reim( z, &re, &im ); + + re = stdlib_base_roundnf( re, n ); + im = stdlib_base_roundnf( im, n ); + return stdlib_complex64( re, im ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/test/test.js b/lib/node_modules/@stdlib/math/base/special/croundnf/test/test.js new file mode 100644 index 000000000000..77952410e644 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/test/test.js @@ -0,0 +1,321 @@ +/** +* @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 PI = require( '@stdlib/constants/float32/pi' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var powf = require( '@stdlib/math/base/special/powf' ); +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 float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var croundnf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof croundnf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', function test( t ) { + var v; + + v = croundnf( new Complex64( NaN, NaN ), 0 ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( NaN, 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 `NaNs` if provided `n = +-infinity`', function test( t ) { + var v; + + v = croundnf( new Complex64( 3.14, 3.14 ), PINF ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( 3.14, 3.14 ), NINF ); + 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 = croundnf( new Complex64( -0.0, -0.0 ), 0 ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( -0.0, -0.0 ), -2 ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( -0.0, -0.0 ), 2 ); + 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 = croundnf( new Complex64( +0.0, +0.0 ), 0 ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( +0.0, +0.0 ), -2 ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( +0.0, +0.0 ), 2 ); + 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 = croundnf( new Complex64( PINF, PINF ), 5 ); + 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 = croundnf( new Complex64( NINF, NINF ), -3 ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding real and imaginary components to a desired number of decimals', function test( t ) { + var v; + + v = croundnf( new Complex64( -PI, PI ), -2 ); + t.strictEqual( realf( v ), -3.140000104904175, 'returns expected value' ); + t.strictEqual( imagf( v ), 3.140000104904175, 'returns expected value' ); + + v = croundnf( new Complex64( PI, -PI ), -2 ); + t.strictEqual( realf( v ), 3.140000104904175, 'returns expected value' ); + t.strictEqual( imagf( v ), -3.140000104904175, 'returns expected value' ); + + v = croundnf( new Complex64( 9.99999, 9.9999 ), -2 ); + t.strictEqual( realf( v ), 10.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 10.0, 'returns expected value' ); + + v = croundnf( new Complex64( -9.99999, -9.9999 ), -2 ); + t.strictEqual( realf( v ), -10.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -10.0, 'returns expected value' ); + + v = croundnf( new Complex64( 0.0, 0.0 ), 2 ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + v = croundnf( new Complex64( 12368.0, -12368.0 ), -3 ); + t.strictEqual( realf( v ), 12368.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -12368.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'rounding components to a desired number of decimals can result in unexpected behavior', function test( t ) { + var x; + var v; + + x = 0.2 + 0.1; // => 0.30000000000000004 + + v = croundnf( new Complex64( x, x ), -7 ); + t.strictEqual( realf( v ), 0.30000001192092896, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.30000001192092896, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding components to a desired number of digits', function test( t ) { + var v; + + v = croundnf( new Complex64( -PI, PI ), 4 ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + v = croundnf( new Complex64( -12368.0, 12368.0 ), 3 ); + t.strictEqual( realf( v ), float64ToFloat32( -11999.9990234375 ), 'returns expected value' ); + t.strictEqual( imagf( v ), float64ToFloat32( 11999.9990234375 ), 'returns expected value' ); + + v = croundnf( new Complex64( 12363.0, -12363.0 ), 1 ); + t.strictEqual( realf( v ), 12360.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -12360.0, 'returns expected value' ); + + v = croundnf( new Complex64( PI, -PI ), 3 ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the components unchanged if provided an `n` which is less than the minimum decimal exponential (-45 for float32)', function test( t ) { + var exp; + var n; + var x; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*76.0 ) - 38; + x = float64ToFloat32( (1.0+randu()) * powf( 10.0, exp ) ); + n = -(round( randu()*100.0 ) + 46); + v = croundnf( new Complex64( x, x ), n ); + t.strictEqual( realf( v ), x, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + t.strictEqual( imagf( v ), x, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + } + t.end(); +}); + +tape( 'if a component is too large a float32 to have decimals and `n < 0`, the component is returned unchanged', function test( t ) { + var sign; + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + sign = ( randu()<0.5 ) ? -1.0 : 1.0; + exp = 8 + round( randu()*30.0 ); // float32 can represent integers up to ~10^38 + x = float64ToFloat32( sign * (1.0+randu()) * powf( 10.0, exp ) ); + n = -(round( randu()*38.0) ); + v = croundnf( new Complex64( x, x ), n ); + t.strictEqual( realf( v ), x, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + t.strictEqual( imagf( v ), x, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + } + t.end(); +}); + +tape( 'if `n > 38` (exceeds float32 max exponent), the function returns `+-0` (sign preserving)', function test( t ) { + var sign; + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + sign = ( randu()<0.5 ) ? -1.0 : 1.0; + exp = round( randu()*37.0 ); + x = float64ToFloat32( sign * (1.0+randu()) * powf( 10.0, exp ) ); + n = round( randu()*100.0 ) + 39; + v = croundnf( new Complex64( x, x ), n ); + if ( sign === -1.0 ) { + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + } else { + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value when provided re='+x+', im='+x+', n='+n+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports rounding very small numbers (including subnormals)', function test( t ) { + var expected; + var delta; + var tol; + var x; + var n; + var v; + var i; + + x = 3.1468234343023397e-38; + + n = []; + for ( i = -38; i > -45; i-- ) { + n.push( i ); + } + expected = [ + 3e-38, + 3.1e-38, + 3.15e-38, + 3.147e-38, + 3.1468e-38, + 3.14682e-38, + 3.146823e-38 + ]; + + for ( i = 0; i < n.length; i++ ) { + v = croundnf( new Complex64( x, x ), n[ i ] ); + if ( realf( v ) === expected[i] ) { + t.strictEqual( realf( v ), expected[i], 'returns '+expected[i]+' when provided re='+x+', im='+x+', and n='+n[i]+'.' ); + t.strictEqual( imagf( v ), expected[i], 'returns '+expected[i]+' when provided re='+x+', im='+x+', and n='+n[i]+'.' ); + } else { + delta = ulpdiff( realf( v ), expected[i] ); + tol = 2.0; // Allow 2 ULP difference for float32 + t.strictEqual( delta <= tol, true, 're: '+x+'. n: '+n[i]+'. v: '+realf( v )+'. expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol ); + + delta = ulpdiff( imagf( v ), expected[i] ); + tol = 2.0; + t.strictEqual( delta <= tol, true, 'im: '+x+'. n: '+n[i]+'. v: '+imagf( v )+'. expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol ); + } + } + t.end(); +}); + +tape( 'if the function encounters overflow, the function returns the input component', function test( t ) { + var x; + var v; + + x = float64ToFloat32( 3.14682343 ); + v = croundnf( new Complex64( x, x ), -40 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = float64ToFloat32( -3.14682343 ); + v = croundnf( new Complex64( x, x ), -40 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = float64ToFloat32( 16777216 ); + v = croundnf( new Complex64( x, x ), -39 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = float64ToFloat32( -16777216 ); + v = croundnf( new Complex64( x, x ), -39 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/croundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/croundnf/test/test.native.js new file mode 100644 index 000000000000..86589462f11d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/croundnf/test/test.native.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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PI = require( '@stdlib/constants/float32/pi' ); +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 ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var croundnf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( croundnf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof croundnf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( NaN, NaN ), 0 ); + 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`', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( -0.0, -0.0 ), 0 ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( -0.0, -0.0 ), -2 ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( -0.0, -0.0 ), 2 ); + 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`', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( +0.0, +0.0 ), 0 ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( +0.0, +0.0 ), -2 ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + + v = croundnf( new Complex64( +0.0, +0.0 ), 2 ); + 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`', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( PINF, PINF ), 5 ); + 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`', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( NINF, NINF ), -3 ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding real and imaginary components to a desired number of decimals', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( -PI, PI ), -2 ); + t.strictEqual( realf( v ), -3.140000104904175, 'returns expected value' ); + t.strictEqual( imagf( v ), 3.140000104904175, 'returns expected value' ); + + v = croundnf( new Complex64( PI, -PI ), -2 ); + t.strictEqual( realf( v ), 3.140000104904175, 'returns expected value' ); + t.strictEqual( imagf( v ), -3.140000104904175, 'returns expected value' ); + + v = croundnf( new Complex64( 9.99999, 9.9999 ), -2 ); + t.strictEqual( realf( v ), 10.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 10.0, 'returns expected value' ); + + v = croundnf( new Complex64( -9.99999, -9.9999 ), -2 ); + t.strictEqual( realf( v ), -10.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -10.0, 'returns expected value' ); + + v = croundnf( new Complex64( 0.0, 0.0 ), 2 ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + v = croundnf( new Complex64( 12368.0, -12368.0 ), -3 ); + t.strictEqual( realf( v ), 12368.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -12368.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports rounding components to a desired number of digits', opts, function test( t ) { + var v; + + v = croundnf( new Complex64( -PI, PI ), 4 ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + v = croundnf( new Complex64( -12368.0, 12368.0 ), 3 ); + t.ok( ulpdiff( realf( v ), -12000.0 ) <= 2, 'returns expected value' ); + t.ok( ulpdiff( imagf( v ), 12000.0 ) <= 2, 'returns expected value' ); + + v = croundnf( new Complex64( 12363.0, -12363.0 ), 1 ); + t.ok( ulpdiff( realf( v ), 12360.0 ) <= 2, 'returns expected value' ); + t.ok( ulpdiff( imagf( v ), -12360.0 ) <= 2, 'returns expected value' ); + + v = croundnf( new Complex64( PI, -PI ), 3 ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); + + t.end(); +});