From 45b233d5a3a2521a388a29fa15468de3e89bb0f7 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Tue, 20 Jan 2026 20:12:38 +0000 Subject: [PATCH 1/2] feat: add math/base/special/roundbf --- 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/roundbf/README.md | 196 ++++++++++++++++++ .../special/roundbf/benchmark/benchmark.js | 56 +++++ .../roundbf/benchmark/benchmark.native.js | 66 ++++++ .../roundbf/benchmark/c/native/Makefile | 146 +++++++++++++ .../roundbf/benchmark/c/native/benchmark.c | 139 +++++++++++++ .../math/base/special/roundbf/binding.gyp | 170 +++++++++++++++ .../math/base/special/roundbf/docs/repl.txt | 32 +++ .../special/roundbf/docs/types/index.d.ts | 56 +++++ .../base/special/roundbf/docs/types/test.ts | 51 +++++ .../base/special/roundbf/examples/c/Makefile | 146 +++++++++++++ .../base/special/roundbf/examples/c/example.c | 35 ++++ .../base/special/roundbf/examples/index.js | 31 +++ .../math/base/special/roundbf/include.gypi | 53 +++++ .../stdlib/math/base/special/roundbf.h | 46 ++++ .../math/base/special/roundbf/lib/index.js | 49 +++++ .../math/base/special/roundbf/lib/main.js | 82 ++++++++ .../math/base/special/roundbf/lib/native.js | 51 +++++ .../math/base/special/roundbf/manifest.json | 81 ++++++++ .../math/base/special/roundbf/package.json | 71 +++++++ .../math/base/special/roundbf/src/Makefile | 70 +++++++ .../math/base/special/roundbf/src/addon.c | 22 ++ .../math/base/special/roundbf/src/main.c | 59 ++++++ .../math/base/special/roundbf/test/test.js | 77 +++++++ .../base/special/roundbf/test/test.native.js | 83 ++++++++ 24 files changed, 1868 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/include/stdlib/math/base/special/roundbf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/roundbf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/README.md b/lib/node_modules/@stdlib/math/base/special/roundbf/README.md new file mode 100644 index 000000000000..62b42c838726 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/README.md @@ -0,0 +1,196 @@ + + +# roundbf + +> Round a single-precision floating-point number to the nearest base-b floating-point value. + +
+ +## Usage + +```javascript +var roundbf = require( '@stdlib/math/base/special/roundbf' ); +``` + +#### roundbf( x, b ) + +Rounds a single-precision floating-point number to the nearest base-b floating-point value. + +```javascript +// Binary rounding: +var v = roundbf( 7.9, 2 ); +// returns NaN + +// Decimal rounding: +v = roundbf( 9.1, 10 ); +// returns NaN + +// Preserve signed zero: +v = roundbf( -0.0, 2 ); +// returns -0.0 +``` + +
+ + + +
+ +## Notes + +- Due to rounding error in [floating-point numbers][ieee754], rounding may **not** be exact. For example, +- The function rounds values on a **logarithmic scale** (to the nearest power of `b`) + +```javascript +roundbf( 0.1 + 0.2, 10 ); +// may not equal exactly 0.3 +``` + +
+ + + +
+ +## Examples + +```javascript +var roundbf = require( '@stdlib/math/base/special/roundbf' ); + +var x = [ -7.9, -3.5, -1.2, 0.0, 1.2, 3.5, 7.9 ]; +var b = 2; +var i; + +for ( i = 0; i < x.length; i++ ) { + console.log( 'x: %f. base: %d. rounded: %f', x[ i ], b, roundbf( x[ i ], b ) ); +} +``` + +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/roundbf.h" +``` + +#### stdlib_base_roundbf( x, b ) + +Rounds a single-precision floating-point number to the nearest `base-b` floating-point value. + +```c +float out = stdlib_base_roundbf( 7.9f, 2 ); +// returns 8.0f +``` + +The function accepts the following arguments: + +- **x**: `[in] float` input value. +- **b**: `[in] int32_t` base. + +```c +float stdlib_base_roundbf( const float x, const int32_t b ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/roundbf.h" +#include +#include + +int main( void ) { + const float x[] = { -7.9f, -3.5f, 0.0f, 3.5f, 7.9f }; + const int32_t b[] = { 2, 10, 2, 2, 10 }; + + float v; + int i; + for ( i = 0; i < 5; i++ ) { + v = stdlib_base_roundbf( x[ i ], b[ i ] ); + printf( "roundbf(%f, %d) = %f\n", x[ i ], b[ i ], v ); + } +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js new file mode 100644 index 000000000000..a68d184c5587 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var roundbf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + // Generate float32 input values: + x = uniform( 100, -5.0e6, 5.0e6, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = roundbf( x[ i % x.length ], 2 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + 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/roundbf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..d7ab998f61ee --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.native.js @@ -0,0 +1,66 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var roundbf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( roundbf instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var x; + var y; + var i; + + // Generate float32 input values: + x = uniform( 100, -5.0e6, 5.0e6, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = roundbf( x[ i % x.length ], 2 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + 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/roundbf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# 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/roundbf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..1c5f29aaaa09 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/benchmark.c @@ -0,0 +1,139 @@ +/** +* @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/roundbf.h" + +#include +#include +#include +#include +#include + +#define NAME "roundbf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmark results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random float on the interval [0,1). +* +* @return random float +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float x[ 100 ]; + float y; + double t; + double elapsed; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1.0e7f * rand_float() ) - 5.0e6f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_roundbf( x[ i%100 ], 2 ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + /* Seed the random number generator: */ + srand( (unsigned int)time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp @@ -0,0 +1,170 @@ +# @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. + +# 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/roundbf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/roundbf/docs/repl.txt new file mode 100644 index 000000000000..f46d90b967eb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( x, b ) + Rounds a single-precision floating-point number to the nearest base-b + floating-point value. + + Due to floating-point rounding error, rounding may not be exact. + + Parameters + ---------- + x: number + Input value. + + b: integer + Integer base (must be greater than or equal to 2). + + Returns + ------- + y: number + Rounded value. + + Examples + -------- + > var y = {{alias}}( 7.9, 2 ) + NaN + > y = {{alias}}( 9.1, 10 ) + NaN + > y = {{alias}}( 0.0, 2 ) + 0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/index.d.ts new file mode 100644 index 000000000000..46ba3f020c64 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Rounds a single-precision floating-point number to the nearest base-b +* floating-point value. +* +* ## Notes +* +* - The function rounds to the nearest value representable as +* \\( m \\times b^k \\), where \\( m \\) is a significand and \\( k \\) +* is an integer exponent. +* - Due to floating-point rounding error, rounding may not be exact. +* +* @param x - input value +* @param b - integer base (must be >= 2) +* @returns rounded value +* +* @example +* // Binary rounding: +* var v = roundbf( 7.9, 2 ); +* // returns NaN +* +* @example +* // Decimal rounding: +* var v = roundbf( 9.1, 10 ); +* // returns NaN +* +* @example +* // Preserve zero: +* var v = roundbf( 0.0, 2 ); +* // returns 0.0 +*/ +declare function roundbf( x: number, b: number ): number; + + +// EXPORTS // + +export = roundbf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/test.ts new file mode 100644 index 000000000000..c856051df35f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/docs/types/test.ts @@ -0,0 +1,51 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import roundbf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + roundbf( 3.141592653589793, 2 ); // $ExpectType number + roundbf( 9.1, 10 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + roundbf( true, 2 ); // $ExpectError + roundbf( false, 2 ); // $ExpectError + roundbf( '5', 2 ); // $ExpectError + roundbf( [], 2 ); // $ExpectError + roundbf( {}, 2 ); // $ExpectError + roundbf( ( x: number ): number => x, 2 ); // $ExpectError + + roundbf( 9, true ); // $ExpectError + roundbf( 9, false ); // $ExpectError + roundbf( 5, '5' ); // $ExpectError + roundbf( 8, [] ); // $ExpectError + roundbf( 9, {} ); // $ExpectError + roundbf( 8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + roundbf(); // $ExpectError + roundbf( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# 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/roundbf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/example.c new file mode 100644 index 000000000000..f34617b7252a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/example.c @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/roundbf.h" +#include +#include + +int main( void ) { + const float x[] = { -7.9f, -3.5f, -1.2f, 0.0f, 1.2f, 3.5f, 7.9f}; + const int32_t b[] = { 2, 10, 2, 2, 10, 2, 10 }; + + float v; + int i; + + for ( i = 0; i < 7; i++ ) { + v = stdlib_base_roundbf( x[ i ], b[ i ] ); + printf( "roundbf(%f, %d) = %f\n", x[ i ], b[ i ], v ); + } + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js new file mode 100644 index 000000000000..b2f3976ee9dc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 roundbf = require( './../lib' ); + +var x = [ -7.9, -3.5, -1.2, 0.0, 1.2, 3.5, 7.9 ]; +var b = 2; +var i; + +for ( i = 0; i < x.length; i++ ) { + console.log( 'x: %f. base: %d. rounded: %f', x[ i ], b, roundbf( x[ i ], b ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi b/lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi @@ -0,0 +1,53 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having +* undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Rounds a single-precision floating-point number to the nearest base-b +* floating-point value. +* +* @param x input value +* @param b integer base (must be >= 2) +* @return rounded value +*/ +float stdlib_base_roundbf( const float x, const int32_t b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_ROUNDBF_H diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/index.js new file mode 100644 index 000000000000..efa67cc1ac2e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Round a single-precision floating-point number to the nearest base-b floating-point value. +* +* @module @stdlib/math/base/special/roundbf +* +* @example +* var roundbf = require( '@stdlib/math/base/special/roundbf' ); +* +* // Binary rounding: +* var v = roundbf( 7.9, 2 ); +* // returns NaN +* +* // Decimal rounding: +* v = roundbf( 9.1, 10 ); +* // returns NaN +* +* // Preserve signed zero: +* v = roundbf( 0.0, 2 ); +* // returns 0.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/main.js new file mode 100644 index 000000000000..8dd2d5dea0c7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 log = require( '@stdlib/math/base/special/log' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var round = require( '@stdlib/math/base/special/round' ); +var float32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Rounds a single-precision floating-point number to the nearest base-b floating-point value. +* +* @param {number} x - input value +* @param {PositiveInteger} b - integer base (must be >= 2) +* @returns {number} rounded value +* +* @example +* var y1 = roundbf( 7.9, 2 ); +* // returns NaN +* +* @example +* var y2 = roundbf( 9.1, 10 ); +* // returns NaN +* +* @example +* var y3 = roundbf( -0.0, 2 ); +* // returns -0.0 +*/ +function roundbf( x, b ) { + var k; + var y; + + if ( + isnan( x ) || + isnan( b ) || + isInfinite( b ) || + b < 2 + ) { + return NaN; + } + if ( x === 0.0 || isInfinite( x ) ) { + return float32( x ); + } + + // Determine nearest base-b exponent: + k = round( log( abs( x ) ) / log( b ) ); + + // Round to nearest b^k: + y = round( x / pow( b, k ) ) * pow( b, k ); + + // Cast to float32: + return float32( y ); +} + + +// EXPORTS // + +module.exports = roundbf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/native.js new file mode 100644 index 000000000000..4ca450ef02cc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/native.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds a single-precision floating-point number to the nearest base-b floating-point value. +* +* @private +* @param {number} x - input value +* @param {PositiveInteger} b - integer base (must be >= 2) +* @returns {number} rounded value +* +* @example +* var v = roundbf( 7.9, 2 ); +* // returns NaN +* +* @example +* var v = roundbf( 9.1, 10 ); +* // returns NaN +*/ +function roundbf( x, b ) { + return addon( x, b ); +} + + +// EXPORTS // + +module.exports = roundbf; diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/manifest.json b/lib/node_modules/@stdlib/math/base/special/roundbf/manifest.json new file mode 100644 index 000000000000..824db8f01ea0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/manifest.json @@ -0,0 +1,81 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/assert/isnanf", + "@stdlib/math/base/assert/isinfinitef", + "@stdlib/math/base/special/frexpf", + "@stdlib/math/base/special/ldexpf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/isnanf", + "@stdlib/math/base/assert/isinfinitef", + "@stdlib/math/base/special/frexpf", + "@stdlib/math/base/special/ldexpf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/isnanf", + "@stdlib/math/base/assert/isinfinitef", + "@stdlib/math/base/special/frexpf", + "@stdlib/math/base/special/ldexpf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/package.json b/lib/node_modules/@stdlib/math/base/special/roundbf/package.json new file mode 100644 index 000000000000..c3feb64980c9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/math/base/special/roundbf", + "version": "0.0.0", + "description": "Round a single-precision floating-point number to the nearest base-b floating-point value.", + "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/number/float32/base/to-float32": "^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", + "float32", + "single-precision", + "round", + "roundbf", + "base", + "binary", + "decimal", + "nearest", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# 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/roundbf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.c new file mode 100644 index 000000000000..32f1b1c9056a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @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/roundbf.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_FI_F( stdlib_base_roundbf ) diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/src/main.c b/lib/node_modules/@stdlib/math/base/special/roundbf/src/main.c new file mode 100644 index 000000000000..737635cc4c0b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/src/main.c @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/roundbf.h" +#include "stdlib/math/base/assert/isnanf.h" +#include "stdlib/math/base/assert/isinfinitef.h" +#include "stdlib/math/base/special/frexpf.h" +#include "stdlib/math/base/special/ldexpf.h" +#include +#include + +/** +* Rounds a single-precision floating-point number to the nearest base-b floating-point value. +* +* @param x input value +* @param b base +* @return rounded value +* +* @example +* float y = stdlib_base_roundbf( 7.9f, 2 ); +* // returns 8.0f +*/ +float stdlib_base_roundbf( const float x, const int32_t b ) { + float frac; + int exp; + float k; + + // Special cases: + if ( stdlib_base_isnanf( x ) || b < 2 ) { + return 0.0f / 0.0f; // NaN + } + if ( stdlib_base_isinfinitef( x ) || x == 0.0f ) { + return x; + } + + // Decompose x = frac * 2^exp: + frac = stdlib_base_frexpf( x, &exp ); + + // Convert exponent to base-b exponent: + k = roundf( (float)exp / log2f( (float)b ) ); + + // Reconstruct rounded value: + return stdlib_base_ldexpf( frac, (int)( k * log2f( (float)b ) ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundbf/test/test.js new file mode 100644 index 000000000000..ad60b4128ba2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/test/test.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var roundbf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof roundbf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'returns NaN if provided NaN', function test( t ) { + t.strictEqual( isnan( roundbf( NaN, 2 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'returns NaN for invalid base', function test( t ) { + t.strictEqual( isnan( roundbf( 3.14, 1 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( roundbf( 3.14, 0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( roundbf( 3.14, -2 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( roundbf( 3.14, NaN ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'returns infinities unchanged', function test( t ) { + t.strictEqual( roundbf( PINF, 2 ), PINF, 'returns expected value' ); + t.strictEqual( roundbf( NINF, 10 ), NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'preserves signed zero', function test( t ) { + t.strictEqual( isPositiveZero( roundbf( 0.0, 2 ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( roundbf( -0.0, 10 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'rounds correctly for base 2', function test( t ) { + t.strictEqual( roundbf( 7.9, 2 ), 8.0, 'returns expected value' ); + t.strictEqual( roundbf( 3.1, 2 ), 4.0, 'returns expected value' ); + t.strictEqual( roundbf( -7.9, 2 ), -8.0, 'returns expected value' ); + t.end(); +}); + +tape( 'rounds correctly for base 10', function test( t ) { + t.strictEqual( roundbf( 9.1, 10 ), 10.0, 'returns expected value' ); + t.strictEqual( roundbf( 4.9, 10 ), 10.0, 'returns expected value' ); + t.strictEqual( roundbf( -9.1, 10 ), -10.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundbf/test/test.native.js new file mode 100644 index 000000000000..cee0e7950f8a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/test/test.native.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var roundbf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( roundbf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof roundbf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'returns NaN if provided NaN', opts, function test( t ) { + t.strictEqual( isnan( roundbf( NaN, 2 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'returns NaN for invalid base', opts, function test( t ) { + t.strictEqual( isnan( roundbf( 3.14, 1 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( roundbf( 3.14, 0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( roundbf( 3.14, -2 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'returns infinities unchanged', opts, function test( t ) { + t.strictEqual( roundbf( PINF, 2 ), PINF, 'returns expected value' ); + t.strictEqual( roundbf( NINF, 10 ), NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'preserves signed zero', opts, function test( t ) { + t.strictEqual( isPositiveZero( roundbf( 0.0, 2 ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( roundbf( -0.0, 10 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'rounds correctly for base 2', opts, function test( t ) { + t.strictEqual( roundbf( 7.9, 2 ), 8.0, 'returns expected value' ); + t.strictEqual( roundbf( -7.9, 2 ), -8.0, 'returns expected value' ); + t.end(); +}); + +tape( 'rounds correctly for base 10', opts, function test( t ) { + t.strictEqual( roundbf( 9.1, 10 ), 10.0, 'returns expected value' ); + t.strictEqual( roundbf( -9.1, 10 ), -10.0, 'returns expected value' ); + t.end(); +}); From 40585f766e0d7161b1a5385a96226bb65016bf43 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 21 Jan 2026 18:06:38 +0000 Subject: [PATCH 2/2] chore: update copyright years --- .../@stdlib/math/base/special/roundbf/benchmark/benchmark.js | 2 +- .../math/base/special/roundbf/benchmark/benchmark.native.js | 2 +- .../math/base/special/roundbf/benchmark/c/native/Makefile | 2 +- .../math/base/special/roundbf/benchmark/c/native/benchmark.c | 2 +- lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp | 2 +- .../@stdlib/math/base/special/roundbf/examples/c/Makefile | 2 +- .../@stdlib/math/base/special/roundbf/examples/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi | 2 +- .../@stdlib/math/base/special/roundbf/lib/native.js | 2 +- lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile | 2 +- lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js index a68d184c5587..d97a050094d1 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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/roundbf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.native.js index d7ab998f61ee..a80f12be3212 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/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/roundbf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/Makefile index f69e9da2b4d3..979768abbcec 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/Makefile @@ -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/roundbf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/benchmark.c index 1c5f29aaaa09..a0421b632133 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/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/roundbf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp index ec3992233442..0d6508a12e99 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/binding.gyp @@ -1,6 +1,6 @@ # @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/roundbf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile index 6aed70daf167..c8f8e9a1517b 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/c/Makefile @@ -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/roundbf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js index b2f3976ee9dc..3816eeb79685 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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/roundbf/include.gypi b/lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi index 575cb043c0bf..bee8d41a2caf 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/include.gypi @@ -1,6 +1,6 @@ # @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/roundbf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/roundbf/lib/native.js index 4ca450ef02cc..c1789eb21438 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/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/roundbf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile index bcf18aa46655..2caf905cedbe 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/src/Makefile @@ -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/roundbf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.c index 32f1b1c9056a..ba54a7d78fff 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/roundbf/src/addon.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.