diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/README.md b/lib/node_modules/@stdlib/math/base/special/round10f/README.md new file mode 100644 index 000000000000..116efc156969 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/README.md @@ -0,0 +1,196 @@ + + +# round10f + +> Round a numeric value to the nearest power of ten using single-precision floating-point arithmetic. + +
+ +## Usage + +```javascript +var round10f = require( '@stdlib/math/base/special/round10f' ); +``` + +#### round10f( x ) + +Rounds a `numeric` value to the nearest power of ten using single-precision floating-point arithmetic. + +```javascript +var y; + +y = round10f( 3.1415926 ); +// returns 1.0 + +y = round10f( 123.456 ); +// returns 100.0 + +y = round10f( -2.5 ); +// returns -1.0 + +y = round10f( -0.0 ); +// returns -0.0 +``` + +
+ + + +
+ +## Examples + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var round10f = require( '@stdlib/math/base/special/round10f' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = uniform( 100, -50.0, 50.0, opts ); + +// Ensure float32 precision: +var i; +for ( i = 0; i < x.length; i++ ) { + x[ i ] = toFloat32( x[ i ] ); +} + +function fcn( v ) { + return round10f( v ); +} + +logEachMap( 'x: %0.4f => %0.4f', x, fcn ); +``` + +
+ + + + +* * * + +
+ +## C APIs + +
+ +This package provides a C API for rounding single-precision floating-point numbers to the nearest power of \\(10\\). + +
+ + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/round10f.h" +``` + +#### stdlib_base_round10f( x ) + +Rounds a single-precision floating-point number to the nearest power of ten. + +```c +float out = stdlib_base_round10f( 3.14f ); +// returns 1.0f + +out = stdlib_base_round10f( 123.456f ); +// returns 100.0f +``` + +**Arguments** + +- **x**: `[in] float` input value. + +**Returns** + +- `float`: rounded value. + +```c +float stdlib_base_round10f( const float x ); +``` + +
+ + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/round10f.h" +#include + +int main( void ) { + const float x[] = { + -5.0f, -3.89f, -2.78f, -1.67f, -0.56f, + 0.56f, 1.67f, 2.78f, 3.89f, 5.0f + }; + + float v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_round10f( x[ i ] ); + printf( "round10f(%f) = %f\n", x[ i ], v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/benchmark.js new file mode 100644 index 000000000000..44fb272997c9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/benchmark.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var round10f = require( './../lib/main.js' ); +var pkg = require( './../package.json' ).name; + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + // Generate float32 input values: + x = uniform( 100, -5.0e3, 5.0e3 ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = toFloat32( x[ i ] ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = round10f( x[ i % x.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/benchmark.native.js new file mode 100644 index 000000000000..d7c5a564d230 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/benchmark.native.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var round10f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( round10f instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var x; + var y; + var i; + + // Generate float32 input data: + x = uniform( 100, -5.0e3, 5.0e3 ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = toFloat32( x[ i ] ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = round10f( x[ i % x.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/c/native/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|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/round10f/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..f343b18a9b2e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/benchmark/c/native/benchmark.c @@ -0,0 +1,74 @@ +/** +* @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/round10f.h" +#include +#include +#include +#include + +#define NAME "round10f" +#define ITERATIONS 1000000 +#define REPEATS 3 + +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +static float rand_float( void ) { + return (float)rand() / ( (float)RAND_MAX + 1.0f ); +} + +static double benchmark( void ) { + float x[100]; + volatile float y; /* prevent compiler optimization */ + double elapsed; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1.0e4f * rand_float() ) - 5.0e3f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_round10f( x[ i % 100 ] ); + } + elapsed = tic() - t; + + if ( y != y ) { + printf( "should not return NaN\n" ); + } + + return elapsed; +} + +int main( void ) { + double elapsed; + int i; + + srand( time( NULL ) ); + + printf( "native::%s\n", NAME ); + for ( i = 0; i < REPEATS; i++ ) { + elapsed = benchmark(); + printf( " elapsed: %0.9f sec\n", elapsed ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/binding.gyp b/lib/node_modules/@stdlib/math/base/special/round10f/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/round10f/docs/repl.txt new file mode 100644 index 000000000000..65246aafa87c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/docs/repl.txt @@ -0,0 +1,30 @@ +{{alias}}( x ) + Rounds a numeric value to the nearest power of ten using + single-precision floating-point arithmetic. + + Parameters + ---------- + x: number + Input value. + + Returns + ------- + y: number + Rounded value. + + Examples + -------- + > var y = {{alias}}( 3.1415926 ) + 1.0 + > y = {{alias}}( 123.456 ) + 100.0 + > y = {{alias}}( 9.5 ) + 10.0 + > y = {{alias}}( -2.5 ) + -1.0 + > y = {{alias}}( -0.0 ) + -0.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/round10f/docs/types/index.d.ts new file mode 100644 index 000000000000..be52154bad0b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/docs/types/index.d.ts @@ -0,0 +1,48 @@ +/* +* @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 numeric value to the nearest power of 10 on a linear scale (single-precision). +* +* @param x - input value +* @returns rounded value +* +* @example +* var v = round10f( 3.1415926 ); +* // returns 1.0 +* +* @example +* var v = round10f( 13.0 ); +* // returns 10.0 +* +* @example +* var v = round10f( -0.314 ); +* // returns -0.10000000149011612 +* +* @example +* var v = round10f( NaN ); +* // returns NaN +*/ +declare function round10f( x: number ): number; + + +// EXPORTS // + +export = round10f; diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/round10f/docs/types/test.ts new file mode 100644 index 000000000000..3659b22e7be4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/docs/types/test.ts @@ -0,0 +1,45 @@ +/* +* @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 round10f = require( './index' ); + +// TESTS // + +// The function returns a number... +{ + round10f( 8.78 ); // $ExpectType number + round10f( 0.5 ); // $ExpectType number + round10f( -3.2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided an argument other than a number... +{ + round10f( true ); // $ExpectError + round10f( false ); // $ExpectError + round10f( null ); // $ExpectError + round10f( undefined ); // $ExpectError + round10f( '5' ); // $ExpectError + round10f( [] ); // $ExpectError + round10f( {} ); // $ExpectError + round10f( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + round10f(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/round10f/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := 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/round10f/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/round10f/examples/c/example.c new file mode 100644 index 000000000000..8be612b4286a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/examples/c/example.c @@ -0,0 +1,37 @@ +/** +* @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/round10f.h" +#include + +int main( void ) { + const float x[] = { + -5.0f, -3.89f, -2.78f, -1.67f, -0.56f, + 0.56f, 1.67f, 2.78f, 3.89f, 5.0f + }; + + float v; + int i; + + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_round10f( x[ i ] ); + printf( "round10f(%f) = %f\n", x[ i ], v ); + } + + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/examples/index.js b/lib/node_modules/@stdlib/math/base/special/round10f/examples/index.js new file mode 100644 index 000000000000..b7b42519e658 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var round10f = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = uniform( 100, -50.0, 50.0, opts ); + +// ensure float32 precision: +var i; +for ( i = 0; i < x.length; i++ ) { + x[ i ] = toFloat32( x[ i ] ); +} + +function fcn( v ) { + return round10f( v ); +} + +logEachMap( 'x: %0.4f => %0.4f', x, fcn ); diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/include.gypi b/lib/node_modules/@stdlib/math/base/special/round10f/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '=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", + "round10", + "round10f", + "nearest", + "number", + "float32", + "single-precision" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base/single@v1.0", + "base_alias": "round10f", + "alias": "round10f", + "pkg_desc": "round a numeric value to the nearest power of 10 on a linear scale using single-precision floating-point arithmetic", + "desc": "rounds a numeric value to the nearest power of ten on a linear scale using single-precision floating-point arithmetic", + "short_desc": "", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "float", + "dtype": "float32" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -10, + 10 + ] + } + } + ], + "returns": { + "desc": "function value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "float", + "dtype": "float32" + } + }, + "keywords": [ + "round", + "round10", + "round10f", + "nearest" + ], + "extra_keywords": [ + "math.round", + "float32" + ] + } + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/src/Makefile b/lib/node_modules/@stdlib/math/base/special/round10f/src/Makefile new file mode 100644 index 000000000000..3f38164b44e1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/src/Makefile @@ -0,0 +1,71 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# 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/round10f/src/addon.c b/lib/node_modules/@stdlib/math/base/special/round10f/src/addon.c new file mode 100644 index 000000000000..80d60f0dddd0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/round10f.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_round10f ) diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/src/main.c b/lib/node_modules/@stdlib/math/base/special/round10f/src/main.c new file mode 100644 index 000000000000..bd65249e22bc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/src/main.c @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/round10f.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/assert/is_infinitef.h" +#include "stdlib/math/base/special/absf.h" +#include "stdlib/math/base/special/floorf.h" +#include "stdlib/math/base/special/powf.h" +#include "stdlib/math/base/special/log10.h" + +float stdlib_base_round10f( const float x ) { + float ax; + float e0; + float e1; + float y0; + float y1; + + /* NaN and ±inf return input */ + if ( stdlib_base_is_nanf( x ) || stdlib_base_is_infinitef( x ) ) { + return x; + } + + /* Preserve ±0.0f */ + if ( x == 0.0f ) { + return x; + } + + /* abs(x) */ + ax = stdlib_base_absf( x ); + + /* lower exponent = floor(log10(ax)) */ + e0 = stdlib_base_floorf( (float)stdlib_base_log10( ax ) ); + + /* next exponent */ + e1 = e0 + 1.0f; + + /* powers */ + y0 = stdlib_base_powf( 10.0f, e0 ); + y1 = stdlib_base_powf( 10.0f, e1 ); + + /* return whichever is closer */ + if ( (ax - y0) <= (y1 - ax) ) { + return ( x < 0.0f ) ? -y0 : y0; + } + return ( x < 0.0f ) ? -y1 : y1; +} diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/test/test.js b/lib/node_modules/@stdlib/math/base/special/round10f/test/test.js new file mode 100644 index 000000000000..c6f7a74c193a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/test/test.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 tape = require( 'tape' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +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 toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var round10f = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof round10f, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', function test( t ) { + var v = round10f( toFloat32( +0.0 ) ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', function test( t ) { + var v = round10f( toFloat32( -0.0 ) ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var v = round10f( NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { + var v = round10f( PINF ); + t.strictEqual( v, PINF, 'returns +infinity' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var v = round10f( NINF ); + t.strictEqual( v, NINF, 'returns -infinity' ); + t.end(); +}); + +tape( 'the function rounds to the nearest power of 10 on a linear scale', function test( t ) { + t.strictEqual( round10f( toFloat32( -4.2 ) ), toFloat32( -1.0 ), '-4.2 -> -1' ); + t.strictEqual( round10f( toFloat32( -4.8 ) ), toFloat32( -1.0 ), '-4.8 -> -1' ); + t.strictEqual( round10f( toFloat32( 4.2 ) ), toFloat32( 1.0 ), '4.2 -> 1' ); + t.strictEqual( round10f( toFloat32( 9.4 ) ), toFloat32( 10.0 ), '9.4 -> 10' ); + t.strictEqual( round10f( toFloat32( 9.5 ) ), toFloat32( 10.0 ), '9.5 -> 10' ); + t.strictEqual( round10f( toFloat32( 12.0 ) ), toFloat32( 10.0 ), '12 -> 10' ); + t.strictEqual( round10f( toFloat32( -12.0 ) ), toFloat32( -10.0 ), '-12 -> -10' ); + t.strictEqual( round10f( toFloat32( 60.1 ) ), toFloat32( 100.0 ), '60.1 -> 100' ); + t.strictEqual( round10f( toFloat32( 0.3 ) ), toFloat32( 0.1 ), '0.3 -> 0.1' ); + t.strictEqual( round10f( toFloat32( 0.61 ) ), toFloat32( 1.0 ), '0.61 -> 1' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/round10f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/round10f/test/test.native.js new file mode 100644 index 000000000000..9287d807619b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/round10f/test/test.native.js @@ -0,0 +1,92 @@ +/** +* @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 NINF = require( '@stdlib/constants/float32/ninf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +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' ); +var toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// VARIABLES // + +var round10f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( round10f instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof round10f, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { + var v = round10f( toFloat32( +0.0 ) ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { + var v = round10f( toFloat32( -0.0 ) ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var v = round10f( NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { + var v = round10f( PINF ); + t.strictEqual( v, PINF, 'returns +infinity' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { + var v = round10f( NINF ); + t.strictEqual( v, NINF, 'returns -infinity' ); + t.end(); +}); + +tape( 'the function rounds to the nearest power of 10 on a linear scale', opts, function test( t ) { + t.strictEqual( round10f( toFloat32( -4.2 ) ), toFloat32( -1.0 ), '-4.2 -> -1' ); + t.strictEqual( round10f( toFloat32( -4.8 ) ), toFloat32( -1.0 ), '-4.8 -> -1' ); + t.strictEqual( round10f( toFloat32( 4.2 ) ), toFloat32( 1.0 ), '4.2 -> 1' ); + t.strictEqual( round10f( toFloat32( 9.4 ) ), toFloat32( 10.0 ), '9.4 -> 10' ); + t.strictEqual( round10f( toFloat32( 9.5 ) ), toFloat32( 10.0 ), '9.5 -> 10' ); + t.strictEqual( round10f( toFloat32( 12.0 ) ), toFloat32( 10.0 ), '12 -> 10' ); + t.strictEqual( round10f( toFloat32( -12.0 ) ), toFloat32( -10.0 ), '-12 -> -10' ); + t.strictEqual( round10f( toFloat32( 60.1 ) ), toFloat32( 100.0 ), '60.1 -> 100' ); + t.strictEqual( round10f( toFloat32( 0.3 ) ), toFloat32( 0.1 ), '0.3 -> 0.1' ); + t.strictEqual( round10f( toFloat32( 0.61 ) ), toFloat32( 1.0 ), '0.61 -> 1' ); + t.end(); +});