From 54a0638d93dab81c8d7f5a6b3e81f535f79ac965 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 12:29:12 +0530 Subject: [PATCH 01/17] feat: add math/base/special/roundnf --- .../math/base/special/roundnf/README.md | 210 ++++++++++++++++++ .../special/roundnf/benchmark/benchmark.js | 54 +++++ .../roundnf/benchmark/benchmark.native.js | 63 ++++++ .../roundnf/benchmark/c/native/Makefile | 125 +++++++++++ .../roundnf/benchmark/c/native/benchmark.c | 79 +++++++ .../math/base/special/roundnf/binding.gyp | 170 ++++++++++++++ .../math/base/special/roundnf/docs/repl.txt | 34 +++ .../special/roundnf/docs/types/index.d.ts | 32 +++ .../base/special/roundnf/docs/types/test.ts | 54 +++++ .../base/special/roundnf/examples/c/Makefile | 125 +++++++++++ .../base/special/roundnf/examples/c/example.c | 33 +++ .../base/special/roundnf/examples/index.js | 35 +++ .../math/base/special/roundnf/include.gypi | 53 +++++ .../stdlib/math/base/special/roundnf.h | 40 ++++ .../math/base/special/roundnf/lib/index.js | 55 +++++ .../math/base/special/roundnf/lib/main.js | 167 ++++++++++++++ .../math/base/special/roundnf/lib/native.js | 55 +++++ .../math/base/special/roundnf/manifest.json | 102 +++++++++ .../math/base/special/roundnf/package.json | 71 ++++++ .../math/base/special/roundnf/src/Makefile | 134 +++++++++++ .../math/base/special/roundnf/src/addon.c | 34 +++ .../math/base/special/roundnf/src/main.c | 146 ++++++++++++ .../math/base/special/roundnf/test/test.js | 110 +++++++++ .../base/special/roundnf/test/test.native.js | 115 ++++++++++ 24 files changed, 2096 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/include/stdlib/math/base/special/roundnf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md new file mode 100644 index 000000000000..368ab39dcb7a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md @@ -0,0 +1,210 @@ + + +# roundnf + +> Round a single-precision floating-point number to the nearest multiple of 10^n. + +
+ +## Usage + +```javascript +var roundnf = require( '@stdlib/math/base/special/roundnf' ); +``` + +#### roundnf( x, n ) + +Rounds a single-precision floating-point number to the nearest multiple of `10^n`. + +```javascript +// Round a value to 2 decimal places: +var v = roundnf( 3.141592, -2 ); +// returns 3.14 + +// If n = 0, `roundnf` behaves like `roundf`: +v = roundnf( 3.141592, 0 ); +// returns 3.0 + +// Round a value to the nearest hundred: +v = roundnf( 1234.56, 2 ); +// returns 1200.0 +``` + +
+ + + +
+ +## Notes + +- When operating on [floating-point numbers][ieee754] in bases other than `2`, rounding to specified digits can be **inexact**. For example, + + ```javascript + var x = 0.2 + 0.1; + // returns 0.30000000000000004 + + // Should round to 0.3... + var v = roundnf( x, -16 ); + // returns ~0.3000000000000001 + ``` + +- Ties are rounded toward positive infinity. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var roundnf = require( '@stdlib/math/base/special/roundnf' ); + +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 10, -50.0, 50.0, opts ); +var n = discreteUniform( 10, -5, 0, opts ); + +var i; +for ( i = 0; i < x.length; i++ ) { + console.log( 'roundnf(%f, %d) = %f', x[ i ], n[ i ], roundnf( x[ i ], n[ i ] ) ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/roundnf.h" +``` + +#### stdlib_base_roundnf( x, n ) + +Rounds a single-precision floating-point number to the nearest multiple of `10^n`. + +```c +float out = stdlib_base_roundnf( 3.141592f, -2 ); +// returns 3.14f +``` + +The function accepts the following arguments: + +- **x**: `[in] float` input value. +- **n**: `[in] int32_t` integer power of 10. + +```c +float stdlib_base_roundnf( const float x, const int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/roundnf.h" +#include + +int main( void ) { + const float x[] = { 3.141592f, -3.141592f, 1234.56f, -1234.56f }; + const int32_t n[] = { -2, -2, 2, 2 }; + + float v; + int i; + for ( i = 0; i < 4; i++ ) { + v = stdlib_base_roundnf( x[ i ], n[ i ] ); + printf( "roundnf(%f, %d) = %f\n", x[ i ], n[ i ], v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js new file mode 100644 index 000000000000..d87bf7b7c301 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var roundnf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var n; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 100.0 ) - 50.0; + n = discreteUniform( -5, 0 ); + y = roundnf( x, n ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..496076e510b4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var roundnf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( roundnf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var n; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 100.0 ) - 50.0; + n = discreteUniform( -5, 0 ); + y = roundnf( x, n ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..4e0b88bac199 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile @@ -0,0 +1,125 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS: +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 compiler: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define compiler flags: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code: +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes: +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries: +LIBRARIES ?= -lm + +# List of library paths: +LIBPATH ?= + +# List of C targets: +c_targets := benchmark + + +# RULES # + +#/ +# Compiles source files. +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +#/ +$(c_targets): %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$(c_targets) + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o $(c_targets) + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..cb143390ad08 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/roundnf.h" +#include +#include +#include +#include + +#define ITERATIONS 1000000 + +/** +* Runs benchmarks. +* +* @return elapsed time in seconds +*/ +static double benchmark() { + struct timeval start; + struct timeval end; + double elapsed; + float x; + float y; + int i; + + gettimeofday( &start, NULL ); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( ( (float)rand() / (float)RAND_MAX ) * 100.0f ) - 50.0f; + y = stdlib_base_roundnf( x, -2 ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + gettimeofday( &end, NULL ); + elapsed = (double)( end.tv_sec - start.tv_sec ) + ( (double)( end.tv_usec - start.tv_usec ) / 1.0e6 ); + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + double rate; + int i; + + // Warm-up: + for ( i = 0; i < 1000; i++ ) { + stdlib_base_roundnf( (float)i, -2 ); + } + + // Benchmark: + printf( "Benchmark: roundnf\n" ); + elapsed = benchmark(); + rate = (double)ITERATIONS / elapsed; + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %f sec\n", elapsed ); + printf( " rate: %f ops/sec\n", rate ); + + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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/roundnf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt new file mode 100644 index 000000000000..bf7e6ca808fe --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt @@ -0,0 +1,34 @@ +{{alias}}( x, n ) + Rounds a single-precision floating-point number to the nearest multiple + of `10^n`. + + Parameters + ---------- + x: number + Input value. + + n: integer + Integer power of 10. + + Returns + ------- + y: number + Rounded value. + + Examples + -------- + // Round to 2 decimal places: + > var y = {{alias}}( 3.141592, -2 ) + 3.14 + + // Round to nearest integer: + > y = {{alias}}( 3.7, 0 ) + 4.0 + + // Round to nearest hundred: + > y = {{alias}}( 1234.56, 2 ) + 1200.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts new file mode 100644 index 000000000000..1f1db093ad0f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts @@ -0,0 +1,32 @@ +/** +* Rounds a single-precision 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 x - input value +* @param n - integer power of `10` +* @returns rounded value +* +* @example +* // Round a value to 2 decimal places: +* var v = roundnf( 3.141592, -2 ); +* // returns 3.14 +* +* @example +* // If n = 0, `roundnf` behaves like `roundf`: +* var v = roundnf( 3.141592, 0 ); +* // returns 3.0 +* +* @example +* // Round a value to the nearest hundred: +* var v = roundnf( 1234.56, 2 ); +* // returns 1200.0 +*/ +declare function roundnf( x: number, n: number ): number; + + +// EXPORTS // + +export = roundnf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts new file mode 100644 index 000000000000..bf4ae28fbcf6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts @@ -0,0 +1,54 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import roundnf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + roundnf( 3.14, -2 ); // $ExpectType number + roundnf( 1234.56, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number for the first argument... +{ + roundnf( true, -2 ); // $ExpectError + roundnf( false, -2 ); // $ExpectError + roundnf( '5', -2 ); // $ExpectError + roundnf( [], -2 ); // $ExpectError + roundnf( {}, -2 ); // $ExpectError + roundnf( ( x: number ): number => x, -2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a value other than a number for the second argument... +{ + roundnf( 3.14, true ); // $ExpectError + roundnf( 3.14, false ); // $ExpectError + roundnf( 3.14, '5' ); // $ExpectError + roundnf( 3.14, [] ); // $ExpectError + roundnf( 3.14, {} ); // $ExpectError + roundnf( 3.14, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + roundnf(); // $ExpectError + roundnf( 3.14 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile new file mode 100644 index 000000000000..14ac0f9f7272 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile @@ -0,0 +1,125 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS: +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 compiler: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define compiler flags: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code: +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes: +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries: +LIBRARIES ?= -lm + +# List of library paths: +LIBPATH ?= + +# List of C targets: +c_targets := example + + +# RULES # + +#/ +# Compiles source files. +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +#/ +$(c_targets): %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$(c_targets) + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o $(c_targets) + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c new file mode 100644 index 000000000000..4cad9f443857 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/roundnf.h" +#include + +int main( void ) { + const float x[] = { 3.141592f, -3.141592f, 1234.56f, -1234.56f, 9.99999f, -9.99999f, 0.0f, -0.0f }; + const int32_t n[] = { -2, -2, 2, 2, -2, -2, -2, -2 }; + + float v; + int i; + for ( i = 0; i < 8; i++ ) { + v = stdlib_base_roundnf( x[ i ], n[ i ] ); + printf( "roundnf(%f, %d) = %f\n", x[ i ], n[ i ], v ); + } + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js new file mode 100644 index 000000000000..3b624522d78b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var roundnf = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 10, -50.0, 50.0, opts ); +var n = discreteUniform( 10, -5, 0, opts ); + +var i; +console.log( '' ); +for ( i = 0; i < x.length; i++ ) { + console.log( 'roundnf(%f, %d) = %f', x[ i ], n[ i ], roundnf( x[ i ], n[ i ] ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi b/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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 a single-precision floating-point number to the nearest multiple of `10^n`. +*/ +float stdlib_base_roundnf( const float x, const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_ROUNDNF_H diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js new file mode 100644 index 000000000000..00c5bd6993c1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Round a single-precision floating-point number to the nearest multiple of `10^n`. +* +* @module @stdlib/math/base/special/roundnf +* +* @example +* var roundnf = require( '@stdlib/math/base/special/roundnf' ); +* +* // Round a value to 2 decimal places: +* var v = roundnf( 3.141592, -2 ); +* // returns 3.14 +* +* @example +* var roundnf = require( '@stdlib/math/base/special/roundnf' ); +* +* // If n = 0, `roundnf` behaves like `roundf`: +* var v = roundnf( 3.141592, 0 ); +* // returns 3.0 +* +* @example +* var roundnf = require( '@stdlib/math/base/special/roundnf' ); +* +* // Round a value to the nearest hundred: +* var v = roundnf( 1234.56, 2 ); +* // returns 1200.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js new file mode 100644 index 000000000000..36f177b651cd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); +var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); +var powf = require( '@stdlib/math/base/special/powf' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float32/max-safe-integer' ); +var MAX_EXP = require( '@stdlib/constants/float32/max-base10-exponent' ); +var MIN_EXP = require( '@stdlib/constants/float32/min-base10-exponent' ); +var MIN_EXP_SUBNORMAL = require( '@stdlib/constants/float32/min-base10-exponent-subnormal' ); + + +// VARIABLES // + +var MAX_INT = MAX_SAFE_INTEGER + 1.0; +var HUGE = 1.0e+38; + + +// MAIN // + +/** +* Rounds a single-precision floating-point number to the nearest multiple of \\(10^n\\). +* +* ## Method +* +* 1. If \\(|x| <= 2^{24}\\) and \\(|n| <= 38\\), we can use the formula +* +* ```tex +* \\operatorname{roundnf}(x,n) = \\frac{\\operatorname{roundf}(x \\cdot 10^{-n})}{10^{-n}} +* ``` +* +* which shifts the decimal to the nearest multiple of \\(10^n\\), performs a standard \\(\\mathrm{roundf}\\) operation, and then shifts the decimal to its original position. +* +* +* +* If \\(x \\cdot 10^{-n}\\) overflows, \\(x\\) lacks a sufficient number of decimal digits to have any effect when rounding. Accordingly, the rounded value is \\(x\\). +* +* +* +* +* +* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) may not be \\(0.3\\) due to the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\\mathrm{roundf}\\). +* +* +* +* 2. If \\(n > 38\\), we recognize that the maximum absolute single-precision floating-point number is \\(\\approx 3.4\\mbox{e}38\\) and, thus, the result of rounding any possible finite number \\(x\\) to the nearest \\(10^n\\) is \\(0.0\\). To ensure consistent behavior with \\(\\operatorname{roundf}(x)\\), the sign of \\(x\\) is preserved. +* +* 3. If \\(n < -45\\), \\(n\\) exceeds the maximum number of possible decimal places (such as with subnormal numbers), and, thus, the rounded value is \\(x\\). +* +* 4. If \\(x > 2^{24}\\), \\(x\\) is **always** an integer (i.e., \\(x\\) has no decimal digits). If \\(n <= 0\\), the rounded value is \\(x\\). +* +* 5. If \\(n < -37\\), we let \\(m = n + 38\\) and modify the above formula to avoid overflow. +* +* ```tex +* \\operatorname{roundnf}(x,n) = \\frac{\\biggl(\\frac{\\operatorname{roundf}( (x \\cdot 10^{38}) 10^{-m})}{10^{38}}\\biggr)}{10^{-m}} +* ``` +* +* If overflow occurs, the rounded value is \\(x\\). +* +* ## Special Cases +* +* ```tex +* \\begin{align*} +* \\operatorname{roundnf}(\\mathrm{NaN}, n) &= \\mathrm{NaN} \\\\ +* \\operatorname{roundnf}(x, \\mathrm{NaN}) &= \\mathrm{NaN} \\\\ +* \\operatorname{roundnf}(x, \\pm\\infty) &= \\mathrm{NaN} \\\\ +* \\operatorname{roundnf}(\\pm\\infty, n) &= \\pm\\infty \\\\ +* \\operatorname{roundnf}(\\pm 0, n) &= \\pm 0 +* \\end{align*} +* ``` +* +* @param {number} x - input value +* @param {integer} n - integer power of `10` +* @returns {number} rounded value +* +* @example +* // Round a value to 2 decimal places: +* var v = roundnf( 3.141592, -2 ); +* // returns 3.14 +* +* @example +* // If n = 0, `roundnf` behaves like `roundf`: +* var v = roundnf( 3.141592, 0 ); +* // returns 3.0 +* +* @example +* // Round a value to the nearest hundred: +* var v = roundnf( 1234.56, 2 ); +* // returns 1200.0 +*/ +function roundnf( x, n ) { + var s; + var y; + + x = float64ToFloat32( x ); + + if ( + isnanf( x ) || + isnan( n ) || + isInfinite( n ) + ) { + return NaN; + } + if ( + // Handle infinities... + isInfinitef( x ) || + + // Handle +-0... + x === 0.0 || + + // If `n` exceeds the maximum number of feasible decimal places (such as with subnormal numbers), nothing to round... + n < MIN_EXP_SUBNORMAL || + + // If `|x|` is large enough, no decimals to round... + ( absf( x ) > MAX_INT && n <= 0 ) + ) { + return x; + } + // The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0. + if ( n > MAX_EXP ) { + return float64ToFloat32( 0.0 * x ); // preserve the sign (same behavior as roundf) + } + // If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding... + if ( n < MIN_EXP ) { + s = powf( 10.0, -( n + MAX_EXP ) ); + y = float64ToFloat32( float64ToFloat32( x * HUGE ) * s ); // order of operation matters! + if ( isInfinitef( y ) ) { + return x; + } + return float64ToFloat32( float64ToFloat32( roundf( y ) / HUGE ) / s ); + } + s = powf( 10.0, -n ); + y = float64ToFloat32( x * s ); + if ( isInfinitef( y ) ) { + return x; + } + return float64ToFloat32( roundf( y ) / s ); +} + + +// EXPORTS // + +module.exports = roundnf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js new file mode 100644 index 000000000000..e7bdfbea6412 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds a single-precision floating-point number to the nearest multiple of `10^n`. +* +* @private +* @param {number} x - input value +* @param {integer} n - integer power of `10` +* @returns {number} rounded value +* +* @example +* var v = roundnf( 3.141592, -2 ); +* // returns 3.14 +* +* @example +* var v = roundnf( 3.141592, 0 ); +* // returns 3.0 +* +* @example +* var v = roundnf( 1234.56, 2 ); +* // returns 1200.0 +*/ +function roundnf( x, n ) { + return addon( x, n ); +} + + +// EXPORTS // + +module.exports = roundnf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundnf/manifest.json new file mode 100644 index 000000000000..2d40f1f8b40f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/manifest.json @@ -0,0 +1,102 @@ +{ + "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/absf", + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/powf", + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/constants/float32/max-base10-exponent", + "@stdlib/constants/float32/min-base10-exponent", + "@stdlib/constants/float32/min-base10-exponent-subnormal", + "@stdlib/math/base/assert/is-infinitef", + "@stdlib/math/base/assert/is-nanf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/powf", + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/constants/float32/max-base10-exponent", + "@stdlib/constants/float32/min-base10-exponent", + "@stdlib/constants/float32/min-base10-exponent-subnormal", + "@stdlib/math/base/assert/is-infinitef", + "@stdlib/math/base/assert/is-nanf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/powf", + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/constants/float32/max-base10-exponent", + "@stdlib/constants/float32/min-base10-exponent", + "@stdlib/constants/float32/min-base10-exponent-subnormal", + "@stdlib/math/base/assert/is-infinitef", + "@stdlib/math/base/assert/is-nanf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/package.json b/lib/node_modules/@stdlib/math/base/special/roundnf/package.json new file mode 100644 index 000000000000..0d28d30668fc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/math/base/special/roundnf", + "version": "0.0.0", + "description": "Round a single-precision 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", + "math", + "mathematics", + "round", + "roundnf", + "rounding", + "float", + "float32", + "single", + "precision", + "floating-point", + "number", + "decimal", + "ieee754" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile new file mode 100644 index 000000000000..2c12db3307b8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile @@ -0,0 +1,134 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# 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 := addon.node + + +# 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 flags +# @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): %.node: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) -lm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c new file mode 100644 index 000000000000..564437c8c95e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/roundnf.h" +#include "stdlib/math/base/napi/binary.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param x input value +* @param n power of 10 +* @return roundnf( (float)x, (int32_t)n ) +*/ +static double addon( const double x, const double n ) { + return (double)stdlib_base_roundnf( (float)x, (int32_t)n ); +} + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c new file mode 100644 index 000000000000..60f2a113e41a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/roundnf.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/assert/is_infinitef.h" +#include "stdlib/math/base/special/absf.h" +#include "stdlib/math/base/special/roundf.h" +#include "stdlib/math/base/special/powf.h" +#include "stdlib/constants/float32/max_safe_integer.h" +#include "stdlib/constants/float32/max_base10_exponent.h" +#include "stdlib/constants/float32/min_base10_exponent.h" +#include "stdlib/constants/float32/min_base10_exponent_subnormal.h" +#include + +static const float MAX_INT = STDLIB_CONSTANT_FLOAT32_MAX_SAFE_INTEGER + 1.0f; +static const float HUGE_VALUE = 1.0e+38f; + +/** +* Rounds a single-precision floating-point number to the nearest multiple of `10^n`. +* +* ## Method +* +* 1. If \\(|x| <= 2^{24}\\) and \\(|n| <= 38\\), we can use the formula +* +* ```tex +* \\operatorname{roundnf}(x,n) = \\frac{\\operatorname{roundf}(x \\cdot 10^{-n})}{10^{-n}} +* ``` +* +* which shifts the decimal to the nearest multiple of \\(10^n\\), performs a standard \\(\\mathrm{roundf}\\) operation, and then shifts the decimal to its original position. +* +* +* +* If \\(x \\cdot 10^{-n}\\) overflows, \\(x\\) lacks a sufficient number of decimal digits to have any effect when rounding. Accordingly, the rounded value is \\(x\\). +* +* +* +* +* +* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) may not be \\(0.3\\) due to the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\\mathrm{roundf}\\). +* +* +* +* 2. If \\(n > 38\\), we recognize that the maximum absolute single-precision floating-point number is \\(\\approx 3.4\\mbox{e}38\\) and, thus, the result of rounding any possible finite number \\(x\\) to the nearest \\(10^n\\) is \\(0.0\\). To ensure consistent behavior with \\(\\operatorname{roundf}(x)\\), the sign of \\(x\\) is preserved. +* +* 3. If \\(n < -45\\), \\(n\\) exceeds the maximum number of possible decimal places (such as with subnormal numbers), and, thus, the rounded value is \\(x\\). +* +* 4. If \\(x > 2^{24}\\), \\(x\\) is **always** an integer (i.e., \\(x\\) has no decimal digits). If \\(n <= 0\\), the rounded value is \\(x\\). +* +* 5. If \\(n < -37\\), we let \\(m = n + 38\\) and modify the above formula to avoid overflow. +* +* ```tex +* \\operatorname{roundnf}(x,n) = \\frac{\\biggl(\\frac{\\operatorname{roundf}( (x \\cdot 10^{38}) 10^{-m})}{10^{38}}\\biggr)}{10^{-m}} +* ``` +* +* If overflow occurs, the rounded value is \\(x\\). +* +* ## Special Cases +* +* ```tex +* \\begin{align*} +* \\operatorname{roundnf}(\\mathrm{NaN}, n) &= \\mathrm{NaN} \\\\ +* \\operatorname{roundnf}(x, \\mathrm{NaN}) &= \\mathrm{NaN} \\\\ +* \\operatorname{roundnf}(x, \\pm\\infty) &= \\mathrm{NaN} \\\\ +* \\operatorname{roundnf}(\\pm\\infty, n) &= \\pm\\infty \\\\ +* \\operatorname{roundnf}(\\pm 0, n) &= \\pm 0 +* \\end{align*} +* ``` +* +* @param x number +* @param n power of 10 +* @return rounded value +* +* @example +* // Round a value to 2 decimal places: +* float v = stdlib_base_roundnf( 3.141592f, -2 ); +* // returns 3.14f +* +* @example +* // If n = 0, `roundnf` behaves like `roundf`: +* float v = stdlib_base_roundnf( 3.141592f, 0 ); +* // returns 3.0f +* +* @example +* // Round a value to the nearest hundred: +* float v = stdlib_base_roundnf( 1234.56f, 2 ); +* // returns 1200.0f +*/ +float stdlib_base_roundnf( const float x, const int32_t n ) { + float s; + float y; + + if ( stdlib_base_is_nanf( x ) ) { + return 0.0f / 0.0f; // NaN + } + + if ( + // Handle infinites... + stdlib_base_is_infinitef( x ) || + + // Handle +-0... + x == 0.0f || + + // If `n` exceeds the maximum number of feasible decimal places (such as with subnormal numbers), nothing to round... + n < STDLIB_CONSTANT_FLOAT32_MIN_BASE10_EXPONENT_SUBNORMAL || + + // If `|x|` is large enough, no decimals to round... + ( stdlib_base_absf( x ) > MAX_INT && n <= 0 ) + ) { + return x; + } + // The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0. + if ( n > STDLIB_CONSTANT_FLOAT32_MAX_BASE10_EXPONENT ) { + return 0.0f * x; // preserve the sign (same behavior as roundf) + } + // If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding... + if ( n < STDLIB_CONSTANT_FLOAT32_MIN_BASE10_EXPONENT ) { + s = stdlib_base_powf( 10.0f, (float)-(n + STDLIB_CONSTANT_FLOAT32_MAX_BASE10_EXPONENT) ); + y = ( x * HUGE_VALUE ) * s; // order of operation matters! + if ( stdlib_base_is_infinitef( y ) ) { + return x; + } + return ( stdlib_base_roundf( y ) / HUGE_VALUE ) / s; + } + s = stdlib_base_powf( 10.0f, (float)-n ); + y = x * s; + if ( stdlib_base_is_infinitef( y ) ) { + return x; + } + return stdlib_base_roundf( y ) / s; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js new file mode 100644 index 000000000000..394c0c299b3d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +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 PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var roundnf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof roundnf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns NaN if provided NaN', function test( t ) { + var v = roundnf( NaN, -2 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns NaN if provided n = NaN', function test( t ) { + var v = roundnf( 3.14, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns +infinity if provided +infinity', function test( t ) { + var v = roundnf( PINF, -2 ); + t.strictEqual( v, PINF, 'returns +infinity' ); + t.end(); +}); + +tape( 'the function returns -infinity if provided -infinity', function test( t ) { + var v = roundnf( NINF, -2 ); + t.strictEqual( v, NINF, 'returns -infinity' ); + t.end(); +}); + +tape( 'the function returns +0 if provided +0', function test( t ) { + var v = roundnf( 0.0, -2 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns +0' ); + t.end(); +}); + +tape( 'the function returns -0 if provided -0', function test( t ) { + var v = roundnf( -0.0, -2 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); + t.end(); +}); + +tape( 'the function supports rounding to 2 decimal places', function test( t ) { + t.strictEqual( roundnf( 3.141592, -2 ), float64ToFloat32( 3.14 ), 'returns expected value' ); + t.strictEqual( roundnf( 9.99999, -2 ), float64ToFloat32( 10.0 ), 'returns expected value' ); + t.strictEqual( roundnf( -1.234567, -2 ), float64ToFloat32( -1.23 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding to nearest integer (n=0)', function test( t ) { + t.strictEqual( roundnf( 3.7, 0 ), float64ToFloat32( 4.0 ), 'returns expected value' ); + t.strictEqual( roundnf( 3.2, 0 ), float64ToFloat32( 3.0 ), 'returns expected value' ); + t.strictEqual( roundnf( -3.7, 0 ), float64ToFloat32( -4.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding to nearest hundred (n=2)', function test( t ) { + t.strictEqual( roundnf( 1234.56, 2 ), float64ToFloat32( 1200.0 ), 'returns expected value' ); + t.strictEqual( roundnf( 1299.99, 2 ), float64ToFloat32( 1300.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding to nearest thousand (n=3)', function test( t ) { + var v = roundnf( 12368.0, 3 ); + var expected = float64ToFloat32( 12000.0 ); + // Due to float32 precision, allow small error (< 1.0) + t.ok( Math.abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); + t.end(); +}); + +tape( 'if a value is too large, the function returns the input value', function test( t ) { + var x = float64ToFloat32( 1.0e20 ); + t.strictEqual( roundnf( x, -2 ), x, 'returns input value' ); + t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js new file mode 100644 index 000000000000..c3c60850bb56 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var 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 PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var roundnf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( roundnf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof roundnf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns NaN if provided NaN', opts, function test( t ) { + var v = roundnf( NaN, -2 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns NaN if provided n = NaN', opts, function test( t ) { + var v = roundnf( 3.14, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns +infinity if provided +infinity', opts, function test( t ) { + var v = roundnf( PINF, -2 ); + t.strictEqual( v, PINF, 'returns +infinity' ); + t.end(); +}); + +tape( 'the function returns -infinity if provided -infinity', opts, function test( t ) { + var v = roundnf( NINF, -2 ); + t.strictEqual( v, NINF, 'returns -infinity' ); + t.end(); +}); + +tape( 'the function returns +0 if provided +0', opts, function test( t ) { + var v = roundnf( 0.0, -2 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns +0' ); + t.end(); +}); + +tape( 'the function returns -0 if provided -0', opts, function test( t ) { + var v = roundnf( -0.0, -2 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); + t.end(); +}); + +tape( 'the function supports rounding to 2 decimal places', opts, function test( t ) { + t.strictEqual( roundnf( 3.141592, -2 ), 3.14, 'returns expected value' ); + t.strictEqual( roundnf( 9.99999, -2 ), 10.0, 'returns expected value' ); + t.strictEqual( roundnf( -1.234567, -2 ), -1.23, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding to nearest integer (n=0)', opts, function test( t ) { + t.strictEqual( roundnf( 3.7, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( roundnf( 3.2, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( roundnf( -3.7, 0 ), -4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding to nearest hundred (n=2)', opts, function test( t ) { + t.strictEqual( roundnf( 1234.56, 2 ), 1200.0, 'returns expected value' ); + t.strictEqual( roundnf( 1299.99, 2 ), 1300.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding to nearest thousand (n=3)', opts, function test( t ) { + t.strictEqual( roundnf( 12368.0, 3 ), 12000.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if a value is too large, the function returns the input value', opts, function test( t ) { + var x = 1.0e20; + t.strictEqual( roundnf( x, -2 ), x, 'returns input value' ); + t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' ); + t.end(); +}); From 763596aef427986201a2e832811873d2881e4f06 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 12:50:22 +0530 Subject: [PATCH 02/17] fix: correct float32 doctest values and lint errors in roundnf --- .../math/base/special/roundnf/README.md | 4 ++-- .../roundnf/benchmark/c/native/benchmark.c | 4 ++-- .../math/base/special/roundnf/docs/repl.txt | 2 +- .../special/roundnf/docs/types/index.d.ts | 22 ++++++++++++++++++- .../base/special/roundnf/examples/c/Makefile | 2 +- .../math/base/special/roundnf/lib/index.js | 2 +- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md index 368ab39dcb7a..f0fdff6760c5 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md @@ -37,7 +37,7 @@ Rounds a single-precision floating-point number to the nearest multiple of `10^n ```javascript // Round a value to 2 decimal places: var v = roundnf( 3.141592, -2 ); -// returns 3.14 +// returns 3.140000104904175 // If n = 0, `roundnf` behaves like `roundf`: v = roundnf( 3.141592, 0 ); @@ -64,7 +64,7 @@ v = roundnf( 1234.56, 2 ); // Should round to 0.3... var v = roundnf( x, -16 ); - // returns ~0.3000000000000001 + // returns 0.30000001192092896 ``` - Ties are rounded toward positive infinity. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c index cb143390ad08..409ebbd53ee8 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c @@ -66,7 +66,7 @@ int main( void ) { for ( i = 0; i < 1000; i++ ) { stdlib_base_roundnf( (float)i, -2 ); } - + // Benchmark: printf( "Benchmark: roundnf\n" ); elapsed = benchmark(); @@ -74,6 +74,6 @@ int main( void ) { printf( " iterations: %d\n", ITERATIONS ); printf( " elapsed: %f sec\n", elapsed ); printf( " rate: %f ops/sec\n", rate ); - + return 0; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt index bf7e6ca808fe..7b341334f57c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt @@ -19,7 +19,7 @@ -------- // Round to 2 decimal places: > var y = {{alias}}( 3.141592, -2 ) - 3.14 + 3.140000104904175 // Round to nearest integer: > y = {{alias}}( 3.7, 0 ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts index 1f1db093ad0f..b4804942afac 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts @@ -1,3 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + /** * Rounds a single-precision floating-point number to the nearest multiple of `10^n`. * @@ -12,7 +32,7 @@ * @example * // Round a value to 2 decimal places: * var v = roundnf( 3.141592, -2 ); -* // returns 3.14 +* // returns 3.140000104904175 * * @example * // If n = 0, `roundnf` behaves like `roundf`: diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile index 14ac0f9f7272..a1a969527e06 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile @@ -99,7 +99,7 @@ all: $(c_targets) # # @private #/ -$(c_targets): %.c +$(c_targets): %: %.c $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) #/ diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js index 00c5bd6993c1..922fb7a21e0b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js @@ -28,7 +28,7 @@ * * // Round a value to 2 decimal places: * var v = roundnf( 3.141592, -2 ); -* // returns 3.14 +* // returns 3.140000104904175 * * @example * var roundnf = require( '@stdlib/math/base/special/roundnf' ); From 153d4e96b42deba663bae04788dc29ea13432a91 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 12:58:33 +0530 Subject: [PATCH 03/17] fixes the Lint errors --- .../roundnf/benchmark/c/native/Makefile | 2 +- .../math/base/special/roundnf/lib/main.js | 4 +-- .../base/special/roundnf/test/test.native.js | 26 +++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile index 4e0b88bac199..46054174e863 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile @@ -99,7 +99,7 @@ all: $(c_targets) # # @private #/ -$(c_targets): %.c +$(c_targets): %: %.c $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) #/ diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js index 36f177b651cd..ea80beb57eb9 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js @@ -100,7 +100,7 @@ var HUGE = 1.0e+38; * @example * // Round a value to 2 decimal places: * var v = roundnf( 3.141592, -2 ); -* // returns 3.14 +* // returns 3.140000104904175 * * @example * // If n = 0, `roundnf` behaves like `roundf`: @@ -142,7 +142,7 @@ function roundnf( x, n ) { } // The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0. if ( n > MAX_EXP ) { - return float64ToFloat32( 0.0 * x ); // preserve the sign (same behavior as roundf) + return float64ToFloat32( 0.0 * x ); // preserve the sign (same behavior as roundf) // cspell:disable-line } // If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding... if ( n < MIN_EXP ) { diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index c3c60850bb56..8d2baa93d91d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -22,12 +22,13 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); 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 PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); -var tryRequire = require( '@stdlib/utils/try-require' ); // VARIABLES // @@ -83,32 +84,35 @@ tape( 'the function returns -0 if provided -0', opts, function test( t ) { }); tape( 'the function supports rounding to 2 decimal places', opts, function test( t ) { - t.strictEqual( roundnf( 3.141592, -2 ), 3.14, 'returns expected value' ); - t.strictEqual( roundnf( 9.99999, -2 ), 10.0, 'returns expected value' ); - t.strictEqual( roundnf( -1.234567, -2 ), -1.23, 'returns expected value' ); + t.strictEqual( roundnf( 3.141592, -2 ), float64ToFloat32( 3.14 ), 'returns expected value' ); + t.strictEqual( roundnf( 9.99999, -2 ), float64ToFloat32( 10.0 ), 'returns expected value' ); + t.strictEqual( roundnf( -1.234567, -2 ), float64ToFloat32( -1.23 ), 'returns expected value' ); t.end(); }); tape( 'the function supports rounding to nearest integer (n=0)', opts, function test( t ) { - t.strictEqual( roundnf( 3.7, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( roundnf( 3.2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( roundnf( -3.7, 0 ), -4.0, 'returns expected value' ); + t.strictEqual( roundnf( 3.7, 0 ), float64ToFloat32( 4.0 ), 'returns expected value' ); + t.strictEqual( roundnf( 3.2, 0 ), float64ToFloat32( 3.0 ), 'returns expected value' ); + t.strictEqual( roundnf( -3.7, 0 ), float64ToFloat32( -4.0 ), 'returns expected value' ); t.end(); }); tape( 'the function supports rounding to nearest hundred (n=2)', opts, function test( t ) { - t.strictEqual( roundnf( 1234.56, 2 ), 1200.0, 'returns expected value' ); - t.strictEqual( roundnf( 1299.99, 2 ), 1300.0, 'returns expected value' ); + t.strictEqual( roundnf( 1234.56, 2 ), float64ToFloat32( 1200.0 ), 'returns expected value' ); + t.strictEqual( roundnf( 1299.99, 2 ), float64ToFloat32( 1300.0 ), 'returns expected value' ); t.end(); }); tape( 'the function supports rounding to nearest thousand (n=3)', opts, function test( t ) { - t.strictEqual( roundnf( 12368.0, 3 ), 12000.0, 'returns expected value' ); + var v = roundnf( 12368.0, 3 ); + var expected = float64ToFloat32( 12000.0 ); + // Due to float32 precision, allow small error (< 1.0) + t.ok( Math.abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); t.end(); }); tape( 'if a value is too large, the function returns the input value', opts, function test( t ) { - var x = 1.0e20; + var x = float64ToFloat32( 1.0e20 ); t.strictEqual( roundnf( x, -2 ), x, 'returns input value' ); t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' ); t.end(); From ff1cfab93bc06d61d2c796a8e5de4a0906e3f9e0 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 13:04:42 +0530 Subject: [PATCH 04/17] fixes the Lint errors --- .../@stdlib/math/base/special/roundnf/lib/native.js | 4 +++- .../@stdlib/math/base/special/roundnf/test/test.native.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js index e7bdfbea6412..d59f92772e50 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js @@ -34,8 +34,10 @@ var addon = require( './../src/addon.node' ); * @returns {number} rounded value * * @example +* var roundnf = require( '@stdlib/math/base/special/roundnf/native.js' ); +* * var v = roundnf( 3.141592, -2 ); -* // returns 3.14 +* // returns 3.140000104904175 * * @example * var v = roundnf( 3.141592, 0 ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index 8d2baa93d91d..1be03f8d28a8 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -55,7 +55,7 @@ tape( 'the function returns NaN if provided NaN', opts, function test( t ) { tape( 'the function returns NaN if provided n = NaN', opts, function test( t ) { var v = roundnf( 3.14, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( float64ToFloat32( v ) ), true, 'returns NaN' ); t.end(); }); From 15255dee7b6fe680f3900a4553e29c7ce78bccb7 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 13:41:09 +0530 Subject: [PATCH 05/17] fix: resolve all CI errors - float32 precision, lint fixes, and N-API corrections --- .../@stdlib/math/base/special/roundnf/lib/native.js | 2 -- .../@stdlib/math/base/special/roundnf/src/addon.c | 6 +++--- .../@stdlib/math/base/special/roundnf/test/test.js | 6 ++++-- .../@stdlib/math/base/special/roundnf/test/test.native.js | 6 ------ 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js index d59f92772e50..1972e395ecd3 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js @@ -34,8 +34,6 @@ var addon = require( './../src/addon.node' ); * @returns {number} rounded value * * @example -* var roundnf = require( '@stdlib/math/base/special/roundnf/native.js' ); -* * var v = roundnf( 3.141592, -2 ); * // returns 3.140000104904175 * diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c index 564437c8c95e..41deb5f23bd2 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c @@ -27,8 +27,8 @@ * @param n power of 10 * @return roundnf( (float)x, (int32_t)n ) */ -static double addon( const double x, const double n ) { - return (double)stdlib_base_roundnf( (float)x, (int32_t)n ); +static float addon( const float x, const int32_t n ) { + return stdlib_base_roundnf( x, n ); } -STDLIB_MATH_BASE_NAPI_MODULE_DD_D( addon ) +STDLIB_MATH_BASE_NAPI_MODULE_FI_F( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js index 394c0c299b3d..bd111c3f50bb 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); 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' ); @@ -95,10 +96,11 @@ tape( 'the function supports rounding to nearest hundred (n=2)', function test( }); tape( 'the function supports rounding to nearest thousand (n=3)', function test( t ) { - var v = roundnf( 12368.0, 3 ); var expected = float64ToFloat32( 12000.0 ); + var v = roundnf( 12368.0, 3 ); + // Due to float32 precision, allow small error (< 1.0) - t.ok( Math.abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); + t.ok( abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index 1be03f8d28a8..9a8837194fa8 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -53,12 +53,6 @@ tape( 'the function returns NaN if provided NaN', opts, function test( t ) { t.end(); }); -tape( 'the function returns NaN if provided n = NaN', opts, function test( t ) { - var v = roundnf( 3.14, NaN ); - t.strictEqual( isnanf( float64ToFloat32( v ) ), true, 'returns NaN' ); - t.end(); -}); - tape( 'the function returns +infinity if provided +infinity', opts, function test( t ) { var v = roundnf( PINF, -2 ); t.strictEqual( v, PINF, 'returns +infinity' ); From 67377241ea262e24dd2cbfa2c007454257bd4002 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 13:45:23 +0530 Subject: [PATCH 06/17] fix: resolve lint errors in test.native.js --- .../@stdlib/math/base/special/roundnf/test/test.native.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index 9a8837194fa8..934c95e51b3c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -24,9 +24,10 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var tryRequire = require( '@stdlib/utils/try-require' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var abs = require( '@stdlib/math/base/special/abs' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); @@ -98,10 +99,11 @@ tape( 'the function supports rounding to nearest hundred (n=2)', opts, function }); tape( 'the function supports rounding to nearest thousand (n=3)', opts, function test( t ) { - var v = roundnf( 12368.0, 3 ); var expected = float64ToFloat32( 12000.0 ); + var v = roundnf( 12368.0, 3 ); + // Due to float32 precision, allow small error (< 1.0) - t.ok( Math.abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); + t.ok( abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); t.end(); }); From 8a020f2fc63a06aeb2e23d0f8ce6685c046cdbb2 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 27 Dec 2025 14:12:26 +0530 Subject: [PATCH 07/17] refactor: use standard N-API pattern matching ldexpf convention --- .../@stdlib/math/base/special/roundnf/src/addon.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c index 41deb5f23bd2..8e0e789c91c9 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c @@ -18,17 +18,5 @@ #include "stdlib/math/base/special/roundnf.h" #include "stdlib/math/base/napi/binary.h" -#include -/** -* Receives JavaScript callback invocation data. -* -* @param x input value -* @param n power of 10 -* @return roundnf( (float)x, (int32_t)n ) -*/ -static float addon( const float x, const int32_t n ) { - return stdlib_base_roundnf( x, n ); -} - -STDLIB_MATH_BASE_NAPI_MODULE_FI_F( addon ) +STDLIB_MATH_BASE_NAPI_MODULE_FI_F( stdlib_base_roundnf ) From 07c8f39ac47503f37128c6369d8c78f1bfa3218f Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 28 Dec 2025 11:22:07 +0530 Subject: [PATCH 08/17] =?UTF-8?q?test:=20add=20edge=20case=20tests=20for?= =?UTF-8?q?=20n=3D=C2=B1Infinity=20and=20extreme=20exponent=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../math/base/special/roundnf/test/test.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js index bd111c3f50bb..d270f71396ee 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js @@ -51,6 +51,18 @@ tape( 'the function returns NaN if provided n = NaN', function test( t ) { t.end(); }); +tape( 'the function returns NaN if provided n = +-infinity', function test( t ) { + var v; + + v = roundnf( 3.14, PINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN when n = +infinity' ); + + v = roundnf( 3.14, NINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN when n = -infinity' ); + + t.end(); +}); + tape( 'the function returns +infinity if provided +infinity', function test( t ) { var v = roundnf( PINF, -2 ); t.strictEqual( v, PINF, 'returns +infinity' ); @@ -110,3 +122,27 @@ tape( 'if a value is too large, the function returns the input value', function t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' ); t.end(); }); + +tape( 'if `n` exceeds the maximum exponent, the function returns `+-0` (sign preserving)', function test( t ) { + var v; + + v = roundnf( 3.14, 40 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns +0 when x > 0 and n > MAX_EXP' ); + + v = roundnf( -3.14, 40 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns -0 when x < 0 and n > MAX_EXP' ); + + t.end(); +}); + +tape( 'if `n` is less than the minimum subnormal exponent, the function returns the input value', function test( t ) { + var v; + + v = roundnf( 3.14, -50 ); + t.strictEqual( v, float64ToFloat32( 3.14 ), 'returns input value when n < MIN_EXP_SUBNORMAL' ); + + v = roundnf( -2.71, -50 ); + t.strictEqual( v, float64ToFloat32( -2.71 ), 'returns input value when n < MIN_EXP_SUBNORMAL' ); + + t.end(); +}); From 2df69c180d70f5e0157e72af9168f223d216241f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 30 Dec 2025 15:58:44 -0800 Subject: [PATCH 09/17] docs: fix examples --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/roundnf/lib/index.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js index 922fb7a21e0b..a13d3457619f 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js @@ -27,22 +27,16 @@ * var roundnf = require( '@stdlib/math/base/special/roundnf' ); * * // Round a value to 2 decimal places: -* var v = roundnf( 3.141592, -2 ); -* // returns 3.140000104904175 -* -* @example -* var roundnf = require( '@stdlib/math/base/special/roundnf' ); +* var v = roundnf( 3.1415927410125732, -2 ); +* // returns ~3.14 * * // If n = 0, `roundnf` behaves like `roundf`: -* var v = roundnf( 3.141592, 0 ); +* var v = roundnf( 3.1415927410125732, 0 ); * // returns 3.0 * -* @example -* var roundnf = require( '@stdlib/math/base/special/roundnf' ); -* * // Round a value to the nearest hundred: -* var v = roundnf( 1234.56, 2 ); -* // returns 1200.0 +* var v = roundnf( 12368.0, 3 ); +* // returns ~12000.0 */ // MODULES // From e80d5d69cfeb022a77bee384b682546203930220 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 30 Dec 2025 15:59:11 -0800 Subject: [PATCH 10/17] fix: use correct `f32` emulation --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/roundnf/lib/main.js | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js index ea80beb57eb9..5aaa9a7bae93 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js @@ -21,13 +21,11 @@ // MODULES // var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' ); var roundf = require( '@stdlib/math/base/special/roundf' ); var powf = require( '@stdlib/math/base/special/powf' ); var absf = require( '@stdlib/math/base/special/absf' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); var MAX_SAFE_INTEGER = require( '@stdlib/constants/float32/max-safe-integer' ); var MAX_EXP = require( '@stdlib/constants/float32/max-base10-exponent' ); var MIN_EXP = require( '@stdlib/constants/float32/min-base10-exponent' ); @@ -36,8 +34,8 @@ var MIN_EXP_SUBNORMAL = require( '@stdlib/constants/float32/min-base10-exponent- // VARIABLES // -var MAX_INT = MAX_SAFE_INTEGER + 1.0; -var HUGE = 1.0e+38; +var MAX_INT = MAX_SAFE_INTEGER + 1; +var HUGE = f32( 1.0e+38 ); // MAIN // @@ -63,7 +61,7 @@ var HUGE = 1.0e+38; * * * -* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) may not be \\(0.3\\) due to the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\\mathrm{roundf}\\). +* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\). * * * @@ -73,7 +71,7 @@ var HUGE = 1.0e+38; * * 4. If \\(x > 2^{24}\\), \\(x\\) is **always** an integer (i.e., \\(x\\) has no decimal digits). If \\(n <= 0\\), the rounded value is \\(x\\). * -* 5. If \\(n < -37\\), we let \\(m = n + 38\\) and modify the above formula to avoid overflow. +* 5. If \\(n < -38\\), we let \\(m = n + 38\\) and modify the above formula to avoid overflow. * * ```tex * \\operatorname{roundnf}(x,n) = \\frac{\\biggl(\\frac{\\operatorname{roundf}( (x \\cdot 10^{38}) 10^{-m})}{10^{38}}\\biggr)}{10^{-m}} @@ -99,29 +97,28 @@ var HUGE = 1.0e+38; * * @example * // Round a value to 2 decimal places: -* var v = roundnf( 3.141592, -2 ); -* // returns 3.140000104904175 +* var v = roundnf( 3.1415927410125732, -2 ); +* // returns ~3.14 * * @example * // If n = 0, `roundnf` behaves like `roundf`: -* var v = roundnf( 3.141592, 0 ); +* var v = roundnf( 3.1415927410125732, 0 ); * // returns 3.0 * * @example * // Round a value to the nearest hundred: -* var v = roundnf( 1234.56, 2 ); -* // returns 1200.0 +* var v = roundnf( 12368.0, 3 ); +* // returns ~12000.0 */ function roundnf( x, n ) { var s; var y; - x = float64ToFloat32( x ); - + x = f32( x ); if ( isnanf( x ) || - isnan( n ) || - isInfinite( n ) + isnanf( n ) || + isInfinitef( n ) ) { return NaN; } @@ -142,23 +139,23 @@ function roundnf( x, n ) { } // The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0. if ( n > MAX_EXP ) { - return float64ToFloat32( 0.0 * x ); // preserve the sign (same behavior as roundf) // cspell:disable-line + return f32( f32( 0.0 ) * x ); // preserve the sign (same behavior as roundf) } // If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding... if ( n < MIN_EXP ) { - s = powf( 10.0, -( n + MAX_EXP ) ); - y = float64ToFloat32( float64ToFloat32( x * HUGE ) * s ); // order of operation matters! + s = powf( f32( 10.0 ), -( n + MAX_EXP ) ); + y = f32( f32( x * HUGE ) * s ); // order of operation matters! if ( isInfinitef( y ) ) { return x; } - return float64ToFloat32( float64ToFloat32( roundf( y ) / HUGE ) / s ); + return f32( f32( roundf( y ) / HUGE ) / s ); } - s = powf( 10.0, -n ); - y = float64ToFloat32( x * s ); + s = powf( f32( 10.0 ), -n ); + y = f32( x * s ); if ( isInfinitef( y ) ) { return x; } - return float64ToFloat32( roundf( y ) / s ); + return f32( roundf( y ) / s ); } From dd9e666aa3e7413f9c725167a1afe0fcd3211e14 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 30 Dec 2025 16:00:57 -0800 Subject: [PATCH 11/17] docs: fix examples --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/roundnf/lib/native.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js index 1972e395ecd3..394c239cf584 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Rounds a single-precision floating-point number to the nearest multiple of `10^n`. +* Rounds a single-precision floating-point number to the nearest multiple of \\(10^n\\). * * @private * @param {number} x - input value @@ -34,16 +34,19 @@ var addon = require( './../src/addon.node' ); * @returns {number} rounded value * * @example -* var v = roundnf( 3.141592, -2 ); -* // returns 3.140000104904175 +* // Round a value to 2 decimal places: +* var v = roundn( 3.141592653589793, -2 ); +* // returns 3.14 * * @example -* var v = roundnf( 3.141592, 0 ); +* // If n = 0, `roundn` behaves like `round`: +* var v = roundn( 3.141592653589793, 0 ); * // returns 3.0 * * @example -* var v = roundnf( 1234.56, 2 ); -* // returns 1200.0 +* // Round a value to the nearest thousand: +* var v = roundn( 12368.0, 3 ); +* // returns 12000.0 */ function roundnf( x, n ) { return addon( x, n ); From 6271ce21cb6a5d45097738ab13adee0b2816e60e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 30 Dec 2025 16:07:37 -0800 Subject: [PATCH 12/17] docs: fix examples --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/roundnf/lib/index.js | 2 +- .../math/base/special/roundnf/lib/main.js | 2 +- .../math/base/special/roundnf/lib/native.js | 12 ++++++------ .../@stdlib/math/base/special/roundnf/src/main.c | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js index a13d3457619f..984177012437 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js @@ -34,7 +34,7 @@ * var v = roundnf( 3.1415927410125732, 0 ); * // returns 3.0 * -* // Round a value to the nearest hundred: +* // Round a value to the nearest thousand: * var v = roundnf( 12368.0, 3 ); * // returns ~12000.0 */ diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js index 5aaa9a7bae93..d7486373f0ca 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js @@ -106,7 +106,7 @@ var HUGE = f32( 1.0e+38 ); * // returns 3.0 * * @example -* // Round a value to the nearest hundred: +* // Round a value to the nearest thousand: * var v = roundnf( 12368.0, 3 ); * // returns ~12000.0 */ diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js index 394c239cf584..390be6912b27 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js @@ -35,18 +35,18 @@ var addon = require( './../src/addon.node' ); * * @example * // Round a value to 2 decimal places: -* var v = roundn( 3.141592653589793, -2 ); -* // returns 3.14 +* var v = roundnf( 3.1415927410125732, -2 ); +* // returns ~3.14 * * @example -* // If n = 0, `roundn` behaves like `round`: -* var v = roundn( 3.141592653589793, 0 ); +* // If n = 0, `roundnf` behaves like `roundf`: +* var v = roundnf( 3.1415927410125732, 0 ); * // returns 3.0 * * @example * // Round a value to the nearest thousand: -* var v = roundn( 12368.0, 3 ); -* // returns 12000.0 +* var v = roundnf( 12368.0, 3 ); +* // returns ~12000.0 */ function roundnf( x, n ) { return addon( x, n ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c index 60f2a113e41a..527e47877285 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c @@ -52,7 +52,7 @@ static const float HUGE_VALUE = 1.0e+38f; * * * -* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) may not be \\(0.3\\) due to the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\\mathrm{roundf}\\). +* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\). * * * @@ -62,7 +62,7 @@ static const float HUGE_VALUE = 1.0e+38f; * * 4. If \\(x > 2^{24}\\), \\(x\\) is **always** an integer (i.e., \\(x\\) has no decimal digits). If \\(n <= 0\\), the rounded value is \\(x\\). * -* 5. If \\(n < -37\\), we let \\(m = n + 38\\) and modify the above formula to avoid overflow. +* 5. If \\(n < -38\\), we let \\(m = n + 38\\) and modify the above formula to avoid overflow. * * ```tex * \\operatorname{roundnf}(x,n) = \\frac{\\biggl(\\frac{\\operatorname{roundf}( (x \\cdot 10^{38}) 10^{-m})}{10^{38}}\\biggr)}{10^{-m}} @@ -88,18 +88,18 @@ static const float HUGE_VALUE = 1.0e+38f; * * @example * // Round a value to 2 decimal places: -* float v = stdlib_base_roundnf( 3.141592f, -2 ); -* // returns 3.14f +* float v = stdlib_base_roundnf( 3.141592653589793f, -2 ); +* // returns ~3.14f * * @example * // If n = 0, `roundnf` behaves like `roundf`: -* float v = stdlib_base_roundnf( 3.141592f, 0 ); +* float v = stdlib_base_roundnf( 3.141592653589793f, 0 ); * // returns 3.0f * * @example -* // Round a value to the nearest hundred: -* float v = stdlib_base_roundnf( 1234.56f, 2 ); -* // returns 1200.0f +* // Round a value to the nearest thousand: +* float v = stdlib_base_roundnf( 12368.0f, 3 ); +* // returns ~12000.0f */ float stdlib_base_roundnf( const float x, const int32_t n ) { float s; From 86697565ef08c8e925a00284ff3fc6f3c55257ec Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 30 Dec 2025 16:13:45 -0800 Subject: [PATCH 13/17] chore: change the order of type casting --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c index 527e47877285..fea07c147143 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c @@ -130,14 +130,14 @@ float stdlib_base_roundnf( const float x, const int32_t n ) { } // If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding... if ( n < STDLIB_CONSTANT_FLOAT32_MIN_BASE10_EXPONENT ) { - s = stdlib_base_powf( 10.0f, (float)-(n + STDLIB_CONSTANT_FLOAT32_MAX_BASE10_EXPONENT) ); + s = stdlib_base_powf( 10.0f, -(float)( n + STDLIB_CONSTANT_FLOAT32_MAX_BASE10_EXPONENT ) ); y = ( x * HUGE_VALUE ) * s; // order of operation matters! if ( stdlib_base_is_infinitef( y ) ) { return x; } return ( stdlib_base_roundf( y ) / HUGE_VALUE ) / s; } - s = stdlib_base_powf( 10.0f, (float)-n ); + s = stdlib_base_powf( 10.0f, -(float)n ); y = x * s; if ( stdlib_base_is_infinitef( y ) ) { return x; From fef58ac49b226ce9f4354e1ded6189539781d853 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Wed, 31 Dec 2025 21:54:42 +0530 Subject: [PATCH 14/17] Fix roundnf: address PR review comments with ulpdiff testing and documentation updates --- .../math/base/special/roundnf/README.md | 48 +-- .../special/roundnf/benchmark/benchmark.js | 13 +- .../roundnf/benchmark/c/native/benchmark.c | 120 +++++-- .../math/base/special/roundnf/docs/repl.txt | 18 +- .../special/roundnf/docs/types/index.d.ts | 26 +- .../base/special/roundnf/examples/index.js | 13 +- .../math/base/special/roundnf/test/test.js | 291 +++++++++++++---- .../base/special/roundnf/test/test.native.js | 295 +++++++++++++++--- 8 files changed, 643 insertions(+), 181 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md index f0fdff6760c5..e71976a4eba5 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md @@ -36,16 +36,16 @@ Rounds a single-precision floating-point number to the nearest multiple of `10^n ```javascript // Round a value to 2 decimal places: -var v = roundnf( 3.141592, -2 ); -// returns 3.140000104904175 +var v = roundnf( 3.1415927410125732, -2 ); +// returns ~3.14 // If n = 0, `roundnf` behaves like `roundf`: -v = roundnf( 3.141592, 0 ); +v = roundnf( 3.1415927410125732, 0 ); // returns 3.0 -// Round a value to the nearest hundred: -v = roundnf( 1234.56, 2 ); -// returns 1200.0 +// Round a value to the nearest thousand: +v = roundnf( 12368.0, 3 ); +// returns ~12000.0 ``` @@ -80,20 +80,20 @@ v = roundnf( 1234.56, 2 ); ```javascript -var uniform = require( '@stdlib/random/array/uniform' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var roundnf = require( '@stdlib/math/base/special/roundnf' ); -var opts = { +var x = uniform( 100, -50.0, 50.0, { 'dtype': 'float32' -}; -var x = uniform( 10, -50.0, 50.0, opts ); -var n = discreteUniform( 10, -5, 0, opts ); +}); -var i; -for ( i = 0; i < x.length; i++ ) { - console.log( 'roundnf(%f, %d) = %f', x[ i ], n[ i ], roundnf( x[ i ], n[ i ] ) ); -} +var n = discreteUniform( 100, -5, 0, { + 'dtype': 'int32' +}); + +logEachMap( 'x: %0.8f. Number of decimals: %d. Rounded: %0.8f', x, n, roundnf ); ``` @@ -131,8 +131,13 @@ for ( i = 0; i < x.length; i++ ) { Rounds a single-precision floating-point number to the nearest multiple of `10^n`. ```c -float out = stdlib_base_roundnf( 3.141592f, -2 ); -// returns 3.14f +// Round a value to 2 decimal places: +float y = stdlib_base_roundnf( 3.14159f, -2 ); +// returns ~3.14f + +// If n = 0, `roundnf` behaves like `roundf`: +y = stdlib_base_roundnf( 3.14159f, 0 ); +// returns 3.0f ``` The function accepts the following arguments: @@ -167,14 +172,13 @@ float stdlib_base_roundnf( const float x, const int32_t n ); #include int main( void ) { - const float x[] = { 3.141592f, -3.141592f, 1234.56f, -1234.56f }; - const int32_t n[] = { -2, -2, 2, 2 }; + const float x[] = { 3.14f, -3.14f, 0.0f, 0.0f/0.0f }; - float v; + float y; int i; for ( i = 0; i < 4; i++ ) { - v = stdlib_base_roundnf( x[ i ], n[ i ] ); - printf( "roundnf(%f, %d) = %f\n", x[ i ], n[ i ], v ); + y = stdlib_base_roundnf( x[ i ], -2 ); + printf( "roundnf(%f, -2) = %f\n", x[ i ], y ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js index d87bf7b7c301..d40b751cccc7 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var roundnf = require( './../lib' ); @@ -36,11 +36,14 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); + n = discreteUniform( 100, -5, 0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 100.0 ) - 50.0; - n = discreteUniform( -5, 0 ); - y = roundnf( x, n ); + y = roundnf( x[ i%x.length ], n[ i%n.length ] ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c index 409ebbd53ee8..0407eea5953e 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c @@ -19,35 +19,111 @@ #include "stdlib/math/base/special/roundnf.h" #include #include +#include #include #include +#define NAME "roundnf" #define ITERATIONS 1000000 +#define REPEATS 3 /** -* Runs benchmarks. +* 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 (inclusive) +* @return random integer +*/ +static int random_discrete_uniform( const int min, const int max ) { + return min + ( rand() % ( max - min + 1 ) ); +} + +/** +* Runs a benchmark. * * @return elapsed time in seconds */ -static double benchmark() { - struct timeval start; - struct timeval end; +static double benchmark( void ) { + float x[ 100 ]; + int n[ 100 ]; double elapsed; - float x; + double t; float y; int i; - gettimeofday( &start, NULL ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -100.0f, 100.0f ); + n[ i ] = random_discrete_uniform( -5, 0 ); + } + + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( ( (float)rand() / (float)RAND_MAX ) * 100.0f ) - 50.0f; - y = stdlib_base_roundnf( x, -2 ); + y = stdlib_base_roundnf( x[ i%100 ], n[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; } } - gettimeofday( &end, NULL ); - elapsed = (double)( end.tv_sec - start.tv_sec ) + ( (double)( end.tv_usec - start.tv_usec ) / 1.0e6 ); + elapsed = tic() - t; if ( y != y ) { printf( "should not return NaN\n" ); } @@ -59,21 +135,17 @@ static double benchmark() { */ int main( void ) { double elapsed; - double rate; int i; - // Warm-up: - for ( i = 0; i < 1000; i++ ) { - stdlib_base_roundnf( (float)i, -2 ); - } - - // Benchmark: - printf( "Benchmark: roundnf\n" ); - elapsed = benchmark(); - rate = (double)ITERATIONS / elapsed; - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %f sec\n", elapsed ); - printf( " rate: %f ops/sec\n", rate ); + // Use the current time to seed the random number generator: + srand( time( NULL ) ); - return 0; + 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/roundnf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt index 7b341334f57c..b72df14fd0ca 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/repl.txt @@ -17,17 +17,17 @@ Examples -------- - // Round to 2 decimal places: - > var y = {{alias}}( 3.141592, -2 ) - 3.140000104904175 + // Round a value to 2 decimal places: + > var y = {{alias}}( 3.1415927410125732, -2 ) + ~3.14 - // Round to nearest integer: - > y = {{alias}}( 3.7, 0 ) - 4.0 + // If n = 0, behaves like roundf: + > y = {{alias}}( 3.1415927410125732, 0 ) + 3.0 - // Round to nearest hundred: - > y = {{alias}}( 1234.56, 2 ) - 1200.0 + // Round a value to the nearest thousand: + > y = {{alias}}( 12368.0, 3 ) + ~12000.0 See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts index b4804942afac..ce26a88ed353 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts @@ -31,19 +31,19 @@ * * @example * // Round a value to 2 decimal places: -* var v = roundnf( 3.141592, -2 ); -* // returns 3.140000104904175 -* -* @example -* // If n = 0, `roundnf` behaves like `roundf`: -* var v = roundnf( 3.141592, 0 ); -* // returns 3.0 -* -* @example -* // Round a value to the nearest hundred: -* var v = roundnf( 1234.56, 2 ); -* // returns 1200.0 -*/ + * var v = roundnf( 3.1415927410125732, -2 ); + * // returns ~3.14 + * + * @example + * // If n = 0, `roundnf` behaves like `roundf`: + * var v = roundnf( 3.1415927410125732, 0 ); + * // returns 3.0 + * + * @example + * // Round a value to the nearest thousand: + * var v = roundnf( 12368.0, 3 ); + * // returns ~12000.0 + */ declare function roundnf( x: number, n: number ): number; diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js index 3b624522d78b..ade954beb276 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js @@ -18,18 +18,15 @@ 'use strict'; -var uniform = require( '@stdlib/random/array/uniform' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var roundnf = require( './../lib' ); var opts = { 'dtype': 'float32' }; -var x = uniform( 10, -50.0, 50.0, opts ); -var n = discreteUniform( 10, -5, 0, opts ); +var x = uniform( 100, -50.0, 50.0, opts ); +var n = discreteUniform( 100, -5, 0, opts ); -var i; -console.log( '' ); -for ( i = 0; i < x.length; i++ ) { - console.log( 'roundnf(%f, %d) = %f', x[ i ], n[ i ], roundnf( x[ i ], n[ i ] ) ); -} +logEachMap( 'x: %0.4f. Number of decimals: %d. Rounded: %0.4f.', x, n, roundnf ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js index d270f71396ee..fb66a5dd9f4d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js @@ -21,13 +21,17 @@ // MODULES // var tape = require( 'tape' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var PI = require( '@stdlib/constants/float32/pi' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' ); 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 PINF = require( '@stdlib/constants/float32/pinf' ); -var NINF = require( '@stdlib/constants/float32/ninf' ); var roundnf = require( './../lib' ); @@ -39,110 +43,279 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns NaN if provided NaN', function test( t ) { - var v = roundnf( NaN, -2 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); - t.end(); -}); +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var v; + + v = roundnf( NaN, -2 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = roundnf( float64ToFloat32( 12368.0 ), NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = roundnf( NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); -tape( 'the function returns NaN if provided n = NaN', function test( t ) { - var v = roundnf( 3.14, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); t.end(); }); -tape( 'the function returns NaN if provided n = +-infinity', function test( t ) { +tape( 'the function returns `NaN` if provided `n = +-infinity`', function test( t ) { var v; - v = roundnf( 3.14, PINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN when n = +infinity' ); + v = roundnf( PI, PINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); - v = roundnf( 3.14, NINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN when n = -infinity' ); + v = roundnf( PI, NINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns +infinity if provided +infinity', function test( t ) { - var v = roundnf( PINF, -2 ); - t.strictEqual( v, PINF, 'returns +infinity' ); +tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { + var v = roundnf( PINF, 5 ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); -tape( 'the function returns -infinity if provided -infinity', function test( t ) { - var v = roundnf( NINF, -2 ); - t.strictEqual( v, NINF, 'returns -infinity' ); +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var v = roundnf( NINF, -3 ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); -tape( 'the function returns +0 if provided +0', function test( t ) { - var v = roundnf( 0.0, -2 ); - t.strictEqual( isPositiveZerof( v ), true, 'returns +0' ); +tape( 'the function returns `-0` if provided `-0`', function test( t ) { + var v; + + v = roundnf( -0.0, 0 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + v = roundnf( -0.0, -2 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + v = roundnf( -0.0, 2 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + t.end(); }); -tape( 'the function returns -0 if provided -0', function test( t ) { - var v = roundnf( -0.0, -2 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); +tape( 'the function returns `+0` if provided `+0`', function test( t ) { + var v; + + v = roundnf( 0.0, 0 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + + v = roundnf( +0.0, -2 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + + v = roundnf( +0.0, 2 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + t.end(); }); -tape( 'the function supports rounding to 2 decimal places', function test( t ) { - t.strictEqual( roundnf( 3.141592, -2 ), float64ToFloat32( 3.14 ), 'returns expected value' ); - t.strictEqual( roundnf( 9.99999, -2 ), float64ToFloat32( 10.0 ), 'returns expected value' ); - t.strictEqual( roundnf( -1.234567, -2 ), float64ToFloat32( -1.23 ), 'returns expected value' ); +tape( 'the function supports rounding a numeric value to a desired number of decimals', function test( t ) { + var expected; + var actual; + var delta; + + actual = roundnf( PI, -2 ); + expected = float64ToFloat32( 3.14 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals 3.14 within float32 precision' ); + + actual = roundnf( -PI, -2 ); + expected = float64ToFloat32( -3.14 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals -3.14 within float32 precision' ); + + actual = roundnf( float64ToFloat32( 9.99999 ), -2 ); + expected = float64ToFloat32( 10.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals 10 within float32 precision' ); + + actual = roundnf( float64ToFloat32( -9.99999 ), -2 ); + expected = float64ToFloat32( -10.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals -10 within float32 precision' ); + + actual = roundnf( 0.0, 2 ); + expected = 0.0; + t.strictEqual( actual, expected, 'equals 0' ); + + actual = roundnf( float64ToFloat32( 12368.0 ), -3 ); + expected = float64ToFloat32( 12368.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals 12368 within float32 precision' ); + + actual = roundnf( float64ToFloat32( -12368.0 ), -3 ); + expected = float64ToFloat32( -12368.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals -12368 within float32 precision' ); + t.end(); }); -tape( 'the function supports rounding to nearest integer (n=0)', function test( t ) { - t.strictEqual( roundnf( 3.7, 0 ), float64ToFloat32( 4.0 ), 'returns expected value' ); - t.strictEqual( roundnf( 3.2, 0 ), float64ToFloat32( 3.0 ), 'returns expected value' ); - t.strictEqual( roundnf( -3.7, 0 ), float64ToFloat32( -4.0 ), 'returns expected value' ); +tape( 'rounding a numeric value to a desired number of decimals can result in unexpected behavior', function test( t ) { + var expected; + var actual; + var delta; + var x; + + x = float64ToFloat32( 0.2 + 0.1 ); // => 0.30000000000000004 as float64, becomes 0.30000001192092896 as float32 + actual = roundnf( x, -16 ); + expected = float64ToFloat32( 0.3000000119209290 ); + delta = ulpdiff( actual, expected ); + t.ok( delta <= 1.0, 'equals 0.3000000119209290 (within 1 ulp) and not exactly 0.3' ); + t.end(); }); -tape( 'the function supports rounding to nearest hundred (n=2)', function test( t ) { - t.strictEqual( roundnf( 1234.56, 2 ), float64ToFloat32( 1200.0 ), 'returns expected value' ); - t.strictEqual( roundnf( 1299.99, 2 ), float64ToFloat32( 1300.0 ), 'returns expected value' ); +tape( 'the function supports rounding a numeric value to a desired number of digits', function test( t ) { + var expected; + var actual; + var delta; + + actual = roundnf( PI, 3 ); + expected = 0.0; + t.strictEqual( actual, expected, 'equals 0' ); + + actual = roundnf( float64ToFloat32( 12368.0 ), 3 ); + expected = float64ToFloat32( 12000.0 ); + delta = ulpdiff( actual, expected ); + t.ok( delta <= 1.0, 'equals 12000 within 1 ulp' ); + + actual = roundnf( float64ToFloat32( 12368.0 ), 1 ); + expected = float64ToFloat32( 12370.0 ); + t.strictEqual( actual, expected, 'equals 12370' ); + + actual = roundnf( -PI, 3 ); + t.strictEqual( isNegativeZerof( actual ), true, 'equals -0' ); + + actual = roundnf( float64ToFloat32( -12368.0 ), 3 ); + expected = float64ToFloat32( -12000.0 ); + delta = ulpdiff( actual, expected ); + t.ok( delta <= 1.0, 'equals -12000 within 1 ulp' ); + + actual = roundnf( float64ToFloat32( -12368.0 ), 1 ); + expected = float64ToFloat32( -12370.0 ); + t.strictEqual( actual, expected, 'equals -12370' ); + t.end(); }); -tape( 'the function supports rounding to nearest thousand (n=3)', function test( t ) { - var expected = float64ToFloat32( 12000.0 ); - var v = roundnf( 12368.0, 3 ); - - // Due to float32 precision, allow small error (< 1.0) - t.ok( abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); +tape( 'the function returns the input value 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()*70.0 ) - 35; // float32 range: ~10^-38 to 10^38 + x = float64ToFloat32( (1.0+randu()) * pow( 10.0, exp ) ); + n = -(round( randu()*50.0 ) + 46); // n < -45 + v = roundnf( x, n ); + t.strictEqual( v, x, 'returns input value when provided x='+x+', n='+n+'.' ); + } t.end(); }); -tape( 'if a value is too large, the function returns the input value', function test( t ) { - var x = float64ToFloat32( 1.0e20 ); - t.strictEqual( roundnf( x, -2 ), x, 'returns input value' ); - t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' ); +tape( 'if `x` is too large a float to have decimals and `n < 0`, the input value is returned', 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()) * pow( 10.0, exp ) ); + n = -( round( randu()*45.0) ); // n in range [0, -45] + v = roundnf( x, n ); + t.strictEqual( x, v, 'returns input value when provided x='+x+', n='+n+'.' ); + } t.end(); }); -tape( 'if `n` exceeds the maximum exponent, the function returns `+-0` (sign preserving)', function test( t ) { +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 ); // float32 range + x = float64ToFloat32( sign * (1.0+randu()) * pow( 10.0, exp ) ); + n = round( randu()*10.0 ) + 39; // n > 38 + v = roundnf( x, n ); + if ( sign === -1.0 ) { + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value when provided x='+x+', n='+n+'.' ); + } else { + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value when provided x='+x+', n='+n+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports rounding very small numbers (including subnormals)', function test( t ) { + var expected; + var actual; + var delta; + var x; + var n; + var i; + + // For float32, subnormal range is roughly 10^-38 to 10^-45 + x = float64ToFloat32( 3.1468234 * pow( 10.0, -38 ) ); - v = roundnf( 3.14, 40 ); - t.strictEqual( isPositiveZerof( v ), true, 'returns +0 when x > 0 and n > MAX_EXP' ); + n = []; + for ( i = -38; i > -45; i-- ) { + n.push( i ); + } - v = roundnf( -3.14, 40 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0 when x < 0 and n > MAX_EXP' ); + expected = [ + float64ToFloat32( 3e-38 ), + float64ToFloat32( 3.1e-38 ), + float64ToFloat32( 3.15e-38 ), + float64ToFloat32( 3.147e-38 ), + float64ToFloat32( 3.1468e-38 ), + float64ToFloat32( 3.14682e-38 ), + float64ToFloat32( 3.146823e-38 ) + ]; + for ( i = 0; i < n.length; i++ ) { + actual = roundnf( x, n[i] ); + if ( i < expected.length ) { + delta = ulpdiff( actual, expected[i] ); + t.ok( delta <= 2.0, 'x: '+x+'. n: '+n[i]+'. v: '+actual+'. expected: '+expected[i]+'. delta: '+delta+' ulps' ); + } else { + // Beyond float32 precision + t.ok( true, 'x: '+x+'. n: '+n[i]+'. v: '+actual ); + } + } t.end(); }); -tape( 'if `n` is less than the minimum subnormal exponent, the function returns the input value', function test( t ) { +tape( 'if the function encounters overflow, the function returns the input value', function test( t ) { + var x; var v; - v = roundnf( 3.14, -50 ); - t.strictEqual( v, float64ToFloat32( 3.14 ), 'returns input value when n < MIN_EXP_SUBNORMAL' ); + x = float64ToFloat32( 3.1468234 ); + v = roundnf( x, -40 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = float64ToFloat32( -3.1468234 ); + v = roundnf( x, -40 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = float64ToFloat32( 16777216.0 ); // 2^24, exact float32 + v = roundnf( x, -30 ); + t.strictEqual( v, x, 'returns the input value' ); - v = roundnf( -2.71, -50 ); - t.strictEqual( v, float64ToFloat32( -2.71 ), 'returns input value when n < MIN_EXP_SUBNORMAL' ); + x = float64ToFloat32( -16777216.0 ); + v = roundnf( x, -30 ); + t.strictEqual( v, x, 'returns the input value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index 934c95e51b3c..0e543b815d01 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -22,14 +22,18 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var PI = require( '@stdlib/constants/float32/pi' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' ); +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 tryRequire = require( '@stdlib/utils/try-require' ); // VARIABLES // @@ -48,68 +52,277 @@ tape( 'main export is a function', opts, function test( t ) { t.end(); }); -tape( 'the function returns NaN if provided NaN', opts, function test( t ) { - var v = roundnf( NaN, -2 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var v; + + v = roundnf( NaN, -2 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = roundnf( float64ToFloat32( 12368.0 ), NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = roundnf( NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `n = +-infinity`', opts, function test( t ) { + var v; + + v = roundnf( PI, PINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = roundnf( PI, NINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { + var v = roundnf( PINF, 5 ); + t.strictEqual( v, PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { + var v = roundnf( NINF, -3 ); + t.strictEqual( v, NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { + var v; + + v = roundnf( -0.0, 0 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + v = roundnf( -0.0, -2 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + v = roundnf( -0.0, 2 ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + t.end(); }); -tape( 'the function returns +infinity if provided +infinity', opts, function test( t ) { - var v = roundnf( PINF, -2 ); - t.strictEqual( v, PINF, 'returns +infinity' ); +tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { + var v; + + v = roundnf( 0.0, 0 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + + v = roundnf( +0.0, -2 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + + v = roundnf( +0.0, 2 ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + t.end(); }); -tape( 'the function returns -infinity if provided -infinity', opts, function test( t ) { - var v = roundnf( NINF, -2 ); - t.strictEqual( v, NINF, 'returns -infinity' ); +tape( 'the function supports rounding a numeric value to a desired number of decimals', opts, function test( t ) { + var expected; + var actual; + var delta; + + actual = roundnf( PI, -2 ); + expected = float64ToFloat32( 3.14 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals 3.14 within float32 precision' ); + + actual = roundnf( -PI, -2 ); + expected = float64ToFloat32( -3.14 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals -3.14 within float32 precision' ); + + actual = roundnf( float64ToFloat32( 9.99999 ), -2 ); + expected = float64ToFloat32( 10.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals 10 within float32 precision' ); + + actual = roundnf( float64ToFloat32( -9.99999 ), -2 ); + expected = float64ToFloat32( -10.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals -10 within float32 precision' ); + + actual = roundnf( 0.0, 2 ); + expected = 0.0; + t.strictEqual( actual, expected, 'equals 0' ); + + actual = roundnf( float64ToFloat32( 12368.0 ), -3 ); + expected = float64ToFloat32( 12368.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals 12368 within float32 precision' ); + + actual = roundnf( float64ToFloat32( -12368.0 ), -3 ); + expected = float64ToFloat32( -12368.0 ); + delta = ulpdiff( actual, expected ); + t.strictEqual( delta, 0.0, 'equals -12368 within float32 precision' ); + t.end(); }); -tape( 'the function returns +0 if provided +0', opts, function test( t ) { - var v = roundnf( 0.0, -2 ); - t.strictEqual( isPositiveZerof( v ), true, 'returns +0' ); +tape( 'rounding a numeric value to a desired number of decimals can result in unexpected behavior', opts, function test( t ) { + var expected; + var actual; + var delta; + var x; + + x = float64ToFloat32( 0.2 + 0.1 ); + actual = roundnf( x, -16 ); + expected = float64ToFloat32( 0.3000000119209290 ); + delta = ulpdiff( actual, expected ); + t.ok( delta <= 1.0, 'equals 0.3000000119209290 (within 1 ulp) and not exactly 0.3' ); + t.end(); }); -tape( 'the function returns -0 if provided -0', opts, function test( t ) { - var v = roundnf( -0.0, -2 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); +tape( 'the function supports rounding a numeric value to a desired number of digits', opts, function test( t ) { + var expected; + var actual; + var delta; + + actual = roundnf( PI, 3 ); + expected = 0.0; + t.strictEqual( actual, expected, 'equals 0' ); + + actual = roundnf( float64ToFloat32( 12368.0 ), 3 ); + expected = float64ToFloat32( 12000.0 ); + delta = ulpdiff( actual, expected ); + t.ok( delta <= 1.0, 'equals 12000 within 1 ulp' ); + + actual = roundnf( float64ToFloat32( 12368.0 ), 1 ); + expected = float64ToFloat32( 12370.0 ); + t.strictEqual( actual, expected, 'equals 12370' ); + + actual = roundnf( -PI, 3 ); + t.strictEqual( isNegativeZerof( actual ), true, 'equals -0' ); + + actual = roundnf( float64ToFloat32( -12368.0 ), 3 ); + expected = float64ToFloat32( -12000.0 ); + delta = ulpdiff( actual, expected ); + t.ok( delta <= 1.0, 'equals -12000 within 1 ulp' ); + + actual = roundnf( float64ToFloat32( -12368.0 ), 1 ); + expected = float64ToFloat32( -12370.0 ); + t.strictEqual( actual, expected, 'equals -12370' ); + t.end(); }); -tape( 'the function supports rounding to 2 decimal places', opts, function test( t ) { - t.strictEqual( roundnf( 3.141592, -2 ), float64ToFloat32( 3.14 ), 'returns expected value' ); - t.strictEqual( roundnf( 9.99999, -2 ), float64ToFloat32( 10.0 ), 'returns expected value' ); - t.strictEqual( roundnf( -1.234567, -2 ), float64ToFloat32( -1.23 ), 'returns expected value' ); +tape( 'the function returns the input value if provided an `n` which is less than the minimum decimal exponential (-45 for float32)', opts, function test( t ) { + var exp; + var n; + var x; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*70.0 ) - 35; + x = float64ToFloat32( (1.0+randu()) * pow( 10.0, exp ) ); + n = -(round( randu()*50.0 ) + 46); + v = roundnf( x, n ); + t.strictEqual( v, x, 'returns input value when provided x='+x+', n='+n+'.' ); + } t.end(); }); -tape( 'the function supports rounding to nearest integer (n=0)', opts, function test( t ) { - t.strictEqual( roundnf( 3.7, 0 ), float64ToFloat32( 4.0 ), 'returns expected value' ); - t.strictEqual( roundnf( 3.2, 0 ), float64ToFloat32( 3.0 ), 'returns expected value' ); - t.strictEqual( roundnf( -3.7, 0 ), float64ToFloat32( -4.0 ), 'returns expected value' ); +tape( 'if `x` is too large a float to have decimals and `n < 0`, the input value is returned', opts, 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 ); + x = float64ToFloat32( sign * (1.0+randu()) * pow( 10.0, exp ) ); + n = -( round( randu()*45.0) ); + v = roundnf( x, n ); + t.strictEqual( x, v, 'returns input value when provided x='+x+', n='+n+'.' ); + } t.end(); }); -tape( 'the function supports rounding to nearest hundred (n=2)', opts, function test( t ) { - t.strictEqual( roundnf( 1234.56, 2 ), float64ToFloat32( 1200.0 ), 'returns expected value' ); - t.strictEqual( roundnf( 1299.99, 2 ), float64ToFloat32( 1300.0 ), 'returns expected value' ); +tape( 'if `n > 38` (exceeds float32 max exponent), the function returns `+-0` (sign preserving)', opts, 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()) * pow( 10.0, exp ) ); + n = round( randu()*10.0 ) + 39; + v = roundnf( x, n ); + if ( sign === -1.0 ) { + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value when provided x='+x+', n='+n+'.' ); + } else { + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value when provided x='+x+', n='+n+'.' ); + } + } t.end(); }); -tape( 'the function supports rounding to nearest thousand (n=3)', opts, function test( t ) { - var expected = float64ToFloat32( 12000.0 ); - var v = roundnf( 12368.0, 3 ); +tape( 'the function supports rounding very small numbers (including subnormals)', opts, function test( t ) { + var expected; + var actual; + var delta; + var x; + var n; + var i; + + x = float64ToFloat32( 3.1468234 * pow( 10.0, -38 ) ); - // Due to float32 precision, allow small error (< 1.0) - t.ok( abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' ); + n = []; + for ( i = -38; i > -45; i-- ) { + n.push( i ); + } + + expected = [ + float64ToFloat32( 3e-38 ), + float64ToFloat32( 3.1e-38 ), + float64ToFloat32( 3.15e-38 ), + float64ToFloat32( 3.147e-38 ), + float64ToFloat32( 3.1468e-38 ), + float64ToFloat32( 3.14682e-38 ), + float64ToFloat32( 3.146823e-38 ) + ]; + + for ( i = 0; i < n.length; i++ ) { + actual = roundnf( x, n[i] ); + if ( i < expected.length ) { + delta = ulpdiff( actual, expected[i] ); + t.ok( delta <= 2.0, 'x: '+x+'. n: '+n[i]+'. v: '+actual+'. expected: '+expected[i]+'. delta: '+delta+' ulps' ); + } else { + t.ok( true, 'x: '+x+'. n: '+n[i]+'. v: '+actual ); + } + } t.end(); }); -tape( 'if a value is too large, the function returns the input value', opts, function test( t ) { - var x = float64ToFloat32( 1.0e20 ); - t.strictEqual( roundnf( x, -2 ), x, 'returns input value' ); - t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' ); +tape( 'if the function encounters overflow, the function returns the input value', opts, function test( t ) { + var x; + var v; + + x = float64ToFloat32( 3.1468234 ); + v = roundnf( x, -40 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = float64ToFloat32( -3.1468234 ); + v = roundnf( x, -40 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = float64ToFloat32( 16777216.0 ); + v = roundnf( x, -30 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = float64ToFloat32( -16777216.0 ); + v = roundnf( x, -30 ); + t.strictEqual( v, x, 'returns the input value' ); + t.end(); }); From c3318fb4462323bee9d2446309230d2bdd096837 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Wed, 31 Dec 2025 22:14:24 +0530 Subject: [PATCH 15/17] Fix roundnf native tests: remove NaN/Infinity tests for n parameter --- .../base/special/roundnf/test/test.native.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index 0e543b815d01..dec8ef47f429 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -58,22 +58,7 @@ tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { v = roundnf( NaN, -2 ); t.strictEqual( isnanf( v ), true, 'returns expected value' ); - v = roundnf( float64ToFloat32( 12368.0 ), NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - v = roundnf( NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns `NaN` if provided `n = +-infinity`', opts, function test( t ) { - var v; - - v = roundnf( PI, PINF ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - v = roundnf( PI, NINF ); + v = roundnf( NaN, 0 ); t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); From 838432c58e0b76f333665a83dc58c2a75a464e1d Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Wed, 7 Jan 2026 11:16:58 +0530 Subject: [PATCH 16/17] docs: match C example with README section --- .../math/base/special/roundnf/examples/c/example.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c index 4cad9f443857..837f2590eeb3 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c @@ -20,14 +20,12 @@ #include int main( void ) { - const float x[] = { 3.141592f, -3.141592f, 1234.56f, -1234.56f, 9.99999f, -9.99999f, 0.0f, -0.0f }; - const int32_t n[] = { -2, -2, 2, 2, -2, -2, -2, -2 }; + const float x[] = { 3.14f, -3.14f, 0.0f, 0.0f/0.0f }; - float v; + float y; int i; - for ( i = 0; i < 8; i++ ) { - v = stdlib_base_roundnf( x[ i ], n[ i ] ); - printf( "roundnf(%f, %d) = %f\n", x[ i ], n[ i ], v ); + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_roundnf( x[ i ], -2 ); + printf( "roundnf(%f, -2) = %f\n", x[ i ], y ); } - return 0; } From 2e3ddcd78f902a49103d20cb2e350cbc17b9d558 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 7 Jan 2026 06:09:45 +0000 Subject: [PATCH 17/17] chore: update copyright years --- lib/node_modules/@stdlib/math/base/special/roundnf/README.md | 2 +- .../@stdlib/math/base/special/roundnf/benchmark/benchmark.js | 2 +- .../math/base/special/roundnf/benchmark/benchmark.native.js | 2 +- .../math/base/special/roundnf/benchmark/c/native/Makefile | 2 +- .../math/base/special/roundnf/benchmark/c/native/benchmark.c | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp | 2 +- .../@stdlib/math/base/special/roundnf/docs/types/index.d.ts | 2 +- .../@stdlib/math/base/special/roundnf/docs/types/test.ts | 2 +- .../@stdlib/math/base/special/roundnf/examples/c/Makefile | 2 +- .../@stdlib/math/base/special/roundnf/examples/c/example.c | 2 +- .../@stdlib/math/base/special/roundnf/examples/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi | 2 +- .../special/roundnf/include/stdlib/math/base/special/roundnf.h | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js | 2 +- .../@stdlib/math/base/special/roundnf/lib/native.js | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c | 2 +- lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js | 2 +- .../@stdlib/math/base/special/roundnf/test/test.native.js | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md index e71976a4eba5..bc35f1523ef5 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js index d40b751cccc7..207e6d1d8ab0 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js index 496076e510b4..4d10aa3ee197 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile index 46054174e863..467f315ff0c6 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c index 0407eea5953e..04e65c6225bd 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp index 68a1ca11d160..0d6508a12e99 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts index ce26a88ed353..ef3ee30b40ab 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/index.d.ts @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts index bf4ae28fbcf6..05f8c69c404b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile index a1a969527e06..1c56c25a4e98 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c index 837f2590eeb3..7adc8a074902 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js index ade954beb276..f106fc4ca071 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi b/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi index ecfaf82a3279..bee8d41a2caf 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/include/stdlib/math/base/special/roundnf.h b/lib/node_modules/@stdlib/math/base/special/roundnf/include/stdlib/math/base/special/roundnf.h index 35e9b7bbd83e..5248bc16a38d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/include/stdlib/math/base/special/roundnf.h +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/include/stdlib/math/base/special/roundnf.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js index 984177012437..0d081489b5ad 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js index d7486373f0ca..74e7e9b8b55d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js index 390be6912b27..04f057eb897d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile index 2c12db3307b8..9d6db97e941c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c index 8e0e789c91c9..75903fd01b03 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c index fea07c147143..36c40d5bc3f3 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js index fb66a5dd9f4d..dc8236cf2d92 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js index dec8ef47f429..b9e6d40072d7 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundnf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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.