diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md new file mode 100644 index 000000000000..bc2b97949130 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md @@ -0,0 +1,255 @@ + + +# wrapf + +> Wrap a value on the half-open interval `[min,max)`. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var wrapf = require( '@stdlib/math/base/special/wrapf' ); +``` + +#### wrapf( v, min, max ) + +Wraps a value on the half-open interval `[min,max)`. + +```javascript +var v = wrapf( 3.14, 0.0, 5.0 ); +// returns ~3.14 + +v = wrapf( -3.14, 0.0, 5.0 ); +// returns ~1.86 + +v = wrapf( 10.0, 0.0, 5.0 ); +// returns 0.0 + +v = wrapf( -0.0, 0.0, 5.0 ); +// returns 0.0 + +v = wrapf( 0.0, -3.14, -0.0 ); +// returns ~-3.14 +``` + +If provided `NaN` for any argument, the function returns `NaN`. + +```javascript +var v = wrapf( NaN, 0.0, 5.0 ); +// returns NaN + +v = wrapf( 0.0, NaN, 5.0 ); +// returns NaN + +v = wrapf( 3.14, 0.0, NaN ); +// returns NaN +``` + +If provided `min == max`, the function returns `NaN`. + +```javascript +var v = wrapf( 3.14, 3.0, 3.0 ); +// returns NaN +``` + +
+ + + + + +
+ +## Notes + +- The function does **not** distinguish between positive and negative zero. Where appropriate, the function returns positive zero. + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var wrapf = require( '@stdlib/math/base/special/wrapf' ); + +var min; +var max; +var v; +var i; + +for ( i = 0; i < 100; i++ ) { + min = discreteUniform( 0.0, 10.0 ); + max = discreteUniform( 5.0, 15.0 ); + v = discreteUniform( -20.0, 20.0 ); + console.log( 'wrapf(%d,%d,%d) => %d', v, min, max, wrapf( v, min, max ) ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/wrapf.h" +``` + +#### stdlib_base_wrapf( v, min, max ) + +Wraps a value on the half-open interval `[min,max)`. + +```c +float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 ); +// returns ~3.14 + +v = stdlib_base_wrapf( -3.14, 0.0, 5.0 ); +// returns ~1.86 +``` + +The function accepts the following arguments: + +- **v**: `[in] float` input value to wrap. +- **min**: `[in] float` minimum value. +- **max**: `[in] float` maximum value. + +```c +float stdlib_base_wrapf( const float v, const float min, const float max ) +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/wrapf.h" +#include + +int main( void ) { + const float min[] = { 0.0f, 0.0f, 0.0f, 0.0f, -3.14f }; + const float max[] = { 5.0f, 5.0f, 5.0f, 5.0f, -0.0f }; + const float v[] = { 3.14f, -3.14f, 10.0f, -0.0f, 0.0f }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_wrap( v[i], min[i], max[i] ); + printf( "wrapf(%f,%f,%f) => %f\n", v[i], min[i], max[i], out ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js new file mode 100644 index 000000000000..f6b29dffda9b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var wrapf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 20.0 ) - 10.0; + y = wrapf( x, -5.0, 5.0 ); + 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/wrapf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..e91a8961467e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.native.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var wrapf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( wrapf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 20.0 ) - 10.0; + y = wrapf( x, -5.0, 5.0 ); + 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/wrapf/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile new file mode 100644 index 000000000000..d564e8b2d6f9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile @@ -0,0 +1,127 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler +# @param {string} [CFLAGS] - C compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm + +#/ +# 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/wrapf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..5e8ad3b6e227 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/benchmark.c @@ -0,0 +1,153 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include +#include + +#define NAME "wrapf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( float elapsed ) { + float rate = (float)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 float tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (float)now.tv_sec + (float)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0 ); +} + +/** +* Wraps a value within a specified range. +* +* @param v value to wrap +* @param min minimum value +* @param max maximum value +* @return wrapped value +*/ +float wrapf( float v, float min, float max ) { + float delta; + if ( min <= v && v < max ) { + return v; + } + // Perform range reduction... + delta = max - min; + if ( v < min ) { + v += delta * ( trunc( ( min - v ) / delta ) + 1.0 ); + } + return min + fmod( ( v - min ), delta ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static float benchmark( void ) { + float elapsed; + float x; + float y; + float t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 20.0 * rand_float() ) - 10.0; + y = wrapf( x, -5.0, 5.0 ); + 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 ) { + float elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..3034b6c99de6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/benchmark.c @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/wrapf.h" +#include +#include +#include +#include +#include + +#define NAME "wrapf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( float elapsed ) { + float rate = (float)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 float tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (float)now.tv_sec + (float)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static float benchmark( void ) { + float elapsed; + float x; + float y; + float t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 20.0 * rand_float() ) - 10.0; + y = stdlib_base_wrapf( x, -5.0, 5.0 ); + 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 ) { + float elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i + 1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt new file mode 100644 index 000000000000..4400433a093b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( v, min, max ) + Wraps a value on the half-open interval `[min,max)`. + + The function does not distinguish between positive and negative zero. Where + appropriate, the function returns positive zero. + + If provided `NaN` for any argument, the function returns `NaN`. + + Parameters + ---------- + v: number + Value to wrap. + + min: number + Minimum value. + + max: number + Maximum value. + + Returns + ------- + y: number + Wrapped value. + + Examples + -------- + > var y = {{alias}}( 3.14, 0.0, 5.0 ) + ~3.14 + > y = {{alias}}( -3.14, 0.0, 5.0 ) + ~1.86 + > y = {{alias}}( 3.14, 0.0, 3.0 ) + ~0.14 + > y = {{alias}}( -0.0, 0.0, 5.0 ) + 0.0 + > y = {{alias}}( 0.0, -3.14, -0.0 ) + ~-3.14 + > y = {{alias}}( NaN, 0.0, 5.0 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/index.d.ts new file mode 100644 index 000000000000..29c6c530b719 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/index.d.ts @@ -0,0 +1,62 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Wraps a value on the half-open interval `[min,max)`. +* +* @param v - input value +* @param min - minimum value +* @param max - maximum value +* @returns wrapped value +* +* @example +* var v = wrapf( 3.14, 0.0, 5.0 ); +* // returns 3.14 +* +* v = wrapf( -3.14, 0.0, 5.0 ); +* // returns ~1.86 +* +* v = wrapf( 10.0, 0.0, 5.0 ); +* // returns 0.0 +* +* v = wrapf( -0.0, 0.0, 5.0 ); +* // returns 0.0 +* +* v = wrapf( 0.0, -0.0, 5.0 ); +* // returns 0.0 +* +* v = wrapf( NaN, 0.0, 5.0 ); +* // returns NaN +* +* v = wrapf( 0.0, NaN, 5.0 ); +* // returns NaN +* +* v = wrapf( 3.14, 0.0, NaN ); +* // returns NaN +* +* v = wrapf( 3.14, 5.0, 0.0 ); +* // returns NaN +*/ +declare function wrapf( v: number, min: number, max: number ): number; + + +// EXPORTS // + +export = wrapf; diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/test.ts new file mode 100644 index 000000000000..482ad7fefb9e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import wrapf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + wrapf( -3, 0, 10 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + wrapf( true, 3, 2 ); // $ExpectError + wrapf( false, 2, 2 ); // $ExpectError + wrapf( '5', 1, 2 ); // $ExpectError + wrapf( [], 1, 2 ); // $ExpectError + wrapf( {}, 2, 2 ); // $ExpectError + wrapf( ( x: number ): number => x, 2, 2 ); // $ExpectError + + wrapf( 9, true, 2 ); // $ExpectError + wrapf( 9, false, 2 ); // $ExpectError + wrapf( 5, '5', 2 ); // $ExpectError + wrapf( 8, [], 2 ); // $ExpectError + wrapf( 9, {}, 2 ); // $ExpectError + wrapf( 8, ( x: number ): number => x, 2 ); // $ExpectError + + wrapf( 3.12, 2, true ); // $ExpectError + wrapf( 4.9, 2, false ); // $ExpectError + wrapf( 2.1, 2, '5' ); // $ExpectError + wrapf( 2.9323213, 2, [] ); // $ExpectError + wrapf( 9.343, 2, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + wrapf(); // $ExpectError + wrapf( 3 ); // $ExpectError + wrapf( 2.131, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/example.c new file mode 100644 index 000000000000..bd48478ee9c3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/example.c @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/wrapf.h" +#include + +int main( void ) { + const float min[] = { 0.0, 0.0, 0.0, 0.0, -3.14 }; + const float max[] = { 5.0, 5.0, 5.0, 5.0, -0.0 }; + const float v[] = { 3.14, -3.14, 10.0, -0.0, 0.0 }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_wrapf( v[i], min[i], max[i] ); + printf( "wrapf(%f,%f,%f) => %f\n", v[i], min[i], max[i], out ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js new file mode 100644 index 000000000000..1105d577ab45 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var wrapf = require( './../lib' ); + +var min; +var max; +var v; +var i; + +for ( i = 0; i < 100; i++ ) { + min = discreteUniform( 0.0, 10.0 ); + max = discreteUniform( 5.0, 15.0 ); + v = discreteUniform( -20.0, 20.0 ); + console.log( 'wrap(%d,%d,%d) => %d', v, min, max, wrapf( v, min, max ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi b/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "wrapf", + "modulo", + "mod", + "range", + "interval" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c new file mode 100644 index 000000000000..f0c22f25dbbf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/wrapf.h" +#include "stdlib/math/base/napi/ternary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_FFF_F( stdlib_base_wrapf ) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c new file mode 100644 index 000000000000..4f86176d717e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/wrapf.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/special/truncf.h" +#include "stdlib/math/base/special/fmodf.h" +#include "stdlib/math/base/assert/is_negative_zerof.h" + +/** +* Wraps a value on the half-open interval [min,max). +* +* @param v input value +* @param min minimum value +* @param max maximum value +* @return wrapped value +* +* @example +* float v = stdlib_base_wrap( 3.14f, 0.0f, 5.0f ); +* // returns 3.14 +*/ +float stdlib_base_wrapf( const float v, const float min, const float max ) { + float delta; + float maxc; + float minc; + float vc; + + if ( stdlib_base_is_nanf( v ) || stdlib_base_is_nanf( min ) || stdlib_base_is_nanf( max ) || max <= min ) { + return 0.0f / 0.0f; // NaN + } + maxc = max; + minc = min; + vc = v; + + // Normalize +-0 to +0... + if ( stdlib_base_is_negative_zerof( vc ) ) { + vc = 0.0f; + } + if ( stdlib_base_is_negative_zerof( minc ) ) { + minc = 0.0f; + } + if ( stdlib_base_is_negative_zerof( maxc ) ) { + maxc = 0.0f; + } + // Simple case where value is already within range... + if ( minc <= vc && vc < maxc ) { + return vc; + } + // Perform range reduction... + delta = maxc - minc; + if ( vc < minc ) { + vc += delta * ( stdlib_base_truncf( ( minc - vc ) / delta ) + 1.0f ); + } + return minc + ( stdlib_base_fmodf( vc - minc, delta ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js new file mode 100644 index 000000000000..ab937db088d6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var abs = require( '@stdlib/math/base/special/absf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var wrapf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof wrapf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any argument, the function returns `NaN`', function test( t ) { + var v; + + v = wrapf( NaN, 0.0, 5.0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( 0.0, NaN, 5.0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, 0.0, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, 5.0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( NaN, 0.0, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, NaN, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided a value which is between a minimum value (inclusive) and a maximum value (exclusive), the function returns the input value', function test( t ) { + var expected; + var delta; + var tol; + var v; + + expected = 3.14; + v = wrapf( 3.14, 0.0, 5.0 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + + expected = -3.14; + v = wrapf( -3.14, -10.0, 15.0 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + + expected = 3.14; + v = wrapf( 3.14, 3.14, 5.0 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + + expected = 3.13; + v = wrapf( 3.13, 0.0, 3.14 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + + t.end(); +}); + +tape( 'if provided a value which less than a minimum value or greater than or equal to a maximum value, the function wraps the value using modulo arithmetic', function test( t ) { + var v; + + v = wrapf( 13.00, 0.0, 5.0 ); + t.strictEqual( v, 3.00, 'returns expected value' ); + + v = wrapf( -3.0, 0.0, 5.0 ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + v = wrapf( -13.0, -10.0, 15.0 ); + t.strictEqual( v, 12.0, 'returns expected value' ); + + v = wrapf( 10.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( -10.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( -30.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( -30.0, -5.0, 0.0 ); + t.strictEqual( v, -5.0, 'returns expected value' ); + + v = wrapf( 30.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( 31.0, 0.0, 5.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + v = wrapf( -31.0, -5.0, 0.0 ); + t.strictEqual( v, -1.0, 'returns expected value' ); + + v = wrapf( 0.0, -3.0, 0.0 ); + t.strictEqual( v, -3.0, 'returns expected value' ); + + v = wrapf( 0.0, -10.0, -0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + v = wrapf( -0.0, -10.0, 0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + v = wrapf( 0.0, -10.0, 0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + v = wrapf( -0.0, -10.0, -0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not distinguish between positive and negative zero', function test( t ) { + var v; + + v = wrapf( -0.0, 0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = wrapf( 0.0, -0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = wrapf( -0.0, -0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = wrapf( 0.0, 0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided a maximum value which is less than or equal to a minimum value', function test( t ) { + var v; + + v = wrapf( 3.14, 10.0, 0.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 10.0, 10.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 3.0, 1.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 1.0, 1.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.native.js new file mode 100644 index 000000000000..a7276c9acf38 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.native.js @@ -0,0 +1,206 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/absf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var isnan = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var wrapf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( wrapf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof wrapf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any argument, the function returns `NaN`', opts, function test( t ) { + var v; + + v = wrapf( NaN, 0.0, 5.0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( 0.0, NaN, 5.0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, 0.0, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, 5.0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( NaN, 0.0, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, NaN, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided a value which is between a minimum value (inclusive) and a maximum value (exclusive), the function returns the input value', opts, function test( t ) { + var expected; + var delta; + var tol; + var v; + + expected = 3.14; + v = wrapf( 3.14, 0.0, 5.0 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + expected = -3.14; + v = wrapf( -3.14, -10.0, 15.0 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + expected = 3.14; + v = wrapf( 3.14, 3.14, 5.0 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + expected = 3.13; + v = wrapf( 3.13, 0.0, 3.14 ); + if ( v === expected ) { + t.equal( v, expected, 'returns expected value' ); + } else { + delta = abs( v - expected ); + tol = EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + + t.end(); +}); + +tape( 'if provided a value which less than a minimum value or greater than or equal to a maximum value, the function wraps the value using modulo arithmetic', opts, function test( t ) { + var v; + + v = wrapf( 13.00, 0.0, 5.0 ); + t.strictEqual( v, 3.00, 'returns expected value' ); + + v = wrapf( -3.0, 0.0, 5.0 ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + v = wrapf( -13.0, -10.0, 15.0 ); + t.strictEqual( v, 12.0, 'returns expected value' ); + + v = wrapf( 10.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( -10.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( -30.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( -30.0, -5.0, 0.0 ); + t.strictEqual( v, -5.0, 'returns expected value' ); + + v = wrapf( 30.0, 0.0, 5.0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = wrapf( 31.0, 0.0, 5.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + v = wrapf( -31.0, -5.0, 0.0 ); + t.strictEqual( v, -1.0, 'returns expected value' ); + + v = wrapf( 0.0, -3.0, 0.0 ); + t.strictEqual( v, -3.0, 'returns expected value' ); + + v = wrapf( 0.0, -10.0, -0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + v = wrapf( -0.0, -10.0, 0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + v = wrapf( 0.0, -10.0, 0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + v = wrapf( -0.0, -10.0, -0.0 ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not distinguish between positive and negative zero', opts, function test( t ) { + var v; + + v = wrapf( -0.0, 0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = wrapf( 0.0, -0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = wrapf( -0.0, -0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = wrapf( 0.0, 0.0, 5.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided a maximum value which is less than or equal to a minimum value', opts, function test( t ) { + var v; + + v = wrapf( 3.14, 10.0, 0.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 10.0, 10.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 3.0, 1.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 1.0, 1.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +});