From 5983a13496a9a1c9addb52283298bbfce9822b39 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Fri, 23 Jan 2026 20:41:08 +0000 Subject: [PATCH 01/28] feat: add math/base/special/roundsdf --- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/roundsdf/README.md | 208 ++++++++++++++++++ .../special/roundsdf/benchmark/benchmark.js | 88 ++++++++ .../roundsdf/benchmark/benchmark.native.js | 97 ++++++++ .../roundsdf/benchmark/c/native/Makefile | 146 ++++++++++++ .../roundsdf/benchmark/c/native/benchmark.c | 100 +++++++++ .../math/base/special/roundsdf/binding.gyp | 170 ++++++++++++++ .../math/base/special/roundsdf/docs/repl.txt | 41 ++++ .../special/roundsdf/docs/types/index.d.ts | 51 +++++ .../base/special/roundsdf/docs/types/test.ts | 61 +++++ .../base/special/roundsdf/examples/c/Makefile | 146 ++++++++++++ .../special/roundsdf/examples/c/example.c | 39 ++++ .../base/special/roundsdf/examples/index.js | 33 +++ .../math/base/special/roundsdf/include.gypi | 53 +++++ .../stdlib/math/base/special/roundsdf.h | 43 ++++ .../math/base/special/roundsdf/lib/index.js | 56 +++++ .../math/base/special/roundsdf/lib/main.js | 79 +++++++ .../math/base/special/roundsdf/lib/native.js | 48 ++++ .../math/base/special/roundsdf/manifest.json | 97 ++++++++ .../math/base/special/roundsdf/package.json | 82 +++++++ .../math/base/special/roundsdf/src/Makefile | 70 ++++++ .../math/base/special/roundsdf/src/addon.c | 26 +++ .../math/base/special/roundsdf/src/main.c | 56 +++++ .../math/base/special/roundsdf/test/test.js | 90 ++++++++ .../base/special/roundsdf/test/test.native.js | 84 +++++++ 24 files changed, 1964 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md new file mode 100644 index 000000000000..26d09fed5654 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md @@ -0,0 +1,208 @@ + + +# roundsdf + +> Round a single-precision floating-point number to the nearest value with `n` significant figures. + +
+ +## Usage + +```javascript +var roundsdf = require( '@stdlib/math/base/special/roundsdf' ); +``` + +#### roundsdf( x, n ) + +Rounds a single-precision floating-point number to the nearest value with `n` significant figures. + +```javascript +var v = roundsdf( 3.141592653589793, 3 ); +// returns 3.14 + +v = roundsdf( 3.141592653589793, 1 ); +// returns 3.0 + +v = roundsdf( 12368.0, 2 ); +// returns 12000.0 + +v = roundsdf( -12368.0, 2 ); +// returns -12000.0 +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var roundsdf = require( '@stdlib/math/base/special/roundsdf' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = uniform( 100, -5000.0, 5000.0, opts ); + +logEachMap( 'x: %0.4f. n: 3. rounded: %0.4f.', x, 3, roundsdf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/roundsdf.h" +``` + +#### stdlib_base_roundsdf( x, n ) + +Rounds a single-precision floating-point number to the nearest value with `n` significant figures + +```c +float v = stdlib_base_roundsdf( 3.1415927f, 3 ); +// returns 3.14f +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **n**: `[in] int32_t` number of significant figures. + +```c +float stdlib_base_roundsdf( float x, int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/roundsdf.h" +#include +#include + +int main( void ) { + const float x[] = { 3.143546f, -3.142635f, 0.0f, NAN }; + + float y; + int i; + + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_roundsdf( x[ i ], 2 ); + printf( "roundsdf(%f) = %f\n", x[ i ], y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js new file mode 100644 index 000000000000..290171e86075 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var roundsdf = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::n=1', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 10000.0 ) - 5000.0; + y = roundsdf( x, 1 ); + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::n=3', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 10000.0 ) - 5000.0; + y = roundsdf( x, 3 ); + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::n=5', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 10000.0 ) - 5000.0; + y = roundsdf( x, 5 ); + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..12058d460d11 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var roundsdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( roundsdf instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native:n=1', pkg ), opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 10000.0 ) - 5000.0; + y = roundsdf( x, 1 ); + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::native:n=3', pkg ), opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 10000.0 ) - 5000.0; + y = roundsdf( x, 3 ); + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::native:n=5', pkg ), opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 10000.0 ) - 5000.0; + y = roundsdf( x, 5 ); + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/Makefile @@ -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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..d97f16df1b35 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/roundsdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include +#include +#include + +#define NAME "roundsdf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Returns a wall-clock time in seconds. +* +* @return time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec * 1.0e-6; +} + +/** +* Generates a pseudo-random float on the interval [-5000, 5000). +* +* @return random float +*/ +static float rand_float( void ) { + return ( (float)rand() / (float)RAND_MAX ) * 10000.0f - 5000.0f; +} + +/** +* Runs the benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float x; + float y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = rand_float(); + y = stdlib_base_roundsdf( x, 5, 10 ); + if ( stdlib_base_is_nan( y ) ) { + printf( "unexpected NaN\n" ); + break; + } + } + return tic() - t; +} + +/** +* Main execution sequence. +* +* @return exit status +*/ +int main( void ) { + double elapsed; + int i; + + printf( "TAP version 13\n" ); + + for ( i = 0; i < REPEATS; i++ ) { + elapsed = benchmark(); + printf( "# %s\n", NAME ); + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", (double)ITERATIONS / elapsed ); + printf( " ...\n" ); + printf( "ok %d benchmark finished\n", i+1 ); + } + + printf( "1..%d\n", REPEATS ); + printf( "# total %d\n", REPEATS ); + printf( "# pass %d\n", REPEATS ); + printf( "# ok\n" ); + + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/roundsdf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt new file mode 100644 index 000000000000..602d99362a34 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt @@ -0,0 +1,41 @@ + +{{alias}}( x, n[, b] ) + Rounds a numeric value to the nearest number toward positive infinity with + `n` significant figures. + + Parameters + ---------- + x: number + Input value. + + n: integer + Number of significant figures. Must be greater than 0. + + b: integer (optional) + Base. Must be greater than 0. Default: 10. + + Returns + ------- + y: number + Rounded value. + + Examples + -------- + > var y = {{alias}}( 3.141592653589793, 3 ) + 3.14 + + > y = {{alias}}( 3.141592653589793, 1 ) + 3 + + > y = {{alias}}( 12368.0, 2 ) + 12000 + + > y = {{alias}}( -12368.0, 2 ) + -12000 + + > y = {{alias}}( 0.0313, 2, 2 ) + 0.031 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts new file mode 100644 index 000000000000..84a0553a816c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts @@ -0,0 +1,51 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 numeric value to the nearest number toward positive infinity with +* `n` significant figures. +* +* @param x - input value +* @param n - number of significant figures +* @param b - base (default: 10) +* @returns rounded value +* +* @example +* var v = roundsdf( 3.141592653589793, 3 ); +* // returns 3.14 +* +* @example +* var v = roundsdf( 3.141592653589793, 1 ); +* // returns 3 +* +* @example +* var v = roundsdf( 12368.0, 2 ); +* // returns 12000 +* +* @example +* var v = roundsdf( 0.0313, 2, 2 ); +* // returns 0.031 +*/ +declare function roundsdf( x: number, n: number, b?: number ): number; + + +// EXPORTS // + +export = roundsdf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts new file mode 100644 index 000000000000..3412d27b0c46 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 roundsdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + roundsdf( 3.141592653589793, 4 ); // $ExpectType number + roundsdf( 3.141592653589793, 1 ); // $ExpectType number + roundsdf( 12368.0, 2 ); // $ExpectType number + roundsdf( 0.0313, 2, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than numbers... +{ + roundsdf( true, 3 ); // $ExpectError + roundsdf( false, 2 ); // $ExpectError + roundsdf( '5', 1 ); // $ExpectError + roundsdf( [], 1 ); // $ExpectError + roundsdf( {}, 2 ); // $ExpectError + roundsdf( ( x: number ): number => x, 2 ); // $ExpectError + + roundsdf( 9, true ); // $ExpectError + roundsdf( 9, false ); // $ExpectError + roundsdf( 5, '5' ); // $ExpectError + roundsdf( 8, [] ); // $ExpectError + roundsdf( 9, {} ); // $ExpectError + roundsdf( 8, ( x: number ): number => x ); // $ExpectError + + roundsdf( 3.14, 2, true ); // $ExpectError + roundsdf( 3.14, 2, false ); // $ExpectError + roundsdf( 3.14, 2, '5' ); // $ExpectError + roundsdf( 3.14, 2, [] ); // $ExpectError + roundsdf( 3.14, 2, {} ); // $ExpectError + roundsdf( 3.14, 2, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + roundsdf(); // $ExpectError + roundsdf( 3 ); // $ExpectError + roundsdf( 2.131, 3, 10, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/Makefile @@ -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. +#/ + +# 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 := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c new file mode 100644 index 000000000000..828f4610fd21 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/roundsdf.h" +#include +#include + +int main( void ) { + const float x[] = { + 3.143546f, + -3.142635f, + 0.0f, + NAN + }; + + float y; + int i; + + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_roundsdf( x[ i ], 2, 10 ); + printf( "roundsdf(%f, 2, 10) = %f\n", x[ i ], y ); + } + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js new file mode 100644 index 000000000000..629171bb08ee --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 logEachMap = require( '@stdlib/console/log-each-map' ); +var roundsdf = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +// Generate random values: +var x = uniform( 100, -5000.0, 5000.0, opts ); + +// Apply rounding: +logEachMap('x: %0.4f. n: 5. rounded: %0.4f.', x, 5, roundsdf); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/include.gypi b/lib/node_modules/@stdlib/math/base/special/roundsdf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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': [ + ' + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Rounds a single-precision floating-point number to the nearest value toward +* positive infinity with `n` significant figures. +* +* @param x input value +* @param n number of significant figures +* @param b base +* @return rounded value +*/ +float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_ROUNDSDF_H diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js new file mode 100644 index 000000000000..1d7dc1720119 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 numeric value to the nearest number toward positive infinity with n significant figures. +* +* @module @stdlib/math/base/special/roundsdf +* +* @example +* var roundsdf = require( '@stdlib/math/base/special/roundsdf' ); +* +* var v = roundsdf( 3.141592653589793, 3 ); +* // returns 3.14 +* +* v = roundsdf( 3.141592653589793, 1 ); +* // returns 3 +* +* v = roundsdf( 12368.0, 2 ); +* // returns 12000 +* +* v = roundsdf( 0.0313, 2, 2 ); +* // returns 0.031 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var native = require( './native.js' ); + + +// MAIN // + +setReadOnly( main, 'native', native ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js new file mode 100644 index 000000000000..931a4330b7f9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var log10 = require( '@stdlib/math/base/special/log10' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var round = require( '@stdlib/math/base/special/round' ); + + +// MAIN // + +/** +* Rounds a numeric value to the nearest number with `n` significant figures. +* +* @param {number} x - input value +* @param {PositiveInteger} n - number of significant figures +* @returns {number} rounded value +* +* @example +* var v = roundsdf( 3.141592653589793, 3 ); +* // returns 3.14 +* +* @example +* var v = roundsdf( 3.141592653589793, 1 ); +* // returns 3.0 +* +* @example +* var v = roundsdf( 12368.0, 2 ); +* // returns 12000.0 +*/ +function roundsdf( x, n ) { + var e; + var s; + + if ( isnan( x ) || isnan( n ) || n < 1 || isInfinite( n ) ) { + return NaN; + } + if ( isInfinite( x ) || x === 0.0 ) { + return x; + } + + // Base-10 exponent: + e = floor( log10( abs( x ) ) - n + 1.0 ); + + // Scale factor: + s = pow( 10.0, abs( e ) ); + + if ( e < 0 ) { + return round( x * s ) / s; + } + return round( x / s ) * s; +} + + +// EXPORTS // + +module.exports = roundsdf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js new file mode 100644 index 000000000000..1fcf93de9aed --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var addon = tryRequire( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds a numeric value to the nearest number with `n` significant figures. +* +* @private +* @param {number} x - input value +* @param {PositiveInteger} n - number of significant figures +* @returns {number} rounded value +*/ +function roundsdf( x, n ) { + return addon( x, n ); +} + + +// EXPORTS // + +module.exports = roundsdf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json new file mode 100644 index 000000000000..bfdb8ec1664c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json @@ -0,0 +1,97 @@ +{ + "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", + "./src/addon.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/ternary", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/ceilf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/logf", + "@stdlib/math/base/special/powf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/ceilf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/logf", + "@stdlib/math/base/special/powf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/ceilf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/logf", + "@stdlib/math/base/special/powf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json new file mode 100644 index 000000000000..9931b6af04fc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json @@ -0,0 +1,82 @@ +{ + "name": "@stdlib/math/base/special/roundsdf", + "version": "0.0.0", + "description": "Round a single-precision floating-point number to the nearest number toward positive infinity with N significant figures.", + "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": { + "@stdlib/utils/define-nonenumerable-read-only-property": "^0.0.0", + "@stdlib/math/base/assert/is-nan": "^0.0.0", + "@stdlib/math/base/assert/is-infinite": "^0.0.0", + "@stdlib/math/base/special/pow": "^0.0.0", + "@stdlib/math/base/special/abs": "^0.0.0", + "@stdlib/math/base/special/floor": "^0.0.0", + "@stdlib/math/base/special/ceil": "^0.0.0", + "@stdlib/math/base/special/log": "^0.0.0" + }, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "math.round", + "round", + "significant", + "figures", + "sigfig", + "sigfigs", + "digits", + "measurement", + "science", + "nearest", + "number", + "float32", + "ceil" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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 + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c new file mode 100644 index 000000000000..a2277d9801eb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c @@ -0,0 +1,26 @@ +/** +* @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/roundsdf.h" +#include "stdlib/math/base/napi/ternary.h" + +/* +* Create a Node-API module for a ternary function accepting +* a float and two integers and returning a float. +*/ +STDLIB_MATH_BASE_NAPI_MODULE_FII_F( stdlib_base_roundsdf ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c new file mode 100644 index 000000000000..785e06aa2af6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/roundsdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/assert/is_infinite.h" +#include +#include + +/** +* Rounds a single-precision floating-point number to the nearest value with `n` +* significant figures. +* +* @param x input value +* @param n number of significant figures +* @return rounded value +*/ +float stdlib_base_roundsdf( const float x, const int32_t n ) { + float ax; + float e; + float s; + + if ( stdlib_base_is_nan( x ) || n < 1 ) { + return 0.0f / 0.0f; // NaN + } + if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { + return x; + } + + // Absolute value: + ax = stdlib_base_absf( x ); + + // Base-10 exponent: + e = stdlib_base_floorf( stdlib_base_log10f( ax ) ); + + // Scale factor: + s = stdlib_base_powf( 10.0f, (float)( n - 1 ) - e ); + + // Round to nearest: + return stdlib_base_roundf( x * s ) / s; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js new file mode 100644 index 000000000000..bb27504e3d1a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var roundsdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof roundsdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns NaN if provided NaN', function test( t ) { + t.ok( isnan( roundsdf( NaN, 2 ) ), 'NaN x' ); + t.ok( isnan( roundsdf( 3.14, NaN ) ), 'NaN n' ); + t.ok( isnan( roundsdf( NaN, NaN ) ), 'NaN x and n' ); + t.end(); +}); + +tape( 'the function returns NaN if provided n < 1', function test( t ) { + t.ok( isnan( roundsdf( 3.14, 0 ) ), 'n = 0' ); + t.ok( isnan( roundsdf( 3.14, -1 ) ), 'n < 0' ); + t.end(); +}); + +tape( 'the function returns infinity unchanged', function test( t ) { + t.strictEqual( roundsdf( PINF, 3 ), PINF, '+infinity' ); + t.strictEqual( roundsdf( NINF, 3 ), NINF, '-infinity' ); + t.end(); +}); + +tape( 'the function preserves signed zeros', function test( t ) { + t.ok( isPositiveZero( roundsdf( 0.0, 2 ) ), '+0 preserved' ); + t.ok( isNegativeZero( roundsdf( -0.0, 2 ) ), '-0 preserved' ); + t.end(); +}); + +tape( 'the function rounds to nearest with n significant figures', function test( t ) { + t.strictEqual( roundsdf( 3.141592653589793, 1 ), 3.0, 'n=1' ); + t.strictEqual( roundsdf( 3.141592653589793, 2 ), 3.1, 'n=2' ); + t.strictEqual( roundsdf( 3.141592653589793, 3 ), 3.14, 'n=3' ); + t.strictEqual( roundsdf( 3.141592653589793, 4 ), 3.142, 'n=4' ); + t.end(); +}); + +tape( 'the function rounds large values correctly', function test( t ) { + t.strictEqual( roundsdf( 12368.0, 1 ), 10000.0, 'n=1' ); + t.strictEqual( roundsdf( 12368.0, 2 ), 12000.0, 'n=2' ); + t.strictEqual( roundsdf( 12368.0, 3 ), 12400.0, 'n=3' ); + t.end(); +}); + +tape( 'the function rounds negative values correctly', function test( t ) { + t.strictEqual( roundsdf( -3.141592653589793, 1 ), -3.0, 'n=1' ); + t.strictEqual( roundsdf( -3.141592653589793, 3 ), -3.14, 'n=3' ); + t.strictEqual( roundsdf( -12368.0, 2 ), -12000.0, 'n=2' ); + t.end(); +}); + +tape( 'the main export has a native method', function test( t ) { + t.strictEqual( typeof roundsdf.native, 'function', 'has native method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js new file mode 100644 index 000000000000..5b97089f5030 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var roundsdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( roundsdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof roundsdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'returns NaN for NaN inputs', opts, function test( t ) { + t.ok( isnan( roundsdf( NaN, 2 ) ), 'NaN input' ); + t.ok( isnan( roundsdf( 3.14, NaN ) ), 'NaN n' ); + t.end(); +}); + +tape( 'returns NaN for n < 1', opts, function test( t ) { + t.ok( isnan( roundsdf( 3.14, 0 ) ), 'n = 0' ); + t.ok( isnan( roundsdf( 3.14, -1 ) ), 'n < 0' ); + t.end(); +}); + +tape( 'returns infinities unchanged', opts, function test( t ) { + t.strictEqual( roundsdf( PINF, 3 ), PINF, '+infinity' ); + t.strictEqual( roundsdf( NINF, 3 ), NINF, '-infinity' ); + t.end(); +}); + +tape( 'preserves signed zero', opts, function test( t ) { + t.ok( isPositiveZero( roundsdf( 0.0, 2 ) ), '+0 preserved' ); + t.ok( isNegativeZero( roundsdf( -0.0, 2 ) ), '-0 preserved' ); + t.end(); +}); + +tape( 'rounds to nearest with n significant figures', opts, function test( t ) { + t.strictEqual( roundsdf( 3.141592653589793, 1 ), 3.0, 'n=1' ); + t.strictEqual( roundsdf( 3.141592653589793, 2 ), 3.1, 'n=2' ); + t.strictEqual( roundsdf( 3.141592653589793, 3 ), 3.14, 'n=3' ); + t.end(); +}); + +tape( 'rounds large and negative values correctly', opts, function test( t ) { + t.strictEqual( roundsdf( 12368.0, 1 ), 10000.0, 'large positive' ); + t.strictEqual( roundsdf( -12368.0, 2 ), -12000.0, 'large negative' ); + t.end(); +}); From 1f81a6e3c2773d0b2d6cad433c2d486c74f45361 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Fri, 23 Jan 2026 20:51:00 +0000 Subject: [PATCH 02/28] chore: update copyright years --- lib/node_modules/@stdlib/math/base/special/roundsdf/README.md | 2 +- .../@stdlib/math/base/special/roundsdf/benchmark/benchmark.js | 2 +- .../math/base/special/roundsdf/benchmark/benchmark.native.js | 2 +- .../math/base/special/roundsdf/benchmark/c/native/Makefile | 2 +- .../math/base/special/roundsdf/benchmark/c/native/benchmark.c | 2 +- lib/node_modules/@stdlib/math/base/special/roundsdf/binding.gyp | 2 +- .../@stdlib/math/base/special/roundsdf/docs/types/index.d.ts | 2 +- .../@stdlib/math/base/special/roundsdf/docs/types/test.ts | 2 +- .../@stdlib/math/base/special/roundsdf/examples/c/Makefile | 2 +- .../@stdlib/math/base/special/roundsdf/examples/c/example.c | 2 +- .../@stdlib/math/base/special/roundsdf/examples/index.js | 2 +- .../@stdlib/math/base/special/roundsdf/include.gypi | 2 +- .../roundsdf/include/stdlib/math/base/special/roundsdf.h | 2 +- .../@stdlib/math/base/special/roundsdf/lib/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js | 2 +- .../@stdlib/math/base/special/roundsdf/lib/native.js | 2 +- .../@stdlib/math/base/special/roundsdf/src/Makefile | 2 +- lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c | 2 +- lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c | 2 +- .../@stdlib/math/base/special/roundsdf/test/test.js | 2 +- .../@stdlib/math/base/special/roundsdf/test/test.native.js | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md index 26d09fed5654..56fe0cc47111 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 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/roundsdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js index 290171e86075..f86ed04432ae 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js index 12058d460d11..c7635d84bac9 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/Makefile index a4bd7b38fd74..979768abbcec 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c index d97f16df1b35..3c623c581b54 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/roundsdf/binding.gyp index 68a1ca11d160..0d6508a12e99 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/binding.gyp +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts index 84a0553a816c..8b1d1ec67df0 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts index 3412d27b0c46..efe3bb95cf0f 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 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/roundsdf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/Makefile index 25ced822f96a..c8f8e9a1517b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c index 828f4610fd21..5484f4d090bb 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js index 629171bb08ee..3f2f7d0063a8 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/include.gypi b/lib/node_modules/@stdlib/math/base/special/roundsdf/include.gypi index ecfaf82a3279..bee8d41a2caf 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/include.gypi +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/include/stdlib/math/base/special/roundsdf.h b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h index 056a066ed734..32a71f5e3683 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js index 1d7dc1720119..c5560491c335 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js index 931a4330b7f9..270425bb4b40 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index 1fcf93de9aed..c3d1a2550de9 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/Makefile index 7733b6180cb4..2caf905cedbe 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c index a2277d9801eb..032c86de03b2 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/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/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 785e06aa2af6..f6ce9b04b629 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js index bb27504e3d1a..42022a1d45fa 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js index 5b97089f5030..8c246213c4ac 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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. From c41e40ca5c5c2503bc70da8c0a5b3459f3fe2d33 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Fri, 23 Jan 2026 21:02:37 +0000 Subject: [PATCH 03/28] feat: add math/base/special/roundsdf --- 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: missing_dependencies - 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 --- --- .../include/stdlib/math/base/special/roundsdf.h | 8 +------- .../@stdlib/math/base/special/roundsdf/src/main.c | 10 +++++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h index 32a71f5e3683..a7a24506c9ce 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h @@ -26,13 +26,7 @@ extern "C" { #endif /** -* Rounds a single-precision floating-point number to the nearest value toward -* positive infinity with `n` significant figures. -* -* @param x input value -* @param n number of significant figures -* @param b base -* @return rounded value +* Rounds a single-precision floating-point number to the nearest value toward positive infinity with `n` significant figures. */ float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index f6ce9b04b629..73b375142c67 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -17,9 +17,13 @@ */ #include "stdlib/math/base/special/roundsdf.h" -#include "stdlib/math/base/assert/is_nan.h" -#include "stdlib/math/base/assert/is_infinite.h" -#include +#include "stdlib/math/base/assert/is-nan.h" +#include "stdlib/math/base/assert/is-infinite.h" +#include "stdlib/math/base/special/absf.h" +#include "stdlib/math/base/special/floorf.h" +#include "stdlib/math/base/special/log10f.h" +#include "stdlib/math/base/special/powf.h" +#include "stdlib/math/base/special/roundf.h" #include /** From aed0b169868ccb09965a92545175326d750b8672 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 06:34:07 +0000 Subject: [PATCH 04/28] fix: correct C assert header names for roundsdf --- 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: missing_dependencies - 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 --- --- .../@stdlib/math/base/special/roundsdf/manifest.json | 12 ++++++------ .../@stdlib/math/base/special/roundsdf/src/main.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json index bfdb8ec1664c..278fe1ceded3 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json @@ -40,8 +40,8 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/ternary", - "@stdlib/math/base/assert/is-infinite", - "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is_infinite", + "@stdlib/math/base/assert/is_nan", "@stdlib/math/base/special/absf", "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", @@ -62,8 +62,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-infinite", - "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is_infinite", + "@stdlib/math/base/assert/is_nan", "@stdlib/math/base/special/absf", "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", @@ -84,8 +84,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-infinite", - "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is_infinite", + "@stdlib/math/base/assert/is_nan", "@stdlib/math/base/special/absf", "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 73b375142c67..9dbffd1271bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -17,8 +17,8 @@ */ #include "stdlib/math/base/special/roundsdf.h" -#include "stdlib/math/base/assert/is-nan.h" -#include "stdlib/math/base/assert/is-infinite.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/assert/is_infinite.h" #include "stdlib/math/base/special/absf.h" #include "stdlib/math/base/special/floorf.h" #include "stdlib/math/base/special/log10f.h" From 3222e8dc32d847bd7cdadab650b66168b0c02e8c Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 06:42:21 +0000 Subject: [PATCH 05/28] fix: resolve C dependencies and example build for roundsdf --- 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: na - task: lint_c_examples status: missing_dependencies - 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/roundsdf/examples/c/example.c | 2 +- .../@stdlib/math/base/special/roundsdf/manifest.json | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c index 5484f4d090bb..4c2780b7dd4d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c @@ -1,4 +1,4 @@ -/** +/* * @license Apache-2.0 * * Copyright (c) 2026 The Stdlib Authors. diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json index 278fe1ceded3..bfdb8ec1664c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json @@ -40,8 +40,8 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/ternary", - "@stdlib/math/base/assert/is_infinite", - "@stdlib/math/base/assert/is_nan", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/absf", "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", @@ -62,8 +62,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is_infinite", - "@stdlib/math/base/assert/is_nan", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/absf", "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", @@ -84,8 +84,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is_infinite", - "@stdlib/math/base/assert/is_nan", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/absf", "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", From 2251bd56c1034dd7817c199e9256e88b819c53b3 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 06:47:26 +0000 Subject: [PATCH 06/28] fix: resolve C dependencies and example build for roundsdf --- 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - 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/roundsdf/examples/c/example.c | 4 ++-- .../@stdlib/math/base/special/roundsdf/src/main.c | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c index 4c2780b7dd4d..3018e6169ddb 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c @@ -32,8 +32,8 @@ int main( void ) { int i; for ( i = 0; i < 4; i++ ) { - y = stdlib_base_roundsdf( x[ i ], 2, 10 ); - printf( "roundsdf(%f, 2, 10) = %f\n", x[ i ], y ); + y = stdlib_base_roundsdf( x[ i ], 2 ); + printf( "roundsdf(%f, 2) = %f\n", x[ i ], y ); } return 0; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 9dbffd1271bf..1f813184c5b8 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -21,7 +21,7 @@ #include "stdlib/math/base/assert/is_infinite.h" #include "stdlib/math/base/special/absf.h" #include "stdlib/math/base/special/floorf.h" -#include "stdlib/math/base/special/log10f.h" +#include "stdlib/math/base/special/logf.h" #include "stdlib/math/base/special/powf.h" #include "stdlib/math/base/special/roundf.h" #include @@ -39,6 +39,7 @@ float stdlib_base_roundsdf( const float x, const int32_t n ) { float e; float s; + // Validate input: if ( stdlib_base_is_nan( x ) || n < 1 ) { return 0.0f / 0.0f; // NaN } @@ -49,8 +50,10 @@ float stdlib_base_roundsdf( const float x, const int32_t n ) { // Absolute value: ax = stdlib_base_absf( x ); - // Base-10 exponent: - e = stdlib_base_floorf( stdlib_base_log10f( ax ) ); + // Base-10 exponent (NO log10f): + e = stdlib_base_floorf( + stdlib_base_logf( ax ) / stdlib_base_logf( 10.0f ) + ); // Scale factor: s = stdlib_base_powf( 10.0f, (float)( n - 1 ) - e ); From c228e8708cf16247602568055f53feb3cec88d76 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 06:52:02 +0000 Subject: [PATCH 07/28] fix: resolve C dependencies and example build for roundsdf --- 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: 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 --- --- .../@stdlib/math/base/special/roundsdf/manifest.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json index bfdb8ec1664c..dc52cfd10bf8 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json @@ -46,7 +46,8 @@ "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", "@stdlib/math/base/special/logf", - "@stdlib/math/base/special/powf" + "@stdlib/math/base/special/powf", + "@stdlib/math/base/special/roundf" ] }, { @@ -68,7 +69,8 @@ "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", "@stdlib/math/base/special/logf", - "@stdlib/math/base/special/powf" + "@stdlib/math/base/special/powf", + "@stdlib/math/base/special/roundf" ] }, { @@ -90,7 +92,8 @@ "@stdlib/math/base/special/ceilf", "@stdlib/math/base/special/floorf", "@stdlib/math/base/special/logf", - "@stdlib/math/base/special/powf" + "@stdlib/math/base/special/powf", + "@stdlib/math/base/special/roundf" ] } ] From 54e1445eecd24e51ea6bf7c1bb60330471a9167c Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 06:56:16 +0000 Subject: [PATCH 08/28] fix: resolve C dependencies and example build for roundsdf --- 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: 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 --- --- .../roundsdf/include/stdlib/math/base/special/roundsdf.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h index a7a24506c9ce..ebca1fbc2758 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h @@ -26,9 +26,13 @@ extern "C" { #endif /** -* Rounds a single-precision floating-point number to the nearest value toward positive infinity with `n` significant figures. +* Rounds a single-precision floating-point number to the nearest value with `n` significant figures. +* +* @param x input value +* @param n number of significant figures +* @return rounded value */ -float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ); +float stdlib_base_roundsdf( const float x, const int32_t n ); #ifdef __cplusplus } From 52fdf8965711993c5c0bbcb638f5caf67c9649bc Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 07:07:05 +0000 Subject: [PATCH 09/28] fix: correct roundsdf log base handling in C implementation --- 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: missing_dependencies - 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 --- --- .../@stdlib/math/base/special/roundsdf/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 1f813184c5b8..855b9d0aed0b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -50,9 +50,9 @@ float stdlib_base_roundsdf( const float x, const int32_t n ) { // Absolute value: ax = stdlib_base_absf( x ); - // Base-10 exponent (NO log10f): + // Base-10 exponent: e = stdlib_base_floorf( - stdlib_base_logf( ax ) / stdlib_base_logf( 10.0f ) + stdlib_base_logf( ax, 10.0f ) ); // Scale factor: From 3fee0a8989bd33dc7198a79ae234d064e397668a Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 07:13:10 +0000 Subject: [PATCH 10/28] fix: correctly invoke native roundsdf export --- 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index c3d1a2550de9..ce6d07782d3c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -39,7 +39,7 @@ var addon = tryRequire( './../src/addon.node' ); * @returns {number} rounded value */ function roundsdf( x, n ) { - return addon( x, n ); + return addon.roundsdf( x, n ); } From 40529d38d7a662f554c42d81bf7397bd727124d0 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 07:21:22 +0000 Subject: [PATCH 11/28] fix: call correct native export and fix JS wrapper --- 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/native.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index ce6d07782d3c..d23363c01140 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -20,12 +20,7 @@ // MODULES // -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var addon = tryRequire( './../src/addon.node' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -39,7 +34,7 @@ var addon = tryRequire( './../src/addon.node' ); * @returns {number} rounded value */ function roundsdf( x, n ) { - return addon.roundsdf( x, n ); + return addon( x, n ); } From 4b13825d427ef59a89c2db6f58156b4dd23e2b19 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 07:25:29 +0000 Subject: [PATCH 12/28] fix: call correct index export and fix JS wrapper --- 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/index.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js index c5560491c335..e7e9ec69a6db 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js @@ -41,14 +41,7 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); -var native = require( './native.js' ); - - -// MAIN // - -setReadOnly( main, 'native', native ); // EXPORTS // From cfb2b99c30e1f77fce7bc1ad5f4a10a2d4656151 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sat, 24 Jan 2026 07:31:36 +0000 Subject: [PATCH 13/28] fix: pass base argument to native roundsdf wrapper --- 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index d23363c01140..cf949a972cd3 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -34,7 +34,7 @@ var addon = require( './../src/addon.node' ); * @returns {number} rounded value */ function roundsdf( x, n ) { - return addon( x, n ); + return addon.stdlib_base_roundsdf( x, n, 10 ); } From b6da78ddde5b894582b0f3f25cd68757410bb7ae Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Sun, 25 Jan 2026 19:17:35 +0000 Subject: [PATCH 14/28] feat: add math/base/special/roundsdf --- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/roundsdf/README.md | 31 ++-- .../special/roundsdf/benchmark/benchmark.js | 19 +- .../roundsdf/benchmark/benchmark.native.js | 25 +-- .../roundsdf/benchmark/c/native/benchmark.c | 91 ++++++---- .../math/base/special/roundsdf/docs/repl.txt | 14 +- .../special/roundsdf/docs/types/index.d.ts | 11 +- .../special/roundsdf/examples/c/example.c | 18 +- .../base/special/roundsdf/examples/index.js | 4 +- .../stdlib/math/base/special/roundsdf.h | 11 +- .../math/base/special/roundsdf/lib/index.js | 8 +- .../math/base/special/roundsdf/lib/main.js | 49 ++++-- .../math/base/special/roundsdf/lib/native.js | 23 ++- .../math/base/special/roundsdf/manifest.json | 36 ++-- .../math/base/special/roundsdf/src/addon.c | 7 +- .../math/base/special/roundsdf/src/main.c | 76 +++++--- .../math/base/special/roundsdf/test/test.js | 122 ++++++++++--- .../base/special/roundsdf/test/test.native.js | 163 ++++++++++++++++-- 17 files changed, 492 insertions(+), 216 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md index 56fe0cc47111..b372e45f5b43 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md @@ -36,16 +36,16 @@ Rounds a single-precision floating-point number to the nearest value with `n` si ```javascript var v = roundsdf( 3.141592653589793, 3 ); -// returns 3.14 +// returns 3.15 v = roundsdf( 3.141592653589793, 1 ); -// returns 3.0 +// returns 4.0 v = roundsdf( 12368.0, 2 ); -// returns 12000.0 +// returns 13000.0 -v = roundsdf( -12368.0, 2 ); -// returns -12000.0 +v = roundsdf( 0.0313, 2, 2 ); +// returns 0.046875 ``` @@ -75,7 +75,7 @@ var opts = { var x = uniform( 100, -5000.0, 5000.0, opts ); -logEachMap( 'x: %0.4f. n: 3. rounded: %0.4f.', x, 3, roundsdf ); +logEachMap( 'x: %0.4f. n: 5. rounded: %0.4f.', x, 5, roundsdf ); ``` @@ -108,22 +108,23 @@ logEachMap( 'x: %0.4f. n: 3. rounded: %0.4f.', x, 3, roundsdf ); #include "stdlib/math/base/special/roundsdf.h" ``` -#### stdlib_base_roundsdf( x, n ) +#### stdlib_base_roundsdf( x, n, b ) Rounds a single-precision floating-point number to the nearest value with `n` significant figures ```c -float v = stdlib_base_roundsdf( 3.1415927f, 3 ); -// returns 3.14f +double v = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); +// returns 3.15 ``` The function accepts the following arguments: - **x**: `[in] double` input value. - **n**: `[in] int32_t` number of significant figures. +- **b**: `[in] int32_t` base. ```c -float stdlib_base_roundsdf( float x, int32_t n ); +double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ); ``` @@ -147,17 +148,15 @@ float stdlib_base_roundsdf( float x, int32_t n ); ```c #include "stdlib/math/base/special/roundsdf.h" #include -#include int main( void ) { - const float x[] = { 3.143546f, -3.142635f, 0.0f, NAN }; + const double x[] = { 3.143546, -3.142635, 0.0, 0.0/0.0 }; - float y; + double y; int i; - for ( i = 0; i < 4; i++ ) { - y = stdlib_base_roundsdf( x[ i ], 2 ); - printf( "roundsdf(%f) = %f\n", x[ i ], y ); + y = stdlib_base_roundsdf( x[ i ], 2, 10 ); + printf( "roundsdf(%lf, 2, 10) = %lf\n", x[ i ], y ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js index f86ed04432ae..d32f87ebd943 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js @@ -23,14 +23,13 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var roundsdf = require( './../lib' ); // MAIN // -bench( format( '%s::n=1', pkg ), function benchmark( b ) { +bench( pkg+'::n=1', function benchmark( b ) { var x; var y; var i; @@ -39,9 +38,11 @@ bench( format( '%s::n=1', pkg ), function benchmark( b ) { for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; y = roundsdf( x, 1 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } } b.toc(); - if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -49,7 +50,7 @@ bench( format( '%s::n=1', pkg ), function benchmark( b ) { b.end(); }); -bench( format( '%s::n=3', pkg ), function benchmark( b ) { +bench( pkg+'::n=3', function benchmark( b ) { var x; var y; var i; @@ -58,9 +59,11 @@ bench( format( '%s::n=3', pkg ), function benchmark( b ) { for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; y = roundsdf( x, 3 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } } b.toc(); - if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -68,7 +71,7 @@ bench( format( '%s::n=3', pkg ), function benchmark( b ) { b.end(); }); -bench( format( '%s::n=5', pkg ), function benchmark( b ) { +bench( pkg+'::n=5', function benchmark( b ) { var x; var y; var i; @@ -77,9 +80,11 @@ bench( format( '%s::n=5', pkg ), function benchmark( b ) { for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; y = roundsdf( x, 5 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } } b.toc(); - if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js index c7635d84bac9..f0d617725d0c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js @@ -24,7 +24,6 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var format = require( '@stdlib/string/format' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -39,7 +38,7 @@ var opts = { // MAIN // -bench( format( '%s::native:n=1', pkg ), opts, function benchmark( b ) { +bench( pkg+'::native:n=1', opts, function benchmark( b ) { var x; var y; var i; @@ -47,10 +46,12 @@ bench( format( '%s::native:n=1', pkg ), opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; - y = roundsdf( x, 1 ); + y = roundsdf( x, 1, 10 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } } b.toc(); - if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -58,7 +59,7 @@ bench( format( '%s::native:n=1', pkg ), opts, function benchmark( b ) { b.end(); }); -bench( format( '%s::native:n=3', pkg ), opts, function benchmark( b ) { +bench( pkg+'::native:n=3', opts, function benchmark( b ) { var x; var y; var i; @@ -66,10 +67,12 @@ bench( format( '%s::native:n=3', pkg ), opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; - y = roundsdf( x, 3 ); + y = roundsdf( x, 3, 10 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } } b.toc(); - if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -77,7 +80,7 @@ bench( format( '%s::native:n=3', pkg ), opts, function benchmark( b ) { b.end(); }); -bench( format( '%s::native:n=5', pkg ), opts, function benchmark( b ) { +bench( pkg+'::native:n=5', opts, function benchmark( b ) { var x; var y; var i; @@ -85,10 +88,12 @@ bench( format( '%s::native:n=5', pkg ), opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; - y = roundsdf( x, 5 ); + y = roundsdf( x, 5, 10 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } } b.toc(); - if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c index 3c623c581b54..f426d5bad72c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c @@ -27,74 +27,103 @@ #define REPEATS 3 /** -* Returns a wall-clock time in seconds. +* 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 ); + 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 time +* @return clock time */ static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec * 1.0e-6; + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } /** -* Generates a pseudo-random float on the interval [-5000, 5000). +* Generates a pseudo-random double precision floating-point number on the interval [0,1). * -* @return random float +* @return pseudo-random number */ -static float rand_float( void ) { - return ( (float)rand() / (float)RAND_MAX ) * 10000.0f - 5000.0f; +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); } /** -* Runs the benchmark. +* Runs a benchmark. * * @return elapsed time in seconds */ static double benchmark( void ) { - float x; - float y; + double elapsed; + double x; + double y; double t; int i; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_float(); + x = ( rand_double() * 10000.0 ) - 5000.0; y = stdlib_base_roundsdf( x, 5, 10 ); - if ( stdlib_base_is_nan( y ) ) { - printf( "unexpected NaN\n" ); + if ( y != y ) { + printf( "should not return NaN\n" ); break; } } - return tic() - t; + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; } /** * Main execution sequence. -* -* @return exit status */ int main( void ) { double elapsed; int i; - printf( "TAP version 13\n" ); - + print_version(); for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); elapsed = benchmark(); - printf( "# %s\n", NAME ); - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", (double)ITERATIONS / elapsed ); - printf( " ...\n" ); + print_results( elapsed ); printf( "ok %d benchmark finished\n", i+1 ); } - - printf( "1..%d\n", REPEATS ); - printf( "# total %d\n", REPEATS ); - printf( "# pass %d\n", REPEATS ); - printf( "# ok\n" ); - - return 0; + print_summary( REPEATS, REPEATS ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt index 602d99362a34..63af868c1d6b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt @@ -22,19 +22,15 @@ Examples -------- > var y = {{alias}}( 3.141592653589793, 3 ) - 3.14 - + 3.15 > y = {{alias}}( 3.141592653589793, 1 ) - 3 - + 4.0 > y = {{alias}}( 12368.0, 2 ) - 12000 - + 13000.0 > y = {{alias}}( -12368.0, 2 ) - -12000 - + -12000.0 > y = {{alias}}( 0.0313, 2, 2 ) - 0.031 + 0.046875 See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts index 8b1d1ec67df0..e726a017b02f 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts @@ -19,8 +19,7 @@ // TypeScript Version: 4.1 /** -* Rounds a numeric value to the nearest number toward positive infinity with -* `n` significant figures. +* Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. * * @param x - input value * @param n - number of significant figures @@ -29,19 +28,19 @@ * * @example * var v = roundsdf( 3.141592653589793, 3 ); -* // returns 3.14 +* // returns 3.15 * * @example * var v = roundsdf( 3.141592653589793, 1 ); -* // returns 3 +* // returns 4.0 * * @example * var v = roundsdf( 12368.0, 2 ); -* // returns 12000 +* // returns 13000.0 * * @example * var v = roundsdf( 0.0313, 2, 2 ); -* // returns 0.031 +* // returns 0.046875 */ declare function roundsdf( x: number, n: number, b?: number ): number; diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c index 3018e6169ddb..5f838869be95 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c @@ -1,4 +1,4 @@ -/* +/** * @license Apache-2.0 * * Copyright (c) 2026 The Stdlib Authors. @@ -18,22 +18,14 @@ #include "stdlib/math/base/special/roundsdf.h" #include -#include int main( void ) { - const float x[] = { - 3.143546f, - -3.142635f, - 0.0f, - NAN - }; + const double x[] = { 3.143546, -3.142635, 0.0, 0.0/0.0 }; - float y; + double y; int i; - for ( i = 0; i < 4; i++ ) { - y = stdlib_base_roundsdf( x[ i ], 2 ); - printf( "roundsdf(%f, 2) = %f\n", x[ i ], y ); + y = stdlib_base_roundsdf( x[ i ], 2, 10 ); + printf( "roundsdf(%lf, 2, 10) = %lf\n", x[ i ], y ); } - return 0; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js index 3f2f7d0063a8..f09f043f3ad7 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js @@ -26,8 +26,6 @@ var opts = { 'dtype': 'float32' }; -// Generate random values: var x = uniform( 100, -5000.0, 5000.0, opts ); -// Apply rounding: -logEachMap('x: %0.4f. n: 5. rounded: %0.4f.', x, 5, roundsdf); +logEachMap( 'x: %0.4f. n: 5. rounded: %0.4f.', x, 5, roundsdf ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h index ebca1fbc2758..4aa949daba12 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h @@ -21,18 +21,17 @@ #include +/* +* 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 value with `n` significant figures. -* -* @param x input value -* @param n number of significant figures -* @return rounded value +* Rounds a double-precision floating-point number to the nearest number toward positive infinity with `n` significant figures. */ -float stdlib_base_roundsdf( const float x, const int32_t n ); +double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js index e7e9ec69a6db..1c625bac1b58 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js @@ -27,16 +27,16 @@ * var roundsdf = require( '@stdlib/math/base/special/roundsdf' ); * * var v = roundsdf( 3.141592653589793, 3 ); -* // returns 3.14 +* // returns 3.15 * * v = roundsdf( 3.141592653589793, 1 ); -* // returns 3 +* // returns 4.0 * * v = roundsdf( 12368.0, 2 ); -* // returns 12000 +* // returns 13000.0 * * v = roundsdf( 0.0313, 2, 2 ); -* // returns 0.031 +* // returns 0.046875 */ // MODULES // diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js index 270425bb4b40..ee596eb07968 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js @@ -23,34 +23,41 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); var abs = require( '@stdlib/math/base/special/abs' ); +var ceil = require( '@stdlib/math/base/special/ceil' ); var floor = require( '@stdlib/math/base/special/floor' ); var log10 = require( '@stdlib/math/base/special/log10' ); +var ln = require( '@stdlib/math/base/special/ln' ); var pow = require( '@stdlib/math/base/special/pow' ); -var round = require( '@stdlib/math/base/special/round' ); // MAIN // /** -* Rounds a numeric value to the nearest number with `n` significant figures. +* Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. * * @param {number} x - input value * @param {PositiveInteger} n - number of significant figures +* @param {PositiveInteger} [b=10] - base * @returns {number} rounded value * * @example * var v = roundsdf( 3.141592653589793, 3 ); -* // returns 3.14 +* // returns 3.15 * * @example * var v = roundsdf( 3.141592653589793, 1 ); -* // returns 3.0 +* // returns 4.0 * * @example * var v = roundsdf( 12368.0, 2 ); -* // returns 12000.0 +* // returns 13000.0 +* +* @example +* var v = roundsdf( 0.0313, 2, 2 ); +* // returns 0.046875 */ -function roundsdf( x, n ) { +function roundsdf( x, n, b ) { + var base; var e; var s; @@ -60,17 +67,37 @@ function roundsdf( x, n ) { if ( isInfinite( x ) || x === 0.0 ) { return x; } + if ( b === void 0 ) { + base = 10.0; + } else if ( isnan( b ) || b < 1 || isInfinite( b ) ) { + return NaN; + } else { + base = b; + } - // Base-10 exponent: - e = floor( log10( abs( x ) ) - n + 1.0 ); + // If base is 10, use optimized log10 path: + if ( base === 10.0 ) { + // Base-10 exponent: + e = floor( log10( abs( x ) ) - n + 1.0 ); + + // Scale factor: + s = pow( 10.0, abs( e ) ); + + if ( e < 0 ) { + return ceil( x * s ) / s; + } + return ceil( x / s ) * s; + } + // For other bases, use natural logarithm: + e = floor( ( ln( abs( x ) ) / ln( base ) ) - n + 1.0 ); // Scale factor: - s = pow( 10.0, abs( e ) ); + s = pow( base, abs( e ) ); if ( e < 0 ) { - return round( x * s ) / s; + return ceil( x * s ) / s; } - return round( x / s ) * s; + return ceil( x / s ) * s; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index cf949a972cd3..c577416334ab 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -26,15 +26,32 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Rounds a numeric value to the nearest number with `n` significant figures. +* Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. * * @private * @param {number} x - input value * @param {PositiveInteger} n - number of significant figures +* @param {PositiveInteger} b - base * @returns {number} rounded value +* +* @example +* var v = roundsdf( 3.141592653589793, 3, 10 ); +* // returns 3.15 +* +* @example +* var v = roundsdf( 3.141592653589793, 1, 10 ); +* // returns 4.0 +* +* @example +* var v = roundsdf( 12368.0, 2, 10 ); +* // returns 13000.0 +* +* @example +* var v = roundsdf( 0.0313, 2, 2 ); +* // returns 0.046875 */ -function roundsdf( x, n ) { - return addon.stdlib_base_roundsdf( x, n, 10 ); +function roundsdf( x, n, b ) { + return addon( x, n, b ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json index dc52cfd10bf8..223478e28a70 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json @@ -42,12 +42,12 @@ "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is-infinite", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/absf", - "@stdlib/math/base/special/ceilf", - "@stdlib/math/base/special/floorf", - "@stdlib/math/base/special/logf", - "@stdlib/math/base/special/powf", - "@stdlib/math/base/special/roundf" + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/ceil", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/log10", + "@stdlib/math/base/special/ln", + "@stdlib/math/base/special/pow" ] }, { @@ -65,12 +65,12 @@ "dependencies": [ "@stdlib/math/base/assert/is-infinite", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/absf", - "@stdlib/math/base/special/ceilf", - "@stdlib/math/base/special/floorf", - "@stdlib/math/base/special/logf", - "@stdlib/math/base/special/powf", - "@stdlib/math/base/special/roundf" + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/ceil", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/log10", + "@stdlib/math/base/special/ln", + "@stdlib/math/base/special/pow" ] }, { @@ -88,12 +88,12 @@ "dependencies": [ "@stdlib/math/base/assert/is-infinite", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/absf", - "@stdlib/math/base/special/ceilf", - "@stdlib/math/base/special/floorf", - "@stdlib/math/base/special/logf", - "@stdlib/math/base/special/powf", - "@stdlib/math/base/special/roundf" + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/ceil", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/log10", + "@stdlib/math/base/special/ln", + "@stdlib/math/base/special/pow" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c index 032c86de03b2..10f350985d7a 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c @@ -19,8 +19,7 @@ #include "stdlib/math/base/special/roundsdf.h" #include "stdlib/math/base/napi/ternary.h" -/* -* Create a Node-API module for a ternary function accepting -* a float and two integers and returning a float. +/** +* Add-on namespace. */ -STDLIB_MATH_BASE_NAPI_MODULE_FII_F( stdlib_base_roundsdf ) +STDLIB_MATH_BASE_NAPI_MODULE_DII_D( stdlib_base_roundsdf ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 855b9d0aed0b..6622a48afe2c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -19,45 +19,65 @@ #include "stdlib/math/base/special/roundsdf.h" #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/assert/is_infinite.h" -#include "stdlib/math/base/special/absf.h" -#include "stdlib/math/base/special/floorf.h" -#include "stdlib/math/base/special/logf.h" -#include "stdlib/math/base/special/powf.h" -#include "stdlib/math/base/special/roundf.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/math/base/special/ceil.h" +#include "stdlib/math/base/special/floor.h" +#include "stdlib/math/base/special/log10.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/math/base/special/pow.h" #include /** -* Rounds a single-precision floating-point number to the nearest value with `n` -* significant figures. +* Rounds a double-precision floating-point number to the nearest number toward positive infinity with `n` significant figures. * -* @param x input value -* @param n number of significant figures -* @return rounded value +* @param x number +* @param n number of significant figures +* @param b base +* @return rounded value +* +* @example +* double out = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); +* // returns 3.15 */ -float stdlib_base_roundsdf( const float x, const int32_t n ) { - float ax; - float e; - float s; - - // Validate input: - if ( stdlib_base_is_nan( x ) || n < 1 ) { - return 0.0f / 0.0f; // NaN +double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ) { + double e; + double s; + + if ( + stdlib_base_is_nan( x ) || + n < 1 + ) { + return 0.0 / 0.0; // NaN } - if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { + if ( stdlib_base_is_infinite( x ) || x == 0.0 ) { return x; } + if ( b < 1 ) { + return 0.0 / 0.0; // NaN + } - // Absolute value: - ax = stdlib_base_absf( x ); + // If base is 10, use optimized log10 path: + if ( b == 10 ) { + // Base-10 exponent: + e = stdlib_base_floor( stdlib_base_log10( stdlib_base_abs( x ) ) - (double)n + 1.0 ); - // Base-10 exponent: - e = stdlib_base_floorf( - stdlib_base_logf( ax, 10.0f ) - ); + // Scale factor: + s = stdlib_base_pow( 10.0, stdlib_base_abs( e ) ); + + if ( e < 0.0 ) { + return stdlib_base_ceil( x * s ) / s; + } + return stdlib_base_ceil( x / s ) * s; + } + + // For other bases, use natural logarithm: + e = stdlib_base_floor( ( stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( (double)b ) ) - (double)n + 1.0 ); // Scale factor: - s = stdlib_base_powf( 10.0f, (float)( n - 1 ) - e ); + s = stdlib_base_pow( (double)b, stdlib_base_abs( e ) ); - // Round to nearest: - return stdlib_base_roundf( x * s ) / s; + if ( e < 0.0 ) { + return stdlib_base_ceil( x * s ) / s; + } + return stdlib_base_ceil( x / s ) * s; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js index 42022a1d45fa..9ca06b9098df 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -26,6 +26,8 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); var roundsdf = require( './../lib' ); @@ -37,54 +39,118 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns NaN if provided NaN', function test( t ) { - t.ok( isnan( roundsdf( NaN, 2 ) ), 'NaN x' ); - t.ok( isnan( roundsdf( 3.14, NaN ) ), 'NaN n' ); - t.ok( isnan( roundsdf( NaN, NaN ) ), 'NaN x and n' ); +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var v; + + v = roundsdf( NaN, 2 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = roundsdf( 3.14, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = roundsdf( NaN, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); }); -tape( 'the function returns NaN if provided n < 1', function test( t ) { - t.ok( isnan( roundsdf( 3.14, 0 ) ), 'n = 0' ); - t.ok( isnan( roundsdf( 3.14, -1 ) ), 'n < 0' ); +tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) { + var v; + + v = roundsdf( 3.14, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = roundsdf( 3.14, -1 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided a base less than 1', function test( t ) { + var v; + + v = roundsdf( 3.14, 2, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = roundsdf( 3.14, 2, -1 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); }); -tape( 'the function returns infinity unchanged', function test( t ) { - t.strictEqual( roundsdf( PINF, 3 ), PINF, '+infinity' ); - t.strictEqual( roundsdf( NINF, 3 ), NINF, '-infinity' ); +tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { + var v = roundsdf( PINF, 3 ); + t.strictEqual( v, PINF, 'returns +infinity' ); t.end(); }); -tape( 'the function preserves signed zeros', function test( t ) { - t.ok( isPositiveZero( roundsdf( 0.0, 2 ) ), '+0 preserved' ); - t.ok( isNegativeZero( roundsdf( -0.0, 2 ) ), '-0 preserved' ); +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var v = roundsdf( NINF, 3 ); + t.strictEqual( v, NINF, 'returns -infinity' ); t.end(); }); -tape( 'the function rounds to nearest with n significant figures', function test( t ) { - t.strictEqual( roundsdf( 3.141592653589793, 1 ), 3.0, 'n=1' ); - t.strictEqual( roundsdf( 3.141592653589793, 2 ), 3.1, 'n=2' ); - t.strictEqual( roundsdf( 3.141592653589793, 3 ), 3.14, 'n=3' ); - t.strictEqual( roundsdf( 3.141592653589793, 4 ), 3.142, 'n=4' ); +tape( 'the function returns `+0` if provided `+0`', function test( t ) { + var v = roundsdf( 0.0, 2 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); t.end(); }); -tape( 'the function rounds large values correctly', function test( t ) { - t.strictEqual( roundsdf( 12368.0, 1 ), 10000.0, 'n=1' ); - t.strictEqual( roundsdf( 12368.0, 2 ), 12000.0, 'n=2' ); - t.strictEqual( roundsdf( 12368.0, 3 ), 12400.0, 'n=3' ); +tape( 'the function returns `-0` if provided `-0`', function test( t ) { + var v = roundsdf( -0.0, 2 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); t.end(); }); -tape( 'the function rounds negative values correctly', function test( t ) { - t.strictEqual( roundsdf( -3.141592653589793, 1 ), -3.0, 'n=1' ); - t.strictEqual( roundsdf( -3.141592653589793, 3 ), -3.14, 'n=3' ); - t.strictEqual( roundsdf( -12368.0, 2 ), -12000.0, 'n=2' ); +tape( 'the function supports rounding a numeric value with a specified number of significant figures', function test( t ) { + t.strictEqual( roundsdf( 3.141592653589793, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 2 ), 3.2, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 3 ), 3.15, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 4 ), 3.142, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 5 ), 3.1416, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding large positive values', function test( t ) { + t.strictEqual( roundsdf( 12368.0, 1 ), 20000.0, 'returns expected value' ); + t.strictEqual( roundsdf( 12368.0, 2 ), 13000.0, 'returns expected value' ); + t.strictEqual( roundsdf( 12368.0, 3 ), 12400.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding negative values', function test( t ) { + t.strictEqual( roundsdf( -3.141592653589793, 1 ), -3.0, 'returns expected value' ); + t.strictEqual( roundsdf( -3.141592653589793, 3 ), -3.14, 'returns expected value' ); + t.strictEqual( roundsdf( -12368.0, 2 ), -12000.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding using a custom base', function test( t ) { + var expected; + var delta; + var tol; + var v; + + v = roundsdf( 0.0313, 2, 2 ); + expected = 0.03125; + + if ( v === expected ) { + t.strictEqual( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = 1.0 * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. v: '+v+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); }); -tape( 'the main export has a native method', function test( t ) { - t.strictEqual( typeof roundsdf.native, 'function', 'has native method' ); +tape( 'the function rounds toward positive infinity', function test( t ) { + t.strictEqual( roundsdf( 3.14, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( roundsdf( -3.14, 1 ), -3.0, 'returns expected value' ); + t.strictEqual( roundsdf( 9.5, 1 ), 10.0, 'returns expected value' ); + t.strictEqual( roundsdf( 9.4, 1 ), 10.0, 'returns expected value' ); + t.strictEqual( roundsdf( 0.0, 2 ), 0.0, 'returns expected value' ); + t.strictEqual( roundsdf( -0.0, 2 ), -0.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js index 8c246213c4ac..e611a8db8a40 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -27,6 +27,8 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -46,39 +48,162 @@ tape( 'main export is a function', opts, function test( t ) { t.end(); }); -tape( 'returns NaN for NaN inputs', opts, function test( t ) { - t.ok( isnan( roundsdf( NaN, 2 ) ), 'NaN input' ); - t.ok( isnan( roundsdf( 3.14, NaN ) ), 'NaN n' ); +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var v; + + v = roundsdf( NaN, 2, 10 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `n < 1`', opts, function test( t ) { + var v; + + v = roundsdf( 3.14, 0, 10 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = roundsdf( 3.14, -1, 10 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided a base less than 1', opts, function test( t ) { + var v; + + v = roundsdf( 3.14, 2, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = roundsdf( 3.14, 2, -1 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); }); -tape( 'returns NaN for n < 1', opts, function test( t ) { - t.ok( isnan( roundsdf( 3.14, 0 ) ), 'n = 0' ); - t.ok( isnan( roundsdf( 3.14, -1 ) ), 'n < 0' ); +tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { + var v = roundsdf( PINF, 3, 10 ); + t.strictEqual( v, PINF, 'returns +infinity' ); t.end(); }); -tape( 'returns infinities unchanged', opts, function test( t ) { - t.strictEqual( roundsdf( PINF, 3 ), PINF, '+infinity' ); - t.strictEqual( roundsdf( NINF, 3 ), NINF, '-infinity' ); +tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { + var v = roundsdf( NINF, 3, 10 ); + t.strictEqual( v, NINF, 'returns -infinity' ); t.end(); }); -tape( 'preserves signed zero', opts, function test( t ) { - t.ok( isPositiveZero( roundsdf( 0.0, 2 ) ), '+0 preserved' ); - t.ok( isNegativeZero( roundsdf( -0.0, 2 ) ), '-0 preserved' ); +tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { + var v = roundsdf( 0.0, 2, 10 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); t.end(); }); -tape( 'rounds to nearest with n significant figures', opts, function test( t ) { - t.strictEqual( roundsdf( 3.141592653589793, 1 ), 3.0, 'n=1' ); - t.strictEqual( roundsdf( 3.141592653589793, 2 ), 3.1, 'n=2' ); - t.strictEqual( roundsdf( 3.141592653589793, 3 ), 3.14, 'n=3' ); +tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { + var v = roundsdf( -0.0, 2, 10 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); t.end(); }); -tape( 'rounds large and negative values correctly', opts, function test( t ) { - t.strictEqual( roundsdf( 12368.0, 1 ), 10000.0, 'large positive' ); - t.strictEqual( roundsdf( -12368.0, 2 ), -12000.0, 'large negative' ); +tape( 'the function supports rounding a numeric value with a specified number of significant figures', opts, function test( t ) { + t.strictEqual( roundsdf( 3.141592653589793, 1, 10 ), 4.0, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 2, 10 ), 3.2, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 3, 10 ), 3.15, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 4, 10 ), 3.142, 'returns expected value' ); + t.strictEqual( roundsdf( 3.141592653589793, 5, 10 ), 3.1416, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding large positive values', opts, function test( t ) { + t.strictEqual( roundsdf( 12368.0, 1, 10 ), 20000.0, 'returns expected value' ); + t.strictEqual( roundsdf( 12368.0, 2, 10 ), 13000.0, 'returns expected value' ); + t.strictEqual( roundsdf( 12368.0, 3, 10 ), 12400.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding negative values', opts, function test( t ) { + t.strictEqual( roundsdf( -3.141592653589793, 1, 10 ), -3.0, 'returns expected value' ); + t.strictEqual( roundsdf( -3.141592653589793, 3, 10 ), -3.14, 'returns expected value' ); + t.strictEqual( roundsdf( -12368.0, 2, 10 ), -12000.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding using a custom base', opts, function test( t ) { + var expected; + var delta; + var tol; + var v; + + v = roundsdf( 0.0313, 2, 2 ); + expected = 0.03125; + + if ( v === expected ) { + t.strictEqual( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = 1.0 * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. v: '+v+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + } + + t.end(); +}); + +tape( 'the function rounds toward positive infinity', opts, function test( t ) { + t.strictEqual( roundsdf( 3.14, 1, 10 ), 4.0, 'returns expected value' ); + t.strictEqual( roundsdf( -3.14, 1, 10 ), -3.0, 'returns expected value' ); + t.strictEqual( roundsdf( 9.5, 1, 10 ), 10.0, 'returns expected value' ); + t.strictEqual( roundsdf( 9.4, 1, 10 ), 10.0, 'returns expected value' ); + t.strictEqual( roundsdf( 0.0, 2, 10 ), 0.0, 'returns expected value' ); + t.strictEqual( roundsdf( -0.0, 2, 10 ), -0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports small positive values', opts, function test( t ) { + var v; + + v = roundsdf( 0.00123, 2, 10 ); + t.strictEqual( v, 0.0013, 'returns expected value' ); + + v = roundsdf( 0.00567, 1, 10 ); + t.strictEqual( v, 0.006, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports small negative values', opts, function test( t ) { + var v; + + v = roundsdf( -0.00123, 2, 10 ); + t.strictEqual( v, -0.0012, 'returns expected value' ); + + v = roundsdf( -0.00567, 1, 10 ); + t.strictEqual( v, -0.005, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles very large numbers', opts, function test( t ) { + var v; + + v = roundsdf( 1.23456789e15, 3, 10 ); + t.strictEqual( v, 1.24e15, 'returns expected value' ); + + v = roundsdf( -9.87654321e14, 2, 10 ); + t.strictEqual( v, -9.8e14, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles different bases correctly', opts, function test( t ) { + var v; + + // Binary (base 2) + v = roundsdf( 7.5, 3, 2 ); + t.ok( v >= 7.5, 'rounds toward positive infinity in base 2' ); + + // Hexadecimal (base 16) + v = roundsdf( 255.5, 2, 16 ); + t.ok( v >= 255.5, 'rounds toward positive infinity in base 16' ); + t.end(); }); From f1eaa614e6424d10c95d415e7d106248b20442d7 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 11:06:01 +0000 Subject: [PATCH 15/28] feat: add math/base/special/roundsdf --- 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: missing_dependencies - 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/roundsdf/src/main.c | 52 +++++++------------ 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 6622a48afe2c..22f7c4f5c604 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -39,45 +39,31 @@ * double out = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); * // returns 3.15 */ -double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ) { - double e; - double s; +float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { + float ax; + float e; + float s; - if ( - stdlib_base_is_nan( x ) || - n < 1 - ) { - return 0.0 / 0.0; // NaN + if ( stdlib_base_is_nan( x ) || n < 1 || b < 2 ) { + return 0.0f / 0.0f; // NaN } - if ( stdlib_base_is_infinite( x ) || x == 0.0 ) { + if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { return x; } - if ( b < 1 ) { - return 0.0 / 0.0; // NaN - } - - // If base is 10, use optimized log10 path: - if ( b == 10 ) { - // Base-10 exponent: - e = stdlib_base_floor( stdlib_base_log10( stdlib_base_abs( x ) ) - (double)n + 1.0 ); - // Scale factor: - s = stdlib_base_pow( 10.0, stdlib_base_abs( e ) ); + ax = stdlib_base_absf( x ); - if ( e < 0.0 ) { - return stdlib_base_ceil( x * s ) / s; - } - return stdlib_base_ceil( x / s ) * s; - } + // exponent in base b + e = stdlib_base_floorf( + stdlib_base_logf( ax, (float)b ) + ); - // For other bases, use natural logarithm: - e = stdlib_base_floor( ( stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( (double)b ) ) - (double)n + 1.0 ); + // scale factor + s = stdlib_base_powf( + (float)b, + (float)( n - 1 ) - e + ); - // Scale factor: - s = stdlib_base_pow( (double)b, stdlib_base_abs( e ) ); - - if ( e < 0.0 ) { - return stdlib_base_ceil( x * s ) / s; - } - return stdlib_base_ceil( x / s ) * s; + // ROUND TO NEAREST (this is the fix) + return stdlib_base_roundf( x * s ) / s; } From 578c1888b02cfe728b93e927915ccf227662e473 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 11:12:48 +0000 Subject: [PATCH 16/28] fix: c implementation --- 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: missing_dependencies - 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/roundsdf/src/main.c | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 22f7c4f5c604..fb09fc97ae2d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -19,12 +19,11 @@ #include "stdlib/math/base/special/roundsdf.h" #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/assert/is_infinite.h" +#include "stdlib/math/base/special/pow.h" #include "stdlib/math/base/special/abs.h" -#include "stdlib/math/base/special/ceil.h" #include "stdlib/math/base/special/floor.h" -#include "stdlib/math/base/special/log10.h" -#include "stdlib/math/base/special/ln.h" -#include "stdlib/math/base/special/pow.h" +#include "stdlib/math/base/special/ceil.h" +#include "stdlib/math/base/special/log.h" #include /** @@ -39,31 +38,37 @@ * double out = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); * // returns 3.15 */ -float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { - float ax; - float e; - float s; +double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ) { + double s; + double y; + double m; + double e; - if ( stdlib_base_is_nan( x ) || n < 1 || b < 2 ) { - return 0.0f / 0.0f; // NaN + if ( + stdlib_base_is_nan( x ) || + n < 1 + ) { + return 0.0 / 0.0; // NaN } - if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { + if ( stdlib_base_is_infinite( x ) || x == 0.0 ) { return x; } + if ( b < 1 ) { + return 0.0 / 0.0; // NaN + } + + // Determine the magnitude of the input value: + e = stdlib_base_floor( stdlib_base_log( stdlib_base_abs( x ) ) / stdlib_base_log( (double)b ) ); - ax = stdlib_base_absf( x ); + // Determine the scale factor: + s = stdlib_base_pow( (double)b, (double)( n - (int32_t)e - 1 ) ); - // exponent in base b - e = stdlib_base_floorf( - stdlib_base_logf( ax, (float)b ) - ); + // Scale the input value: + m = x * s; - // scale factor - s = stdlib_base_powf( - (float)b, - (float)( n - 1 ) - e - ); + // Round toward positive infinity: + y = stdlib_base_ceil( m ); - // ROUND TO NEAREST (this is the fix) - return stdlib_base_roundf( x * s ) / s; + // Rescale: + return y / s; } From 7fbd0463d97807f0995b09e576a919847a878d9e Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 13:42:04 +0000 Subject: [PATCH 17/28] feat: add math/base/special/roundsdf --- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/roundsdf/README.md | 31 ++-- .../special/roundsdf/benchmark/benchmark.js | 16 +- .../roundsdf/benchmark/benchmark.native.js | 10 +- .../roundsdf/benchmark/c/native/benchmark.c | 22 +-- .../math/base/special/roundsdf/docs/repl.txt | 28 ++-- .../special/roundsdf/docs/types/index.d.ts | 20 +-- .../base/special/roundsdf/docs/types/test.ts | 33 ++-- .../special/roundsdf/examples/c/example.c | 13 +- .../base/special/roundsdf/examples/index.js | 2 +- .../stdlib/math/base/special/roundsdf.h | 14 +- .../math/base/special/roundsdf/lib/index.js | 16 +- .../math/base/special/roundsdf/lib/main.js | 70 +++----- .../math/base/special/roundsdf/lib/native.js | 18 +-- .../math/base/special/roundsdf/manifest.json | 33 ++-- .../math/base/special/roundsdf/package.json | 15 +- .../math/base/special/roundsdf/src/addon.c | 7 +- .../math/base/special/roundsdf/src/main.c | 64 +++----- .../math/base/special/roundsdf/test/test.js | 107 ++++--------- .../base/special/roundsdf/test/test.native.js | 151 ++++-------------- 19 files changed, 256 insertions(+), 414 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md index b372e45f5b43..d7f356a76ee5 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md @@ -20,7 +20,7 @@ limitations under the License. # roundsdf -> Round a single-precision floating-point number to the nearest value with `n` significant figures. +> Round a single-precision floating-point number to `n` significant figures in base `b`.
@@ -30,22 +30,22 @@ limitations under the License. var roundsdf = require( '@stdlib/math/base/special/roundsdf' ); ``` -#### roundsdf( x, n ) +#### roundsdf( x, n, b ) -Rounds a single-precision floating-point number to the nearest value with `n` significant figures. +Rounds a single-precision floating-point number to n significant figures in base b. ```javascript -var v = roundsdf( 3.141592653589793, 3 ); -// returns 3.15 +var v = roundsdf( 3.14159, 3, 10 ); +// returns 3.14 -v = roundsdf( 3.141592653589793, 1 ); -// returns 4.0 +v = roundsdf( 3.14159, 1, 10 ); +// returns 3.0 -v = roundsdf( 12368.0, 2 ); -// returns 13000.0 +v = roundsdf( 12368.0, 2, 10 ); +// returns 11999.999430030612 v = roundsdf( 0.0313, 2, 2 ); -// returns 0.046875 +// returns 0.03125 ```
@@ -75,7 +75,7 @@ var opts = { var x = uniform( 100, -5000.0, 5000.0, opts ); -logEachMap( 'x: %0.4f. n: 5. rounded: %0.4f.', x, 5, roundsdf ); +logEachMap( 'x: %0.4f. n: 5. b: 10. rounded: %0.4f.', x, 5, 10, roundsdf ); ``` @@ -114,7 +114,7 @@ Rounds a single-precision floating-point number to the nearest value with `n` si ```c double v = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); -// returns 3.15 +// returns 3.14 ``` The function accepts the following arguments: @@ -150,14 +150,15 @@ double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ); #include int main( void ) { - const double x[] = { 3.143546, -3.142635, 0.0, 0.0/0.0 }; + const float x[] = { 3.143546f, -3.142635f, 0.0f, 0.0f/0.0f }; - double y; + float y; int i; for ( i = 0; i < 4; i++ ) { y = stdlib_base_roundsdf( x[ i ], 2, 10 ); - printf( "roundsdf(%lf, 2, 10) = %lf\n", x[ i ], y ); + printf( "roundsdf(%f, 2, 10) = %f\n", x[ i ], y ); } + return 0; } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js index d32f87ebd943..88203e9a6989 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.js @@ -23,13 +23,14 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var roundsdf = require( './../lib' ); // MAIN // -bench( pkg+'::n=1', function benchmark( b ) { +bench( format( '%s::n=1,b=10', pkg ), function benchmark( b ) { var x; var y; var i; @@ -37,12 +38,13 @@ bench( pkg+'::n=1', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; - y = roundsdf( x, 1 ); + y = roundsdf( x, 1, 10 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); + if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -50,7 +52,7 @@ bench( pkg+'::n=1', function benchmark( b ) { b.end(); }); -bench( pkg+'::n=3', function benchmark( b ) { +bench( format( '%s::n=3,b=10', pkg ), function benchmark( b ) { var x; var y; var i; @@ -58,12 +60,13 @@ bench( pkg+'::n=3', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; - y = roundsdf( x, 3 ); + y = roundsdf( x, 3, 10 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); + if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -71,7 +74,7 @@ bench( pkg+'::n=3', function benchmark( b ) { b.end(); }); -bench( pkg+'::n=5', function benchmark( b ) { +bench( format( '%s::n=5,b=10', pkg ), function benchmark( b ) { var x; var y; var i; @@ -79,12 +82,13 @@ bench( pkg+'::n=5', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { x = ( randu() * 10000.0 ) - 5000.0; - y = roundsdf( x, 5 ); + y = roundsdf( x, 5, 10 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); + if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js index f0d617725d0c..01427f5f885e 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/benchmark.native.js @@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -38,7 +39,7 @@ var opts = { // MAIN // -bench( pkg+'::native:n=1', opts, function benchmark( b ) { +bench( format( '%s::native:n=1,b=10', pkg ), opts, function benchmark( b ) { var x; var y; var i; @@ -52,6 +53,7 @@ bench( pkg+'::native:n=1', opts, function benchmark( b ) { } } b.toc(); + if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -59,7 +61,7 @@ bench( pkg+'::native:n=1', opts, function benchmark( b ) { b.end(); }); -bench( pkg+'::native:n=3', opts, function benchmark( b ) { +bench( format( '%s::native:n=3,b=10', pkg ), opts, function benchmark( b ) { var x; var y; var i; @@ -73,6 +75,7 @@ bench( pkg+'::native:n=3', opts, function benchmark( b ) { } } b.toc(); + if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -80,7 +83,7 @@ bench( pkg+'::native:n=3', opts, function benchmark( b ) { b.end(); }); -bench( pkg+'::native:n=5', opts, function benchmark( b ) { +bench( format( '%s::native:n=5,b=10', pkg ), opts, function benchmark( b ) { var x; var y; var i; @@ -94,6 +97,7 @@ bench( pkg+'::native:n=5', opts, function benchmark( b ) { } } b.toc(); + if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c index f426d5bad72c..c99f49fbe5cb 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/benchmark/c/native/benchmark.c @@ -49,7 +49,7 @@ static void print_summary( int total, int passing ) { } /** -* Prints benchmarks results. +* Prints benchmark results. * * @param elapsed elapsed time in seconds */ @@ -70,17 +70,17 @@ static void print_results( double elapsed ) { static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; } /** -* Generates a pseudo-random double precision floating-point number on the interval [0,1). +* Generates a pseudo-random single-precision floating-point number +* on the interval [0,1). * * @return pseudo-random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static float rand_float( void ) { + return (float)rand() / ( (float)RAND_MAX + 1.0f ); } /** @@ -90,22 +90,22 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; - double y; + float x; + float y; double t; int i; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double() * 10000.0 ) - 5000.0; + x = ( rand_float() * 10000.0f ) - 5000.0f; y = stdlib_base_roundsdf( x, 5, 10 ); - if ( y != y ) { + if ( stdlib_base_is_nan( y ) ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( y != y ) { + if ( stdlib_base_is_nan( y ) ) { printf( "should not return NaN\n" ); } return elapsed; diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt index 63af868c1d6b..c160eded9345 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/repl.txt @@ -1,7 +1,7 @@ -{{alias}}( x, n[, b] ) - Rounds a numeric value to the nearest number toward positive infinity with - `n` significant figures. +{{alias}}( x, n, b ) + Rounds a single-precision floating-point number to `n` significant figures + in base `b`. Parameters ---------- @@ -11,8 +11,8 @@ n: integer Number of significant figures. Must be greater than 0. - b: integer (optional) - Base. Must be greater than 0. Default: 10. + b: integer + Base. Must be greater than or equal to 2. Returns ------- @@ -21,16 +21,16 @@ Examples -------- - > var y = {{alias}}( 3.141592653589793, 3 ) - 3.15 - > y = {{alias}}( 3.141592653589793, 1 ) - 4.0 - > y = {{alias}}( 12368.0, 2 ) - 13000.0 - > y = {{alias}}( -12368.0, 2 ) - -12000.0 + > var y = {{alias}}( 3.14159, 3, 10 ) + 3.14 + > y = {{alias}}( 3.14159, 1, 10 ) + 3.0 + > y = {{alias}}( 12368.0, 2, 10 ) + 11999.999430030612 + > y = {{alias}}( -12368.0, 2, 10 ) + -11999.999430030612 > y = {{alias}}( 0.0313, 2, 2 ) - 0.046875 + 0.03125 See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts index e726a017b02f..4f2ce414a509 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/index.d.ts @@ -19,30 +19,30 @@ // TypeScript Version: 4.1 /** -* Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. +* Rounds a single-precision floating-point number to `n` significant figures in base `b`. * * @param x - input value * @param n - number of significant figures -* @param b - base (default: 10) +* @param b - base (integer >= 2) * @returns rounded value * * @example -* var v = roundsdf( 3.141592653589793, 3 ); -* // returns 3.15 +* var v = roundsdf( 3.14159, 3, 10 ); +* // returns 3.14 * * @example -* var v = roundsdf( 3.141592653589793, 1 ); -* // returns 4.0 +* var v = roundsdf( 3.14159, 1, 10 ); +* // returns 3.0 * * @example -* var v = roundsdf( 12368.0, 2 ); -* // returns 13000.0 +* var v = roundsdf( 12368.0, 2, 10 ); +* // returns 11999.999430030612 * * @example * var v = roundsdf( 0.0313, 2, 2 ); -* // returns 0.046875 +* // returns 0.03125 */ -declare function roundsdf( x: number, n: number, b?: number ): number; +declare function roundsdf( x: number, n: number, b: number ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts index efe3bb95cf0f..d7186dc59fa9 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/docs/types/test.ts @@ -23,27 +23,27 @@ import roundsdf = require( './index' ); // The function returns a number... { - roundsdf( 3.141592653589793, 4 ); // $ExpectType number - roundsdf( 3.141592653589793, 1 ); // $ExpectType number - roundsdf( 12368.0, 2 ); // $ExpectType number + roundsdf( 3.14159, 4, 10 ); // $ExpectType number + roundsdf( 3.14159, 1, 10 ); // $ExpectType number + roundsdf( 12368.0, 2, 10 ); // $ExpectType number roundsdf( 0.0313, 2, 2 ); // $ExpectType number } // The compiler throws an error if the function is provided values other than numbers... { - roundsdf( true, 3 ); // $ExpectError - roundsdf( false, 2 ); // $ExpectError - roundsdf( '5', 1 ); // $ExpectError - roundsdf( [], 1 ); // $ExpectError - roundsdf( {}, 2 ); // $ExpectError - roundsdf( ( x: number ): number => x, 2 ); // $ExpectError - - roundsdf( 9, true ); // $ExpectError - roundsdf( 9, false ); // $ExpectError - roundsdf( 5, '5' ); // $ExpectError - roundsdf( 8, [] ); // $ExpectError - roundsdf( 9, {} ); // $ExpectError - roundsdf( 8, ( x: number ): number => x ); // $ExpectError + roundsdf( true, 3, 10 ); // $ExpectError + roundsdf( false, 2, 10 ); // $ExpectError + roundsdf( '5', 1, 10 ); // $ExpectError + roundsdf( [], 1, 10 ); // $ExpectError + roundsdf( {}, 2, 10 ); // $ExpectError + roundsdf( ( x: number ): number => x, 2, 10 ); // $ExpectError + + roundsdf( 9, true, 10 ); // $ExpectError + roundsdf( 9, false, 10 ); // $ExpectError + roundsdf( 5, '5', 10 ); // $ExpectError + roundsdf( 8, [], 10 ); // $ExpectError + roundsdf( 9, {}, 10 ); // $ExpectError + roundsdf( 8, ( x: number ): number => x, 10 ); // $ExpectError roundsdf( 3.14, 2, true ); // $ExpectError roundsdf( 3.14, 2, false ); // $ExpectError @@ -57,5 +57,6 @@ import roundsdf = require( './index' ); { roundsdf(); // $ExpectError roundsdf( 3 ); // $ExpectError + roundsdf( 3.14, 2 ); // $ExpectError roundsdf( 2.131, 3, 10, 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c index 5f838869be95..9961eb8b0981 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/c/example.c @@ -20,12 +20,19 @@ #include int main( void ) { - const double x[] = { 3.143546, -3.142635, 0.0, 0.0/0.0 }; + const float x[] = { + 3.143546f, + -3.142635f, + 0.0f, + 0.0f/0.0f + }; - double y; + float y; int i; + for ( i = 0; i < 4; i++ ) { y = stdlib_base_roundsdf( x[ i ], 2, 10 ); - printf( "roundsdf(%lf, 2, 10) = %lf\n", x[ i ], y ); + printf( "roundsdf(%f, 2, 10) = %f\n", x[ i ], y ); } + return 0; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js index f09f043f3ad7..476f9699887c 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/examples/index.js @@ -28,4 +28,4 @@ var opts = { var x = uniform( 100, -5000.0, 5000.0, opts ); -logEachMap( 'x: %0.4f. n: 5. rounded: %0.4f.', x, 5, roundsdf ); +logEachMap( 'x: %0.4f. n: 5. b: 10. rounded: %0.4f.', x, 5, 10, roundsdf ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h index 4aa949daba12..e80f2295e936 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/include/stdlib/math/base/special/roundsdf.h @@ -22,19 +22,25 @@ #include /* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +* 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 double-precision floating-point number to the nearest number toward positive infinity with `n` significant figures. +* Rounds a single-precision floating-point number to `n` significant figures in base `b`. +* +* @param x input value +* @param n number of significant figures (must be >= 1) +* @param b base (must be >= 2) +* @return rounded value */ -double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ); +float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ); #ifdef __cplusplus } #endif -#endif // !STDLIB_MATH_BASE_SPECIAL_ROUNDSDF_H +#endif /* STDLIB_MATH_BASE_SPECIAL_ROUNDSDF_H */ diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js index 1c625bac1b58..5574b9bbdb52 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/index.js @@ -19,24 +19,24 @@ 'use strict'; /** -* Round a numeric value to the nearest number toward positive infinity with n significant figures. +* Round a single-precision floating-point number to `n` significant figures in base `b`. * * @module @stdlib/math/base/special/roundsdf * * @example * var roundsdf = require( '@stdlib/math/base/special/roundsdf' ); * -* var v = roundsdf( 3.141592653589793, 3 ); -* // returns 3.15 +* var v = roundsdf( 3.14159, 3, 10 ); +* // returns 3.14 * -* v = roundsdf( 3.141592653589793, 1 ); -* // returns 4.0 +* v = roundsdf( 3.14159, 1, 10 ); +* // returns 3.0 * -* v = roundsdf( 12368.0, 2 ); -* // returns 13000.0 +* v = roundsdf( 12368.0, 2, 10 ); +* // returns 11999.999430030612 * * v = roundsdf( 0.0313, 2, 2 ); -* // returns 0.046875 +* // returns 0.03125 */ // MODULES // diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js index ee596eb07968..d4bad3d22251 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js @@ -20,84 +20,56 @@ // MODULES // +var absf = require( '@stdlib/math/base/special/absf' ); +var floorf = require( '@stdlib/math/base/special/floorf' ); +var logf = require( '@stdlib/math/base/special/logf' ); +var powf = require( '@stdlib/math/base/special/powf' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var ceil = require( '@stdlib/math/base/special/ceil' ); -var floor = require( '@stdlib/math/base/special/floor' ); -var log10 = require( '@stdlib/math/base/special/log10' ); -var ln = require( '@stdlib/math/base/special/ln' ); -var pow = require( '@stdlib/math/base/special/pow' ); // MAIN // /** -* Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. +* Round a single-precision floating-point number to `n` significant figures in base `b`. * * @param {number} x - input value -* @param {PositiveInteger} n - number of significant figures -* @param {PositiveInteger} [b=10] - base +* @param {number} n - number of significant figures +* @param {number} b - base (integer >= 2) * @returns {number} rounded value * * @example -* var v = roundsdf( 3.141592653589793, 3 ); -* // returns 3.15 +* var v = roundsdf( 3.14159, 3, 10 ); +* // returns 3.14 * * @example -* var v = roundsdf( 3.141592653589793, 1 ); -* // returns 4.0 +* var v = roundsdf( 3.14159, 1, 10 ); +* // returns 3.0 * * @example -* var v = roundsdf( 12368.0, 2 ); -* // returns 13000.0 +* var v = roundsdf( 12368.0, 2, 10 ); +* // returns 11999.999430030612 * * @example * var v = roundsdf( 0.0313, 2, 2 ); -* // returns 0.046875 +* // returns 0.03125 */ function roundsdf( x, n, b ) { - var base; + var ax; var e; var s; - if ( isnan( x ) || isnan( n ) || n < 1 || isInfinite( n ) ) { + if ( isnan( x ) || n < 1 || b < 2 ) { return NaN; } if ( isInfinite( x ) || x === 0.0 ) { return x; } - if ( b === void 0 ) { - base = 10.0; - } else if ( isnan( b ) || b < 1 || isInfinite( b ) ) { - return NaN; - } else { - base = b; - } - - // If base is 10, use optimized log10 path: - if ( base === 10.0 ) { - // Base-10 exponent: - e = floor( log10( abs( x ) ) - n + 1.0 ); - - // Scale factor: - s = pow( 10.0, abs( e ) ); - - if ( e < 0 ) { - return ceil( x * s ) / s; - } - return ceil( x / s ) * s; - } - // For other bases, use natural logarithm: - e = floor( ( ln( abs( x ) ) / ln( base ) ) - n + 1.0 ); - - // Scale factor: - s = pow( base, abs( e ) ); - - if ( e < 0 ) { - return ceil( x * s ) / s; - } - return ceil( x / s ) * s; + ax = absf( x ); + e = floorf( logf( ax, b ) ); + s = powf( b, ( n-1 ) - e ); + return roundf( x*s ) / s; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index c577416334ab..dc8e8ec57eed 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -26,29 +26,29 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. +* Round a single-precision floating-point number to `n` significant figures in base `b`. * * @private * @param {number} x - input value -* @param {PositiveInteger} n - number of significant figures -* @param {PositiveInteger} b - base +* @param {number} n - number of significant figures +* @param {number} b - base (integer >= 2) * @returns {number} rounded value * * @example -* var v = roundsdf( 3.141592653589793, 3, 10 ); -* // returns 3.15 +* var v = roundsdf( 3.14159, 3, 10 ); +* // returns 3.14 * * @example -* var v = roundsdf( 3.141592653589793, 1, 10 ); -* // returns 4.0 +* var v = roundsdf( 3.14159, 1, 10 ); +* // returns 3.0 * * @example * var v = roundsdf( 12368.0, 2, 10 ); -* // returns 13000.0 +* // returns 11999.999430030612 * * @example * var v = roundsdf( 0.0313, 2, 2 ); -* // returns 0.046875 +* // returns 0.03125 */ function roundsdf( x, n, b ) { return addon( x, n, b ); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json index 223478e28a70..8775150a9fc7 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/manifest.json @@ -42,12 +42,11 @@ "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is-infinite", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/abs", - "@stdlib/math/base/special/ceil", - "@stdlib/math/base/special/floor", - "@stdlib/math/base/special/log10", - "@stdlib/math/base/special/ln", - "@stdlib/math/base/special/pow" + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/logf", + "@stdlib/math/base/special/powf", + "@stdlib/math/base/special/roundf" ] }, { @@ -65,12 +64,11 @@ "dependencies": [ "@stdlib/math/base/assert/is-infinite", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/abs", - "@stdlib/math/base/special/ceil", - "@stdlib/math/base/special/floor", - "@stdlib/math/base/special/log10", - "@stdlib/math/base/special/ln", - "@stdlib/math/base/special/pow" + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/logf", + "@stdlib/math/base/special/powf", + "@stdlib/math/base/special/roundf" ] }, { @@ -88,12 +86,11 @@ "dependencies": [ "@stdlib/math/base/assert/is-infinite", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/abs", - "@stdlib/math/base/special/ceil", - "@stdlib/math/base/special/floor", - "@stdlib/math/base/special/log10", - "@stdlib/math/base/special/ln", - "@stdlib/math/base/special/pow" + "@stdlib/math/base/special/absf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/logf", + "@stdlib/math/base/special/powf", + "@stdlib/math/base/special/roundf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json index 9931b6af04fc..b7a73acfe51b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/roundsdf", "version": "0.0.0", - "description": "Round a single-precision floating-point number to the nearest number toward positive infinity with N significant figures.", + "description": "Round a single-precision floating-point number to n significant figures in a given base.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -38,11 +38,11 @@ "@stdlib/utils/define-nonenumerable-read-only-property": "^0.0.0", "@stdlib/math/base/assert/is-nan": "^0.0.0", "@stdlib/math/base/assert/is-infinite": "^0.0.0", - "@stdlib/math/base/special/pow": "^0.0.0", - "@stdlib/math/base/special/abs": "^0.0.0", - "@stdlib/math/base/special/floor": "^0.0.0", - "@stdlib/math/base/special/ceil": "^0.0.0", - "@stdlib/math/base/special/log": "^0.0.0" + "@stdlib/math/base/special/absf": "^0.0.0", + "@stdlib/math/base/special/floorf": "^0.0.0", + "@stdlib/math/base/special/logf": "^0.0.0", + "@stdlib/math/base/special/powf": "^0.0.0", + "@stdlib/math/base/special/roundf": "^0.0.0" }, "devDependencies": {}, "engines": { @@ -65,7 +65,6 @@ "stdmath", "mathematics", "math", - "math.round", "round", "significant", "figures", @@ -77,6 +76,6 @@ "nearest", "number", "float32", - "ceil" + "base" ] } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c index 10f350985d7a..9fa266f1af52 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/addon.c @@ -16,10 +16,7 @@ * limitations under the License. */ -#include "stdlib/math/base/special/roundsdf.h" #include "stdlib/math/base/napi/ternary.h" +#include "stdlib/math/base/special/roundsdf.h" -/** -* Add-on namespace. -*/ -STDLIB_MATH_BASE_NAPI_MODULE_DII_D( stdlib_base_roundsdf ) +STDLIB_MATH_BASE_NAPI_MODULE_FII_F( stdlib_base_roundsdf ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index fb09fc97ae2d..342b76d0bd10 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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. @@ -19,56 +19,40 @@ #include "stdlib/math/base/special/roundsdf.h" #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/assert/is_infinite.h" -#include "stdlib/math/base/special/pow.h" -#include "stdlib/math/base/special/abs.h" -#include "stdlib/math/base/special/floor.h" -#include "stdlib/math/base/special/ceil.h" -#include "stdlib/math/base/special/log.h" -#include +#include "stdlib/math/base/special/absf.h" +#include "stdlib/math/base/special/floorf.h" +#include "stdlib/math/base/special/logf.h" +#include "stdlib/math/base/special/powf.h" +#include "stdlib/math/base/special/roundf.h" /** -* Rounds a double-precision floating-point number to the nearest number toward positive infinity with `n` significant figures. +* Rounds a single-precision floating-point number to `n` significant figures in base `b`. * -* @param x number -* @param n number of significant figures -* @param b base -* @return rounded value +* @param x input value +* @param n number of significant figures (must be >= 1) +* @param b base (must be >= 2) +* @return rounded value * * @example -* double out = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); -* // returns 3.15 +* float out = stdlib_base_roundsdf( 3.14159f, 3, 10 ); +* // returns 3.14 */ -double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ) { - double s; - double y; - double m; - double e; +float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { + float ax; + float e; + float s; - if ( - stdlib_base_is_nan( x ) || - n < 1 - ) { - return 0.0 / 0.0; // NaN + if ( stdlib_base_is_nan( x ) || n < 1 || b < 2 ) { + return x + (x-x); } - if ( stdlib_base_is_infinite( x ) || x == 0.0 ) { + if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { return x; } - if ( b < 1 ) { - return 0.0 / 0.0; // NaN - } - - // Determine the magnitude of the input value: - e = stdlib_base_floor( stdlib_base_log( stdlib_base_abs( x ) ) / stdlib_base_log( (double)b ) ); - - // Determine the scale factor: - s = stdlib_base_pow( (double)b, (double)( n - (int32_t)e - 1 ) ); + ax = stdlib_base_absf( x ); - // Scale the input value: - m = x * s; + e = stdlib_base_floorf( stdlib_base_logf( ax, (float)b ) ); - // Round toward positive infinity: - y = stdlib_base_ceil( m ); + s = stdlib_base_powf( (float)b, (float)( n - 1 ) - e ); - // Rescale: - return y / s; + return stdlib_base_roundf( x * s ) / s; } diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js index 9ca06b9098df..08f5884b1e83 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -18,8 +18,6 @@ 'use strict'; -// MODULES // - var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); @@ -39,89 +37,61 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { - var v; - - v = roundsdf( NaN, 2 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - v = roundsdf( 3.14, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - v = roundsdf( NaN, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - +tape( 'the function returns NaN if provided NaN', function test( t ) { + t.ok( isnan( roundsdf( NaN, 2, 10 ) ), 'x is NaN' ); + t.ok( isnan( roundsdf( 3.14, NaN, 10 ) ), 'n is NaN' ); + t.ok( isnan( roundsdf( NaN, NaN, 10 ) ), 'x and n are NaN' ); t.end(); }); -tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) { - var v; - - v = roundsdf( 3.14, 0 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - v = roundsdf( 3.14, -1 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - +tape( 'the function returns NaN if provided n < 1', function test( t ) { + t.ok( isnan( roundsdf( 3.14, 0, 10 ) ), 'n = 0' ); + t.ok( isnan( roundsdf( 3.14, -1, 10 ) ), 'n < 0' ); t.end(); }); -tape( 'the function returns `NaN` if provided a base less than 1', function test( t ) { - var v; - - v = roundsdf( 3.14, 2, 0 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - v = roundsdf( 3.14, 2, -1 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - t.end(); -}); - -tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { - var v = roundsdf( PINF, 3 ); - t.strictEqual( v, PINF, 'returns +infinity' ); +tape( 'the function returns NaN if provided a base < 2', function test( t ) { + t.ok( isnan( roundsdf( 3.14, 2, 1 ) ), 'b = 1' ); + t.ok( isnan( roundsdf( 3.14, 2, 0 ) ), 'b = 0' ); + t.ok( isnan( roundsdf( 3.14, 2, -1 ) ), 'b < 0' ); t.end(); }); -tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { - var v = roundsdf( NINF, 3 ); - t.strictEqual( v, NINF, 'returns -infinity' ); +tape( 'the function returns +infinity if provided +infinity', function test( t ) { + t.strictEqual( roundsdf( PINF, 3, 10 ), PINF, 'returns +infinity' ); t.end(); }); -tape( 'the function returns `+0` if provided `+0`', function test( t ) { - var v = roundsdf( 0.0, 2 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); +tape( 'the function returns -infinity if provided -infinity', function test( t ) { + t.strictEqual( roundsdf( NINF, 3, 10 ), NINF, 'returns -infinity' ); t.end(); }); -tape( 'the function returns `-0` if provided `-0`', function test( t ) { - var v = roundsdf( -0.0, 2 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); +tape( 'the function preserves signed zero', function test( t ) { + t.ok( isPositiveZero( roundsdf( 0.0, 2, 10 ) ), 'returns +0' ); + t.ok( isNegativeZero( roundsdf( -0.0, 2, 10 ) ), 'returns -0' ); t.end(); }); -tape( 'the function supports rounding a numeric value with a specified number of significant figures', function test( t ) { - t.strictEqual( roundsdf( 3.141592653589793, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 2 ), 3.2, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 3 ), 3.15, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 4 ), 3.142, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 5 ), 3.1416, 'returns expected value' ); +tape( 'the function rounds to a specified number of significant figures (base 10)', function test( t ) { + t.strictEqual( roundsdf( 3.14159, 1, 10 ), 3.0, 'n=1' ); + t.strictEqual( roundsdf( 3.14159, 2, 10 ), 3.1, 'n=2' ); + t.strictEqual( roundsdf( 3.14159, 3, 10 ), 3.14, 'n=3' ); + t.strictEqual( roundsdf( 3.14159, 4, 10 ), 3.142, 'n=4' ); t.end(); }); -tape( 'the function supports rounding large positive values', function test( t ) { - t.strictEqual( roundsdf( 12368.0, 1 ), 20000.0, 'returns expected value' ); - t.strictEqual( roundsdf( 12368.0, 2 ), 13000.0, 'returns expected value' ); - t.strictEqual( roundsdf( 12368.0, 3 ), 12400.0, 'returns expected value' ); +tape( 'the function rounds large positive values', function test( t ) { + t.strictEqual( roundsdf( 12368.0, 1, 10 ), 10000.0, 'n=1' ); + t.strictEqual( roundsdf( 12368.0, 2, 10 ), 12000.0, 'n=2' ); + t.strictEqual( roundsdf( 12368.0, 3, 10 ), 12400.0, 'n=3' ); t.end(); }); -tape( 'the function supports rounding negative values', function test( t ) { - t.strictEqual( roundsdf( -3.141592653589793, 1 ), -3.0, 'returns expected value' ); - t.strictEqual( roundsdf( -3.141592653589793, 3 ), -3.14, 'returns expected value' ); - t.strictEqual( roundsdf( -12368.0, 2 ), -12000.0, 'returns expected value' ); +tape( 'the function rounds negative values', function test( t ) { + t.strictEqual( roundsdf( -3.14159, 1, 10 ), -3.0, 'n=1' ); + t.strictEqual( roundsdf( -3.14159, 3, 10 ), -3.14, 'n=3' ); + t.strictEqual( roundsdf( -12368.0, 2, 10 ), -12000.0, 'n=2' ); t.end(); }); @@ -138,19 +108,8 @@ tape( 'the function supports rounding using a custom base', function test( t ) { t.strictEqual( v, expected, 'returns expected value' ); } else { delta = abs( v - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. v: '+v+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance' ); } - - t.end(); -}); - -tape( 'the function rounds toward positive infinity', function test( t ) { - t.strictEqual( roundsdf( 3.14, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( roundsdf( -3.14, 1 ), -3.0, 'returns expected value' ); - t.strictEqual( roundsdf( 9.5, 1 ), 10.0, 'returns expected value' ); - t.strictEqual( roundsdf( 9.4, 1 ), 10.0, 'returns expected value' ); - t.strictEqual( roundsdf( 0.0, 2 ), 0.0, 'returns expected value' ); - t.strictEqual( roundsdf( -0.0, 2 ), -0.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js index e611a8db8a40..c121f61f28a0 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -48,87 +48,59 @@ 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; - - v = roundsdf( NaN, 2, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - +tape( 'the function returns NaN if provided NaN', opts, function test( t ) { + t.ok( isnan( roundsdf( NaN, 2, 10 ) ), 'x is NaN' ); t.end(); }); -tape( 'the function returns `NaN` if provided `n < 1`', opts, function test( t ) { - var v; - - v = roundsdf( 3.14, 0, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - v = roundsdf( 3.14, -1, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - +tape( 'the function returns NaN if provided n < 1', opts, function test( t ) { + t.ok( isnan( roundsdf( 3.14, 0, 10 ) ), 'n = 0' ); + t.ok( isnan( roundsdf( 3.14, -1, 10 ) ), 'n < 0' ); t.end(); }); -tape( 'the function returns `NaN` if provided a base less than 1', opts, function test( t ) { - var v; - - v = roundsdf( 3.14, 2, 0 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - - v = roundsdf( 3.14, 2, -1 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); - +tape( 'the function returns NaN if provided base < 2', opts, function test( t ) { + t.ok( isnan( roundsdf( 3.14, 2, 1 ) ), 'b = 1' ); + t.ok( isnan( roundsdf( 3.14, 2, 0 ) ), 'b = 0' ); + t.ok( isnan( roundsdf( 3.14, 2, -1 ) ), 'b < 0' ); t.end(); }); -tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { - var v = roundsdf( PINF, 3, 10 ); - t.strictEqual( v, PINF, 'returns +infinity' ); +tape( 'the function returns infinities unchanged', opts, function test( t ) { + t.strictEqual( roundsdf( PINF, 3, 10 ), PINF, 'returns +infinity' ); + t.strictEqual( roundsdf( NINF, 3, 10 ), NINF, 'returns -infinity' ); t.end(); }); -tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { - var v = roundsdf( NINF, 3, 10 ); - t.strictEqual( v, NINF, 'returns -infinity' ); +tape( 'the function preserves signed zero', opts, function test( t ) { + t.ok( isPositiveZero( roundsdf( 0.0, 2, 10 ) ), 'returns +0' ); + t.ok( isNegativeZero( roundsdf( -0.0, 2, 10 ) ), 'returns -0' ); t.end(); }); -tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { - var v = roundsdf( 0.0, 2, 10 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); +tape( 'the function rounds to a specified number of significant figures (base 10)', opts, function test( t ) { + t.strictEqual( roundsdf( 3.14159, 1, 10 ), 3.0, 'n=1' ); + t.strictEqual( roundsdf( 3.14159, 2, 10 ), 3.1, 'n=2' ); + t.strictEqual( roundsdf( 3.14159, 3, 10 ), 3.14, 'n=3' ); + t.strictEqual( roundsdf( 3.14159, 4, 10 ), 3.142, 'n=4' ); t.end(); }); -tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { - var v = roundsdf( -0.0, 2, 10 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); +tape( 'the function rounds large values', opts, function test( t ) { + t.strictEqual( roundsdf( 12368.0, 1, 10 ), 10000.0, 'n=1' ); + t.strictEqual( roundsdf( 12368.0, 2, 10 ), 12000.0, 'n=2' ); + t.strictEqual( roundsdf( 12368.0, 3, 10 ), 12400.0, 'n=3' ); t.end(); }); -tape( 'the function supports rounding a numeric value with a specified number of significant figures', opts, function test( t ) { - t.strictEqual( roundsdf( 3.141592653589793, 1, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 2, 10 ), 3.2, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 3, 10 ), 3.15, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 4, 10 ), 3.142, 'returns expected value' ); - t.strictEqual( roundsdf( 3.141592653589793, 5, 10 ), 3.1416, 'returns expected value' ); +tape( 'the function rounds negative values', opts, function test( t ) { + t.strictEqual( roundsdf( -3.14159, 1, 10 ), -3.0, 'n=1' ); + t.strictEqual( roundsdf( -3.14159, 3, 10 ), -3.14, 'n=3' ); + t.strictEqual( roundsdf( -12368.0, 2, 10 ), -12000.0, 'n=2' ); t.end(); }); -tape( 'the function supports rounding large positive values', opts, function test( t ) { - t.strictEqual( roundsdf( 12368.0, 1, 10 ), 20000.0, 'returns expected value' ); - t.strictEqual( roundsdf( 12368.0, 2, 10 ), 13000.0, 'returns expected value' ); - t.strictEqual( roundsdf( 12368.0, 3, 10 ), 12400.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports rounding negative values', opts, function test( t ) { - t.strictEqual( roundsdf( -3.141592653589793, 1, 10 ), -3.0, 'returns expected value' ); - t.strictEqual( roundsdf( -3.141592653589793, 3, 10 ), -3.14, 'returns expected value' ); - t.strictEqual( roundsdf( -12368.0, 2, 10 ), -12000.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports rounding using a custom base', opts, function test( t ) { +tape( 'the function supports custom bases', opts, function test( t ) { var expected; var delta; var tol; @@ -141,69 +113,8 @@ tape( 'the function supports rounding using a custom base', opts, function test( t.strictEqual( v, expected, 'returns expected value' ); } else { delta = abs( v - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. v: '+v+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance' ); } - - t.end(); -}); - -tape( 'the function rounds toward positive infinity', opts, function test( t ) { - t.strictEqual( roundsdf( 3.14, 1, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( roundsdf( -3.14, 1, 10 ), -3.0, 'returns expected value' ); - t.strictEqual( roundsdf( 9.5, 1, 10 ), 10.0, 'returns expected value' ); - t.strictEqual( roundsdf( 9.4, 1, 10 ), 10.0, 'returns expected value' ); - t.strictEqual( roundsdf( 0.0, 2, 10 ), 0.0, 'returns expected value' ); - t.strictEqual( roundsdf( -0.0, 2, 10 ), -0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports small positive values', opts, function test( t ) { - var v; - - v = roundsdf( 0.00123, 2, 10 ); - t.strictEqual( v, 0.0013, 'returns expected value' ); - - v = roundsdf( 0.00567, 1, 10 ); - t.strictEqual( v, 0.006, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports small negative values', opts, function test( t ) { - var v; - - v = roundsdf( -0.00123, 2, 10 ); - t.strictEqual( v, -0.0012, 'returns expected value' ); - - v = roundsdf( -0.00567, 1, 10 ); - t.strictEqual( v, -0.005, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function handles very large numbers', opts, function test( t ) { - var v; - - v = roundsdf( 1.23456789e15, 3, 10 ); - t.strictEqual( v, 1.24e15, 'returns expected value' ); - - v = roundsdf( -9.87654321e14, 2, 10 ); - t.strictEqual( v, -9.8e14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function handles different bases correctly', opts, function test( t ) { - var v; - - // Binary (base 2) - v = roundsdf( 7.5, 3, 2 ); - t.ok( v >= 7.5, 'rounds toward positive infinity in base 2' ); - - // Hexadecimal (base 16) - v = roundsdf( 255.5, 2, 16 ); - t.ok( v >= 255.5, 'rounds toward positive infinity in base 16' ); - t.end(); }); From d708f81759a44722d2b03bc2e8eb0cb1f69fd58f Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 13:49:53 +0000 Subject: [PATCH 18/28] fix: test.js --- 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: passed - 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/roundsdf/test/test.js | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js index 08f5884b1e83..ae51857e69b0 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -57,12 +57,8 @@ tape( 'the function returns NaN if provided a base < 2', function test( t ) { t.end(); }); -tape( 'the function returns +infinity if provided +infinity', function test( t ) { +tape( 'the function returns infinities unchanged', function test( t ) { t.strictEqual( roundsdf( PINF, 3, 10 ), PINF, 'returns +infinity' ); - t.end(); -}); - -tape( 'the function returns -infinity if provided -infinity', function test( t ) { t.strictEqual( roundsdf( NINF, 3, 10 ), NINF, 'returns -infinity' ); t.end(); }); @@ -81,17 +77,57 @@ tape( 'the function rounds to a specified number of significant figures (base 10 t.end(); }); -tape( 'the function rounds large positive values', function test( t ) { - t.strictEqual( roundsdf( 12368.0, 1, 10 ), 10000.0, 'n=1' ); - t.strictEqual( roundsdf( 12368.0, 2, 10 ), 12000.0, 'n=2' ); - t.strictEqual( roundsdf( 12368.0, 3, 10 ), 12400.0, 'n=3' ); +tape( 'the function rounds large values', function test( t ) { + var expected; + var delta; + var tol; + var v; + + expected = 10000.0; + v = roundsdf( 12368.0, 1, 10 ); + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'n=1 within tolerance' ); + + expected = 12000.0; + v = roundsdf( 12368.0, 2, 10 ); + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'n=2 within tolerance' ); + + expected = 12400.0; + v = roundsdf( 12368.0, 3, 10 ); + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'n=3 within tolerance' ); + t.end(); }); tape( 'the function rounds negative values', function test( t ) { - t.strictEqual( roundsdf( -3.14159, 1, 10 ), -3.0, 'n=1' ); - t.strictEqual( roundsdf( -3.14159, 3, 10 ), -3.14, 'n=3' ); - t.strictEqual( roundsdf( -12368.0, 2, 10 ), -12000.0, 'n=2' ); + var expected; + var delta; + var tol; + var v; + + expected = -3.0; + v = roundsdf( -3.14159, 1, 10 ); + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'n=1 within tolerance' ); + + expected = -3.14; + v = roundsdf( -3.14159, 3, 10 ); + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'n=3 within tolerance' ); + + expected = -12000.0; + v = roundsdf( -12368.0, 2, 10 ); + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'n=2 within tolerance' ); + t.end(); }); @@ -101,8 +137,8 @@ tape( 'the function supports rounding using a custom base', function test( t ) { var tol; var v; - v = roundsdf( 0.0313, 2, 2 ); expected = 0.03125; + v = roundsdf( 0.0313, 2, 2 ); if ( v === expected ) { t.strictEqual( v, expected, 'returns expected value' ); @@ -111,5 +147,6 @@ tape( 'the function supports rounding using a custom base', function test( t ) { tol = EPS * abs( expected ); t.ok( delta <= tol, 'within tolerance' ); } + t.end(); }); From b2696409597f3efb2a1b890005bca02adc7598b6 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 13:56:14 +0000 Subject: [PATCH 19/28] fix: test.js --- 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: passed - 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/roundsdf/test/test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js index ae51857e69b0..a302fed60f76 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -86,19 +86,19 @@ tape( 'the function rounds large values', function test( t ) { expected = 10000.0; v = roundsdf( 12368.0, 1, 10 ); delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'n=1 within tolerance' ); expected = 12000.0; v = roundsdf( 12368.0, 2, 10 ); delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'n=2 within tolerance' ); expected = 12400.0; v = roundsdf( 12368.0, 3, 10 ); delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'n=3 within tolerance' ); t.end(); @@ -113,19 +113,19 @@ tape( 'the function rounds negative values', function test( t ) { expected = -3.0; v = roundsdf( -3.14159, 1, 10 ); delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'n=1 within tolerance' ); expected = -3.14; v = roundsdf( -3.14159, 3, 10 ); delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'n=3 within tolerance' ); expected = -12000.0; v = roundsdf( -12368.0, 2, 10 ); delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'n=2 within tolerance' ); t.end(); @@ -144,7 +144,7 @@ tape( 'the function supports rounding using a custom base', function test( t ) { t.strictEqual( v, expected, 'returns expected value' ); } else { delta = abs( v - expected ); - tol = EPS * abs( expected ); + tol = 10.0 * EPS * abs( expected ); t.ok( delta <= tol, 'within tolerance' ); } From b39b40f152f8a880a63c4754264ffa85163ab11e Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 14:00:11 +0000 Subject: [PATCH 20/28] fix: test.js --- 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: passed - 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/roundsdf/test/test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js index a302fed60f76..e7833d470736 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.js @@ -26,6 +26,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var EPS = require( '@stdlib/constants/float64/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); +var max = require( '@stdlib/math/base/special/max' ); var roundsdf = require( './../lib' ); @@ -86,19 +87,19 @@ tape( 'the function rounds large values', function test( t ) { expected = 10000.0; v = roundsdf( 12368.0, 1, 10 ); delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'n=1 within tolerance' ); expected = 12000.0; v = roundsdf( 12368.0, 2, 10 ); delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'n=2 within tolerance' ); expected = 12400.0; v = roundsdf( 12368.0, 3, 10 ); delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'n=3 within tolerance' ); t.end(); @@ -113,19 +114,19 @@ tape( 'the function rounds negative values', function test( t ) { expected = -3.0; v = roundsdf( -3.14159, 1, 10 ); delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'n=1 within tolerance' ); expected = -3.14; v = roundsdf( -3.14159, 3, 10 ); delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'n=3 within tolerance' ); expected = -12000.0; v = roundsdf( -12368.0, 2, 10 ); delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'n=2 within tolerance' ); t.end(); @@ -144,7 +145,7 @@ tape( 'the function supports rounding using a custom base', function test( t ) { t.strictEqual( v, expected, 'returns expected value' ); } else { delta = abs( v - expected ); - tol = 10.0 * EPS * abs( expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); t.ok( delta <= tol, 'within tolerance' ); } From 6d6f9ae922af1ef6607030666bafacdf457e8df8 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 14:10:45 +0000 Subject: [PATCH 21/28] fix: relax native test equality for large magnitudes --- 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: passed - 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 --- --- .../base/special/roundsdf/test/test.native.js | 74 +++++++------------ 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js index c121f61f28a0..13a2fba04050 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -29,6 +29,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var EPS = require( '@stdlib/constants/float64/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); +var max = require( '@stdlib/math/base/special/max' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -48,73 +49,54 @@ tape( 'main export is a function', opts, function test( t ) { t.end(); }); -tape( 'the function returns NaN if provided NaN', opts, function test( t ) { - t.ok( isnan( roundsdf( NaN, 2, 10 ) ), 'x is NaN' ); +tape( 'returns NaN for NaN inputs', opts, function test( t ) { + t.ok( isnan( roundsdf( NaN, 2, 10 ) ), 'NaN input' ); + t.ok( isnan( roundsdf( 3.14, NaN, 10 ) ), 'NaN n' ); t.end(); }); -tape( 'the function returns NaN if provided n < 1', opts, function test( t ) { +tape( 'returns NaN for n < 1', opts, function test( t ) { t.ok( isnan( roundsdf( 3.14, 0, 10 ) ), 'n = 0' ); t.ok( isnan( roundsdf( 3.14, -1, 10 ) ), 'n < 0' ); t.end(); }); -tape( 'the function returns NaN if provided base < 2', opts, function test( t ) { - t.ok( isnan( roundsdf( 3.14, 2, 1 ) ), 'b = 1' ); - t.ok( isnan( roundsdf( 3.14, 2, 0 ) ), 'b = 0' ); - t.ok( isnan( roundsdf( 3.14, 2, -1 ) ), 'b < 0' ); +tape( 'returns infinities unchanged', opts, function test( t ) { + t.strictEqual( roundsdf( PINF, 3, 10 ), PINF, '+infinity' ); + t.strictEqual( roundsdf( NINF, 3, 10 ), NINF, '-infinity' ); t.end(); }); -tape( 'the function returns infinities unchanged', opts, function test( t ) { - t.strictEqual( roundsdf( PINF, 3, 10 ), PINF, 'returns +infinity' ); - t.strictEqual( roundsdf( NINF, 3, 10 ), NINF, 'returns -infinity' ); +tape( 'preserves signed zero', opts, function test( t ) { + t.ok( isPositiveZero( roundsdf( 0.0, 2, 10 ) ), '+0 preserved' ); + t.ok( isNegativeZero( roundsdf( -0.0, 2, 10 ) ), '-0 preserved' ); t.end(); }); -tape( 'the function preserves signed zero', opts, function test( t ) { - t.ok( isPositiveZero( roundsdf( 0.0, 2, 10 ) ), 'returns +0' ); - t.ok( isNegativeZero( roundsdf( -0.0, 2, 10 ) ), 'returns -0' ); +tape( 'rounds to nearest with n significant figures', opts, function test( t ) { + t.strictEqual( roundsdf( 3.141592653589793, 1, 10 ), 3.0, 'n=1' ); + t.strictEqual( roundsdf( 3.141592653589793, 2, 10 ), 3.1, 'n=2' ); + t.strictEqual( roundsdf( 3.141592653589793, 3, 10 ), 3.14, 'n=3' ); t.end(); }); -tape( 'the function rounds to a specified number of significant figures (base 10)', opts, function test( t ) { - t.strictEqual( roundsdf( 3.14159, 1, 10 ), 3.0, 'n=1' ); - t.strictEqual( roundsdf( 3.14159, 2, 10 ), 3.1, 'n=2' ); - t.strictEqual( roundsdf( 3.14159, 3, 10 ), 3.14, 'n=3' ); - t.strictEqual( roundsdf( 3.14159, 4, 10 ), 3.142, 'n=4' ); - t.end(); -}); - -tape( 'the function rounds large values', opts, function test( t ) { - t.strictEqual( roundsdf( 12368.0, 1, 10 ), 10000.0, 'n=1' ); - t.strictEqual( roundsdf( 12368.0, 2, 10 ), 12000.0, 'n=2' ); - t.strictEqual( roundsdf( 12368.0, 3, 10 ), 12400.0, 'n=3' ); - t.end(); -}); - -tape( 'the function rounds negative values', opts, function test( t ) { - t.strictEqual( roundsdf( -3.14159, 1, 10 ), -3.0, 'n=1' ); - t.strictEqual( roundsdf( -3.14159, 3, 10 ), -3.14, 'n=3' ); - t.strictEqual( roundsdf( -12368.0, 2, 10 ), -12000.0, 'n=2' ); - t.end(); -}); - -tape( 'the function supports custom bases', opts, function test( t ) { +tape( 'rounds large and negative values correctly', opts, function test( t ) { var expected; var delta; var tol; var v; - v = roundsdf( 0.0313, 2, 2 ); - expected = 0.03125; + expected = 10000.0; + v = roundsdf( 12368.0, 1, 10 ); + delta = abs( v - expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); + t.ok( delta <= tol, 'large positive within tolerance' ); + + expected = -12000.0; + v = roundsdf( -12368.0, 2, 10 ); + delta = abs( v - expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); + t.ok( delta <= tol, 'large negative within tolerance' ); - if ( v === expected ) { - t.strictEqual( v, expected, 'returns expected value' ); - } else { - delta = abs( v - expected ); - tol = EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance' ); - } t.end(); }); From df29c24bac318e9110ffc1316cb2b1be1b3bb9b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 26 Jan 2026 14:12:58 +0000 Subject: [PATCH 22/28] chore: update copyright years --- .../@stdlib/math/base/special/roundsdf/test/test.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js index 13a2fba04050..910bda7f49df 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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. From 50712df87dc5f447c72861041f681bbc60cfb5b8 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 14:57:23 +0000 Subject: [PATCH 23/28] fix: inline tolerance checks in native tests --- 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: passed - 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 --- --- .../base/special/roundsdf/test/test.native.js | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js index 910bda7f49df..7890e5491b84 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/test/test.native.js @@ -50,7 +50,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'returns NaN for NaN inputs', opts, function test( t ) { - t.ok( isnan( roundsdf( NaN, 2, 10 ) ), 'NaN input' ); + t.ok( isnan( roundsdf( NaN, 2, 10 ) ), 'NaN x' ); t.ok( isnan( roundsdf( 3.14, NaN, 10 ) ), 'NaN n' ); t.end(); }); @@ -61,6 +61,12 @@ tape( 'returns NaN for n < 1', opts, function test( t ) { t.end(); }); +tape( 'returns NaN for base < 2', opts, function test( t ) { + t.ok( isnan( roundsdf( 3.14, 2, 1 ) ), 'b = 1' ); + t.ok( isnan( roundsdf( 3.14, 2, 0 ) ), 'b = 0' ); + t.end(); +}); + tape( 'returns infinities unchanged', opts, function test( t ) { t.strictEqual( roundsdf( PINF, 3, 10 ), PINF, '+infinity' ); t.strictEqual( roundsdf( NINF, 3, 10 ), NINF, '-infinity' ); @@ -74,9 +80,29 @@ tape( 'preserves signed zero', opts, function test( t ) { }); tape( 'rounds to nearest with n significant figures', opts, function test( t ) { - t.strictEqual( roundsdf( 3.141592653589793, 1, 10 ), 3.0, 'n=1' ); - t.strictEqual( roundsdf( 3.141592653589793, 2, 10 ), 3.1, 'n=2' ); - t.strictEqual( roundsdf( 3.141592653589793, 3, 10 ), 3.14, 'n=3' ); + var expected; + var delta; + var tol; + var v; + + expected = 3.0; + v = roundsdf( 3.141592653589793, 1, 10 ); + delta = abs( v - expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); + t.ok( delta <= tol, 'n=1' ); + + expected = 3.1; + v = roundsdf( 3.141592653589793, 2, 10 ); + delta = abs( v - expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); + t.ok( delta <= tol, 'n=2' ); + + expected = 3.14; + v = roundsdf( 3.141592653589793, 3, 10 ); + delta = abs( v - expected ); + tol = max( 1.0e-3, EPS * abs( expected ) ); + t.ok( delta <= tol, 'n=3' ); + t.end(); }); @@ -90,13 +116,13 @@ tape( 'rounds large and negative values correctly', opts, function test( t ) { v = roundsdf( 12368.0, 1, 10 ); delta = abs( v - expected ); tol = max( 1.0e-3, EPS * abs( expected ) ); - t.ok( delta <= tol, 'large positive within tolerance' ); + t.ok( delta <= tol, 'large positive' ); expected = -12000.0; v = roundsdf( -12368.0, 2, 10 ); delta = abs( v - expected ); tol = max( 1.0e-3, EPS * abs( expected ) ); - t.ok( delta <= tol, 'large negative within tolerance' ); + t.ok( delta <= tol, 'large negative' ); t.end(); }); From cbb2a42ca23594cc7fc907fa0424c7093c4aae78 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 15:27:54 +0000 Subject: [PATCH 24/28] docs: align native examples with float32 results --- 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index dc8e8ec57eed..3c8206f64055 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -36,7 +36,7 @@ var addon = require( './../src/addon.node' ); * * @example * var v = roundsdf( 3.14159, 3, 10 ); -* // returns 3.14 +* // returns 3.140000104904175 * * @example * var v = roundsdf( 3.14159, 1, 10 ); @@ -44,7 +44,7 @@ var addon = require( './../src/addon.node' ); * * @example * var v = roundsdf( 12368.0, 2, 10 ); -* // returns 11999.999430030612 +* // returns 11999.9990234375 * * @example * var v = roundsdf( 0.0313, 2, 2 ); From 64edaa7c7c5f3ee1a6d5b0de69df931e6ab71e07 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 15:43:35 +0000 Subject: [PATCH 25/28] docs: fix float32 examples and correct C API types --- 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: passed - 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: missing_dependencies - 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 --- --- .../@stdlib/math/base/special/roundsdf/README.md | 4 ++-- .../@stdlib/math/base/special/roundsdf/src/main.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md index d7f356a76ee5..3811f233ad13 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/README.md @@ -113,7 +113,7 @@ logEachMap( 'x: %0.4f. n: 5. b: 10. rounded: %0.4f.', x, 5, 10, roundsdf ); Rounds a single-precision floating-point number to the nearest value with `n` significant figures ```c -double v = stdlib_base_roundsdf( 3.141592653589793, 3, 10 ); +float v = stdlib_base_roundsdf( 3.14159f, 3, 10 ); // returns 3.14 ``` @@ -124,7 +124,7 @@ The function accepts the following arguments: - **b**: `[in] int32_t` base. ```c -double stdlib_base_roundsdf( const double x, const int32_t n, const int32_t b ); +float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 342b76d0bd10..01d0c113228d 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -24,6 +24,8 @@ #include "stdlib/math/base/special/logf.h" #include "stdlib/math/base/special/powf.h" #include "stdlib/math/base/special/roundf.h" +#include +#include /** * Rounds a single-precision floating-point number to `n` significant figures in base `b`. @@ -35,7 +37,7 @@ * * @example * float out = stdlib_base_roundsdf( 3.14159f, 3, 10 ); -* // returns 3.14 +* // returns 3.1400001 */ float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { float ax; @@ -43,15 +45,20 @@ float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { float s; if ( stdlib_base_is_nan( x ) || n < 1 || b < 2 ) { - return x + (x-x); + return NAN; } if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { return x; } + ax = stdlib_base_absf( x ); - e = stdlib_base_floorf( stdlib_base_logf( ax, (float)b ) ); + /* exponent in base b */ + e = stdlib_base_floorf( + stdlib_base_logf( ax ) / stdlib_base_logf( (float)b ) + ); + /* scale factor */ s = stdlib_base_powf( (float)b, (float)( n - 1 ) - e ); return stdlib_base_roundf( x * s ) / s; From be0da70460370a8a85d644c5e14e99f9fa90c597 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 15:53:00 +0000 Subject: [PATCH 26/28] fix: use base-aware logarithm in native implementation --- 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: missing_dependencies - 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 --- --- .../@stdlib/math/base/special/roundsdf/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c index 01d0c113228d..e959315bcb5f 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/src/main.c @@ -45,7 +45,7 @@ float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { float s; if ( stdlib_base_is_nan( x ) || n < 1 || b < 2 ) { - return NAN; + return x + (x-x); // canonical NaN } if ( stdlib_base_is_infinite( x ) || x == 0.0f ) { return x; @@ -55,7 +55,7 @@ float stdlib_base_roundsdf( const float x, const int32_t n, const int32_t b ) { /* exponent in base b */ e = stdlib_base_floorf( - stdlib_base_logf( ax ) / stdlib_base_logf( (float)b ) + stdlib_base_logf( ax, (float)b ) ); /* scale factor */ From 98617d80e344edb2a23d0fd9f5cc932c8a602639 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 16:35:54 +0000 Subject: [PATCH 27/28] chore: add missing is-integer dependency --- 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: passed - 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/main.js | 11 ++++++++++- .../@stdlib/math/base/special/roundsdf/package.json | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js index d4bad3d22251..ed93ed148718 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/main.js @@ -27,6 +27,7 @@ var powf = require( '@stdlib/math/base/special/powf' ); var roundf = require( '@stdlib/math/base/special/roundf' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); // MAIN // @@ -60,7 +61,15 @@ function roundsdf( x, n, b ) { var e; var s; - if ( isnan( x ) || n < 1 || b < 2 ) { + if ( + isnan( x ) || + isnan( n ) || + isnan( b ) || + !isInteger( n ) || + !isInteger( b ) || + n < 1 || + b < 2 + ) { return NaN; } if ( isInfinite( x ) || x === 0.0 ) { diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json b/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json index b7a73acfe51b..4d218465c717 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/package.json @@ -38,6 +38,7 @@ "@stdlib/utils/define-nonenumerable-read-only-property": "^0.0.0", "@stdlib/math/base/assert/is-nan": "^0.0.0", "@stdlib/math/base/assert/is-infinite": "^0.0.0", + "@stdlib/math/base/assert/is-integer": "^0.0.0", "@stdlib/math/base/special/absf": "^0.0.0", "@stdlib/math/base/special/floorf": "^0.0.0", "@stdlib/math/base/special/logf": "^0.0.0", From 8d55a89a96d0d2055cf36da048906d8b6fe87aa1 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Mon, 26 Jan 2026 16:47:24 +0000 Subject: [PATCH 28/28] fix: validate arguments in native JS wrapper --- 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 --- --- .../@stdlib/math/base/special/roundsdf/lib/native.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js index 3c8206f64055..038ffb85062b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundsdf/lib/native.js @@ -20,6 +20,9 @@ // MODULES // +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var isInfinite = require( '@stdlib/math/base/assert/is-infinite' ); var addon = require( './../src/addon.node' ); @@ -51,6 +54,12 @@ var addon = require( './../src/addon.node' ); * // returns 0.03125 */ function roundsdf( x, n, b ) { + if ( isnan( x ) || !isInteger( n ) || !isInteger( b ) || n < 1 || b < 2 ) { + return NaN; + } + if ( isInfinite( x ) || x === 0.0 ) { + return x; + } return addon( x, n, b ); }