From 98ad0918cd90eda05782a31b7982550162e7e685 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Sat, 2 Nov 2024 11:03:29 +0530 Subject: [PATCH 01/17] feat: add wrapf --- .../@stdlib/math/base/special/wrapf/README.md | 255 ++++++++++++++++++ .../base/special/wrapf/benchmark/benchmark.js | 51 ++++ .../wrapf/benchmark/benchmark.native.js | 60 +++++ .../base/special/wrapf/benchmark/c/Makefile | 107 ++++++++ .../special/wrapf/benchmark/c/benchmark.c | 153 +++++++++++ .../special/wrapf/benchmark/c/native/Makefile | 146 ++++++++++ .../wrapf/benchmark/c/native/benchmark.c | 133 +++++++++ .../math/base/special/wrapf/binding.gyp | 170 ++++++++++++ .../math/base/special/wrapf/docs/repl.txt | 44 +++ .../base/special/wrapf/docs/types/index.d.ts | 62 +++++ .../base/special/wrapf/docs/types/test.ts | 57 ++++ .../base/special/wrapf/examples/c/Makefile | 146 ++++++++++ .../base/special/wrapf/examples/c/example.c | 33 +++ .../math/base/special/wrapf/examples/index.js | 34 +++ .../math/base/special/wrapf/include.gypi | 53 ++++ .../include/stdlib/math/base/special/wrapf.h | 38 +++ .../math/base/special/wrapf/lib/index.js | 64 +++++ .../math/base/special/wrapf/lib/main.js | 100 +++++++ .../math/base/special/wrapf/lib/native.js | 72 +++++ .../math/base/special/wrapf/manifest.json | 79 ++++++ .../math/base/special/wrapf/package.json | 65 +++++ .../math/base/special/wrapf/src/Makefile | 70 +++++ .../math/base/special/wrapf/src/addon.c | 23 ++ .../math/base/special/wrapf/src/main.c | 70 +++++ .../math/base/special/wrapf/test/test.js | 167 ++++++++++++ .../base/special/wrapf/test/test.native.js | 176 ++++++++++++ 26 files changed, 2428 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/wrapf/test/test.native.js 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..899204cb8eef --- /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)` for single-precision floating-point numbers. + + + +
+ +
+ + + + + +
+ +## 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)` for single-precision floating-point numbers. + +```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.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/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js new file mode 100644 index 000000000000..afb69c467eb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnanf = 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 ( 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/wrapf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..9fbd80158e69 --- /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) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnanf = 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 ( 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/wrapf/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile new file mode 100644 index 000000000000..ad9fedcd4fff --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile @@ -0,0 +1,107 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +endif + +# Determine the OS: +# +# [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 +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]: 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 + + +# TARGETS # + +# Default target. +# +# This target is the default target. + +all: $(c_targets) + +.PHONY: all + + +# Compile C source. +# +# This target compiles C source files. + +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm + + +# Run a benchmark. +# +# This target runs a benchmark. + +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + + +# Perform clean-up. +# +# This target removes generated files. + +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..7db9ad13ee53 --- /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) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#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( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* 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 * ( truncf( (min-v)/delta ) + 1.0 ); + } + return min + fmodf( (v-min), delta ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double t; + float x; + float y; + 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 ) { + double 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..f69e9da2b4d3 --- /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) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/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..3cc3bf67a820 --- /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) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/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( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double t; + float x; + float y; + 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 ) { + double 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..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt new file mode 100644 index 000000000000..8042269a5b43 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( v, min, max ) + Wraps a value on the half-open interval `[min,max)` for single-precision + floating-point numbers. + + 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..9a1985a99f88 --- /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) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +* +* @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..e1f441799a49 --- /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) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +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..91d364d19fc3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2022 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..0bb3c9964d46 --- /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) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/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( "wrap(%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..ff5b26021a91 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var 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( 'wrapf(%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..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "wrap", + "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..f79b87238713 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2022 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..6e7a6df71364 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/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..b910fdcf3c72 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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/assert/is_negative_zerof.h" +#include + +/** +* Wraps a value on the half-open interval [min,max) for single-precision floating-point numbers. +* +* @param v input value +* @param min minimum value +* @param max maximum value +* @return wrapped value +* +* @example +* float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 ); +* // 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.0 / 0.0; // NaN + } + maxc = max; + minc = min; + vc = v; + + // Normalize +-0 to +0... + if ( stdlib_base_is_negative_zerof( vc ) ) { + vc = 0.0; + } + if ( stdlib_base_is_negative_zerof( minc ) ) { + minc = 0.0; + } + if ( stdlib_base_is_negative_zerof( maxc ) ) { + maxc = 0.0; + } + // 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.0 ); + } + return minc + ( 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..977f2628d077 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); +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( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( 0.0, NaN, 5.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, 0.0, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, 5.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( NaN, 0.0, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, NaN ); + t.strictEqual( isnanf( 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 v; + + v = wrapf( 3.14, 0.0, 5.0 ); + t.strictEqual( v, 3.14, 'returns expected value' ); + + v = wrapf( -3.14, -10.0, 15.0 ); + t.strictEqual( v, -3.14, 'returns expected value' ); + + v = wrapf( 3.14, 3.14, 5.0 ); + t.strictEqual( v, 3.14, 'returns expected value' ); + + v = wrapf( 3.13, 0.0, 3.14 ); + t.strictEqual( v, 3.13, 'returns expected value' ); + + 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.15, 0.0, 5.0 ); + t.strictEqual( v, 1.85, 'returns expected value' ); + + v = wrapf( -13.14, -10.0, 15.0 ); + t.strictEqual( v, 11.86, '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.14, 0.0 ); + t.strictEqual( v, -3.14, '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( isnanf( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 10.0, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 3.0, 1.0 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 1.0, 1.0 ); + t.strictEqual( isnanf( 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..7f500c86a497 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.native.js @@ -0,0 +1,176 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var isnanf = 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( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( 0.0, NaN, 5.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, 0.0, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, 5.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( NaN, 0.0, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( 3.14, NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = wrapf( NaN, NaN, NaN ); + t.strictEqual( isnanf( 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 v; + + v = wrapf( 3.14, 0.0, 5.0 ); + t.strictEqual( v, 3.14, 'returns expected value' ); + + v = wrapf( -3.14, -10.0, 15.0 ); + t.strictEqual( v, -3.14, 'returns expected value' ); + + v = wrapf( 3.14, 3.14, 5.0 ); + t.strictEqual( v, 3.14, 'returns expected value' ); + + v = wrapf( 3.13, 0.0, 3.14 ); + t.strictEqual( v, 3.13, 'returns expected value' ); + + 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.15, 0.0, 5.0 ); + t.strictEqual( v, 1.85, 'returns expected value' ); + + v = wrapf( -13.14, -10.0, 15.0 ); + t.strictEqual( v, 11.86, '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.14, 0.0 ); + t.strictEqual( v, -3.14, '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( isnanf( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 10.0, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 3.0, 1.0 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = wrapf( 3.14, 1.0, 1.0 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); From 90fd950eb6ae8ddd620021eb7ce7a733542c6367 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 11 Nov 2024 13:42:27 +0530 Subject: [PATCH 02/17] update main.c --- lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json | 3 +++ lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json b/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json index 697674e6440b..5f1650cf76b7 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json @@ -39,6 +39,7 @@ "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is_nanf", "@stdlib/math/base/special/truncf", + "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is_negative_zerof" ] }, @@ -55,6 +56,7 @@ "dependencies": [ "@stdlib/math/base/assert/is_nanf", "@stdlib/math/base/special/truncf", + "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is_negative_zerof" ] }, @@ -71,6 +73,7 @@ "dependencies": [ "@stdlib/math/base/assert/is_nanf", "@stdlib/math/base/special/truncf", + "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is_negative_zerof" ] } 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 index b910fdcf3c72..0d1890237d1c 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -19,6 +19,7 @@ #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" #include @@ -66,5 +67,5 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) { if ( vc < minc ) { vc += delta * ( stdlib_base_truncf( ( minc - vc ) / delta ) + 1.0 ); } - return minc + ( fmodf( vc - minc, delta ) ); + return minc + ( stdlib_base_fmodf( vc - minc, delta ) ); } From 888a513bfeaf0eba8e1f8304af98d7b644469f67 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 11 Nov 2024 13:50:39 +0530 Subject: [PATCH 03/17] update manifest.json --- .../@stdlib/math/base/special/wrapf/manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json b/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json index 5f1650cf76b7..ab57fb1ba58e 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json @@ -37,7 +37,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/ternary", - "@stdlib/math/base/assert/is_nanf", + "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/truncf", "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is_negative_zerof" @@ -54,7 +54,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is_nanf", + "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/truncf", "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is_negative_zerof" @@ -71,7 +71,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is_nanf", + "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/truncf", "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is_negative_zerof" From 611cb2edc7a6b72cc1ab5909254eb6b15a74f03e Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 11 Nov 2024 14:26:44 +0530 Subject: [PATCH 04/17] update manifest.json --- .../@stdlib/math/base/special/wrapf/manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json b/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json index ab57fb1ba58e..0d79bdce7a84 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/manifest.json @@ -40,7 +40,7 @@ "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/truncf", "@stdlib/math/base/special/fmodf", - "@stdlib/math/base/assert/is_negative_zerof" + "@stdlib/math/base/assert/is-negative-zerof" ] }, { @@ -57,7 +57,7 @@ "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/truncf", "@stdlib/math/base/special/fmodf", - "@stdlib/math/base/assert/is_negative_zerof" + "@stdlib/math/base/assert/is-negative-zerof" ] }, { @@ -74,7 +74,7 @@ "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/truncf", "@stdlib/math/base/special/fmodf", - "@stdlib/math/base/assert/is_negative_zerof" + "@stdlib/math/base/assert/is-negative-zerof" ] } ] From 8193eb75c3135bcc31575f4f83748281fb92711c Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 25 Nov 2024 19:10:14 +0530 Subject: [PATCH 05/17] refactor: as per suggested --- .../@stdlib/math/base/special/wrapf/README.md | 14 ++-- .../base/special/wrapf/benchmark/benchmark.js | 7 +- .../wrapf/benchmark/benchmark.native.js | 7 +- .../base/special/wrapf/benchmark/c/Makefile | 79 ++++++++++++++----- .../special/wrapf/benchmark/c/benchmark.c | 13 +-- .../wrapf/benchmark/c/native/benchmark.c | 9 ++- .../base/special/wrapf/examples/c/Makefile | 2 +- .../base/special/wrapf/examples/c/example.c | 6 +- .../math/base/special/wrapf/lib/index.js | 2 +- .../math/base/special/wrapf/lib/main.js | 10 ++- .../math/base/special/wrapf/lib/native.js | 2 +- .../math/base/special/wrapf/src/Makefile | 2 +- .../math/base/special/wrapf/src/main.c | 16 ++-- .../math/base/special/wrapf/test/test.js | 47 +++++------ .../base/special/wrapf/test/test.native.js | 14 ++-- 15 files changed, 140 insertions(+), 90 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md index 899204cb8eef..e7ba629581f4 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md @@ -42,7 +42,7 @@ var wrapf = require( '@stdlib/math/base/special/wrapf' ); #### wrapf( v, min, max ) -Wraps a value on the half-open interval `[min,max)`. +Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers. ```javascript var v = wrapf( 3.14, 0.0, 5.0 ); @@ -58,7 +58,7 @@ v = wrapf( -0.0, 0.0, 5.0 ); // returns 0.0 v = wrapf( 0.0, -3.14, -0.0 ); -// returns -3.14 +// returns ~-3.14 ``` If provided `NaN` for any argument, the function returns `NaN`. @@ -197,9 +197,9 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) #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 }; + 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; @@ -234,8 +234,6 @@ int main( void ) { ## See Also -- [`@stdlib/math/base/special/clampf`][@stdlib/math/base/special/clampf]: restrict a single-precision floating-point number to a specified range. - @@ -246,8 +244,6 @@ int main( void ) { -[@stdlib/math/base/special/clampf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/clampf - 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 index afb69c467eb4..9db07fbece31 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var randu = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var wrapf = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = randu( 100, -10.0, 10.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*20.0 ) - 10.0; - y = wrapf( x, -5.0, 5.0 ); + y = wrapf( x[ i%x.length ], -5.0, 5.0 ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } 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 index 9fbd80158e69..a8da486fb995 100644 --- 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 @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var randu = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = randu( 100, -10.0, 10.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*20.0 ) - 10.0; - y = wrapf( x, -5.0, 5.0 ); + y = wrapf( x[ i%x.length ], -5.0, 5.0 ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } 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 index ad9fedcd4fff..f69e9da2b4d3 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile @@ -16,14 +16,15 @@ # limitations under the License. #/ - # VARIABLES # ifndef VERBOSE QUIET := @ +else + QUIET := endif -# Determine the OS: +# Determine the OS ([1][1], [2][2]). # # [1]: https://en.wikipedia.org/wiki/Uname#Examples # [2]: http://stackoverflow.com/a/27776822/2225624 @@ -36,6 +37,10 @@ ifneq (, $(findstring MSYS,$(OS))) else ifneq (, $(findstring CYGWIN,$(OS))) OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif endif endif endif @@ -54,7 +59,7 @@ CFLAGS ?= \ -Wall \ -pedantic -# Determine whether to generate [position independent code][1]: +# 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 @@ -64,43 +69,77 @@ 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 -# TARGETS # +# RULES # -# Default target. +#/ +# Compiles source files. # -# This target is the default target. - +# @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 - -# Compile C source. +#/ +# Compiles C source files. # -# This target 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) -o $@ $< -lm - + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) -# Run a benchmark. +#/ +# Runs compiled benchmarks. # -# This target runs a benchmark. - +# @example +# make run +#/ run: $(c_targets) $(QUIET) ./$< .PHONY: run - -# Perform clean-up. +#/ +# Removes generated files. # -# This target removes generated files. - +# @example +# make clean +#/ clean: $(QUIET) -rm -f *.o *.out 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 index 7db9ad13ee53..2a2c45e73b1f 100644 --- 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 @@ -99,9 +99,9 @@ float wrapf( float v, float min, float max ) { // Perform range reduction... delta = max - min; if ( v < min ) { - v += delta * ( truncf( (min-v)/delta ) + 1.0 ); + v += delta * ( truncf( ( min - v ) / delta ) + 1.0 ); } - return min + fmodf( (v-min), delta ); + return min + fmodf( ( v - min ), delta ); } /** @@ -112,14 +112,17 @@ float wrapf( float v, float min, float max ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 20.0f * rand_float() ) - 10.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 20.0*rand_float() ) - 10.0; - y = wrapf( x, -5.0, 5.0 ); + y = wrapf( x[ i%100 ], -5.0, 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 index 3cc3bf67a820..26c8019273d0 100644 --- 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 @@ -92,14 +92,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 20.0f * rand_float() ) - 10.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 20.0*rand_float() ) - 10.0; - y = stdlib_base_wrapf( x, -5.0, 5.0 ); + y = wrapf( x[ i%100 ], -5.0, 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 index 91d364d19fc3..6aed70daf167 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2022 The Stdlib Authors. +# Copyright (c) 2024 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. 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 index 0bb3c9964d46..547ee06db833 100644 --- 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 @@ -20,9 +20,9 @@ #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 }; + 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; diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js index 44cfae3e1ce5..ecc7f56dc153 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js @@ -27,7 +27,7 @@ * var wrapf = require( '@stdlib/math/base/special/wrapf' ); * * var v = wrapf( 3.14, 0.0, 5.0 ); -* // returns 3.14 +* // returns ~3.14 * * v = wrapf( -3.14, 0.0, 5.0 ); * // returns ~1.86 diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js index e64e1be47404..07351681bdf5 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js @@ -22,6 +22,7 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var truncf = require( '@stdlib/math/base/special/truncf' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); // MAIN // @@ -36,7 +37,7 @@ var truncf = require( '@stdlib/math/base/special/truncf' ); * * @example * var v = wrapf( 3.14, 0.0, 5.0 ); -* // returns 3.14 +* // returns ~3.14 * * v = wrapf( -3.14, 0.0, 5.0 ); * // returns ~1.86 @@ -72,6 +73,7 @@ function wrapf( v, min, max ) { ) { return NaN; } + // Normalize +-0 to +0... if ( v === 0.0 ) { v = 0.0; @@ -82,16 +84,18 @@ function wrapf( v, min, max ) { if ( max === 0.0 ) { max = 0.0; } + // Simple case where value is already within range... if ( min <= v && v < max ) { return v; } + // Perform range reduction... delta = max - min; if ( v < min ) { - v += delta * ( truncf( (min-v)/delta ) + 1.0 ); + v += delta * ( truncf( ( min - v ) / delta ) + 1.0 ); } - return min + ( (v-min) % delta ); + return float64ToFloat32( float64ToFloat32( min ) + float64ToFloat32( float64ToFloat32( float64ToFloat32( v ) - float64ToFloat32( min ) ) % float64ToFloat32( delta ) ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js index 12d3b8286484..dfb919f7d4a7 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js @@ -36,7 +36,7 @@ var addon = require( './../src/addon.node' ); * * @example * var v = wrapf( 3.14, 0.0, 5.0 ); -* // returns 3.14 +* // returns ~3.14 * * v = wrapf( -3.14, 0.0, 5.0 ); * // returns ~1.86 diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile index f79b87238713..bcf18aa46655 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2022 The Stdlib Authors. +# Copyright (c) 2024 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. 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 index 0d1890237d1c..07ca17464a91 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ * @return wrapped value * * @example -* float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 ); +* float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f ); * // returns 3.14 */ float stdlib_base_wrapf( const float v, const float min, const float max ) { @@ -42,7 +42,7 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) { float vc; if ( stdlib_base_is_nanf( v ) || stdlib_base_is_nanf( min ) || stdlib_base_is_nanf( max ) || max <= min ) { - return 0.0 / 0.0; // NaN + return 0.0f / 0.0f; // NaN } maxc = max; minc = min; @@ -50,22 +50,24 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) { // Normalize +-0 to +0... if ( stdlib_base_is_negative_zerof( vc ) ) { - vc = 0.0; + vc = 0.0f; } if ( stdlib_base_is_negative_zerof( minc ) ) { - minc = 0.0; + minc = 0.0f; } if ( stdlib_base_is_negative_zerof( maxc ) ) { - maxc = 0.0; + 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.0 ); + 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 index 977f2628d077..7d04d0fadae5 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var wrapf = require( './../lib' ); @@ -38,25 +39,25 @@ tape( 'if provided `NaN` for any argument, the function returns `NaN`', function var v; v = wrapf( NaN, 0.0, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( 0.0, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -83,49 +84,49 @@ tape( 'if provided a value which less than a minimum value or greater than or eq var v; v = wrapf( 13.00, 0.0, 5.0 ); - t.strictEqual( v, 3.00, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); v = wrapf( -3.15, 0.0, 5.0 ); - t.strictEqual( v, 1.85, 'returns expected value' ); + t.equal( v, float64ToFloat32( 1.85 ), 'returns expected value' ); - v = wrapf( -13.14, -10.0, 15.0 ); - t.strictEqual( v, 11.86, 'returns expected value' ); + v = wrapf( -13.1, -10.0, 15.0 ); + t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); v = wrapf( 10.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( -10.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, -5.0, 0.0 ); - t.strictEqual( v, -5.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -5.0 ), 'returns expected value' ); v = wrapf( 30.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( 31.0, 0.0, 5.0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 1.0 ), 'returns expected value' ); v = wrapf( -31.0, -5.0, 0.0 ); - t.strictEqual( v, -1.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -1.0 ), 'returns expected value' ); v = wrapf( 0.0, -3.14, 0.0 ); - t.strictEqual( v, -3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, -0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, 0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, 0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, -0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), '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 index 7f500c86a497..74a26daeb23a 100644 --- 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 @@ -47,25 +47,25 @@ tape( 'if provided `NaN` for any argument, the function returns `NaN`', opts, fu var v; v = wrapf( NaN, 0.0, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( 0.0, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); From 76cfcbebe14392aab0c1eaca80d67f8c7ecb4e2b Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 25 Nov 2024 19:21:30 +0530 Subject: [PATCH 06/17] fix: benchmark and test file --- .../wrapf/benchmark/c/native/benchmark.c | 2 +- .../base/special/wrapf/test/test.native.js | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) 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 index 26c8019273d0..b3b1976d4ca7 100644 --- 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 @@ -102,7 +102,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = wrapf( x[ i%100 ], -5.0, 5.0 ); + y = stdlib_base_wrapf( x[ i%100 ], -5.0, 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 index 74a26daeb23a..bf558eff9681 100644 --- 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 @@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -88,53 +89,53 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma 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 ) { +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' ); + t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); v = wrapf( -3.15, 0.0, 5.0 ); - t.strictEqual( v, 1.85, 'returns expected value' ); + t.equal( v, float64ToFloat32( 1.85 ), 'returns expected value' ); - v = wrapf( -13.14, -10.0, 15.0 ); - t.strictEqual( v, 11.86, 'returns expected value' ); + v = wrapf( -13.1, -10.0, 15.0 ); + t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); v = wrapf( 10.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( -10.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, -5.0, 0.0 ); - t.strictEqual( v, -5.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -5.0 ), 'returns expected value' ); v = wrapf( 30.0, 0.0, 5.0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); v = wrapf( 31.0, 0.0, 5.0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( 1.0 ), 'returns expected value' ); v = wrapf( -31.0, -5.0, 0.0 ); - t.strictEqual( v, -1.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -1.0 ), 'returns expected value' ); v = wrapf( 0.0, -3.14, 0.0 ); - t.strictEqual( v, -3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, -0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, 0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, 0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, -0.0 ); - t.strictEqual( v, -10.0, 'returns expected value' ); + t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); t.end(); }); From 4c803d1f0fe75e34bf1cbca182e3f22ff04ff17e Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 25 Nov 2024 19:24:27 +0530 Subject: [PATCH 07/17] fix: lint errors --- lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 8042269a5b43..730522f0f149 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt @@ -27,7 +27,7 @@ Examples -------- > var y = {{alias}}( 3.14, 0.0, 5.0 ) - 3.14 + ~3.14 > y = {{alias}}( -3.14, 0.0, 5.0 ) ~1.86 > y = {{alias}}( 3.14, 0.0, 3.0 ) From 0ee478ebad8b5254b4b5dfe4c89f995faa94cf01 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Mon, 25 Nov 2024 19:58:27 +0530 Subject: [PATCH 08/17] fix: errors --- .../@stdlib/math/base/special/wrapf/docs/repl.txt | 4 ++-- .../@stdlib/math/base/special/wrapf/lib/main.js | 2 +- .../@stdlib/math/base/special/wrapf/test/test.js | 12 ++++++------ .../math/base/special/wrapf/test/test.native.js | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) 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 index 730522f0f149..dfff6b456d31 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt @@ -33,9 +33,9 @@ > y = {{alias}}( 3.14, 0.0, 3.0 ) ~0.14 > y = {{alias}}( -0.0, 0.0, 5.0 ) - 0.0 + ~0.0 > y = {{alias}}( 0.0, -3.14, -0.0 ) - -3.14 + ~-3.14 > y = {{alias}}( NaN, 0.0, 5.0 ) NaN diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js index 07351681bdf5..ce11e044fc7d 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js @@ -87,7 +87,7 @@ function wrapf( v, min, max ) { // Simple case where value is already within range... if ( min <= v && v < max ) { - return v; + return float64ToFloat32( v ); } // Perform range reduction... 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 index 7d04d0fadae5..785319ce3f9d 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -66,16 +66,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma var v; v = wrapf( 3.14, 0.0, 5.0 ); - t.strictEqual( v, 3.14, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); v = wrapf( -3.14, -10.0, 15.0 ); - t.strictEqual( v, -3.14, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), -3.14, 'returns expected value' ); v = wrapf( 3.14, 3.14, 5.0 ); - t.strictEqual( v, 3.14, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); v = wrapf( 3.13, 0.0, 3.14 ); - t.strictEqual( v, 3.13, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), 3.13, 'returns expected value' ); t.end(); }); @@ -86,8 +86,8 @@ tape( 'if provided a value which less than a minimum value or greater than or eq v = wrapf( 13.00, 0.0, 5.0 ); t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); - v = wrapf( -3.15, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 1.85 ), 'returns expected value' ); + v = wrapf( -3.1, 0.0, 5.0 ); + t.equal( v, float64ToFloat32( 1.90 ), 'returns expected value' ); v = wrapf( -13.1, -10.0, 15.0 ); t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); 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 index bf558eff9681..dc8f4707eeb1 100644 --- 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 @@ -75,28 +75,28 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma var v; v = wrapf( 3.14, 0.0, 5.0 ); - t.strictEqual( v, 3.14, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); v = wrapf( -3.14, -10.0, 15.0 ); - t.strictEqual( v, -3.14, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), -3.14, 'returns expected value' ); v = wrapf( 3.14, 3.14, 5.0 ); - t.strictEqual( v, 3.14, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); v = wrapf( 3.13, 0.0, 3.14 ); - t.strictEqual( v, 3.13, 'returns expected value' ); + t.strictEqual( float64ToFloat32( v ), 3.13, 'returns expected value' ); 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 ) { +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.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); - v = wrapf( -3.15, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 1.85 ), 'returns expected value' ); + v = wrapf( -3.1, 0.0, 5.0 ); + t.equal( v, float64ToFloat32( 1.90 ), 'returns expected value' ); v = wrapf( -13.1, -10.0, 15.0 ); t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); From dfe57f20c50c2a44e7fa7417585866b36621127f Mon Sep 17 00:00:00 2001 From: Gururaj Gurram Date: Tue, 17 Dec 2024 02:35:21 +0530 Subject: [PATCH 09/17] fix: lint errors --- .../@stdlib/math/base/special/wrapf/README.md | 8 +--- .../base/special/wrapf/docs/types/index.d.ts | 2 +- .../math/base/special/wrapf/src/main.c | 2 +- .../math/base/special/wrapf/test/test.js | 38 +++++++++---------- .../base/special/wrapf/test/test.native.js | 38 +++++++++---------- 5 files changed, 42 insertions(+), 46 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md index e7ba629581f4..41e8bff1a58b 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md @@ -46,7 +46,7 @@ Wrap a value on the half-open interval `[min,max)` for single-precision floating ```javascript var v = wrapf( 3.14, 0.0, 5.0 ); -// returns 3.14 +// returns ~3.14 v = wrapf( -3.14, 0.0, 5.0 ); // returns ~1.86 @@ -158,7 +158,7 @@ Wraps a value on the half-open interval `[min,max)` for single-precision floatin ```c float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 ); -// returns 3.14 +// returns ~3.14 v = stdlib_base_wrapf( -3.14, 0.0, 5.0 ); // returns ~1.86 @@ -230,10 +230,6 @@ int main( void ) { 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 index 9a1985a99f88..4050333c791c 100644 --- 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 @@ -28,7 +28,7 @@ * * @example * var v = wrapf( 3.14, 0.0, 5.0 ); -* // returns 3.14 +* // returns ~3.14 * * v = wrapf( -3.14, 0.0, 5.0 ); * // returns ~1.86 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 index 07ca17464a91..81aa15a2b370 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -33,7 +33,7 @@ * * @example * float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f ); -* // returns 3.14 +* // returns ~3.14 */ float stdlib_base_wrapf( const float v, const float min, const float max ) { float 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 index 785319ce3f9d..5de0af7d9490 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -39,25 +39,25 @@ tape( 'if provided `NaN` for any argument, the function returns `NaN`', function var v; v = wrapf( NaN, 0.0, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 0.0, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -66,16 +66,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma var v; v = wrapf( 3.14, 0.0, 5.0 ); - t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); v = wrapf( -3.14, -10.0, 15.0 ); - t.strictEqual( float64ToFloat32( v ), -3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); v = wrapf( 3.14, 3.14, 5.0 ); - t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); v = wrapf( 3.13, 0.0, 3.14 ); - t.strictEqual( float64ToFloat32( v ), 3.13, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.13 ), 'returns expected value' ); t.end(); }); @@ -135,16 +135,16 @@ tape( 'the function does not distinguish between positive and negative zero', fu var v; v = wrapf( -0.0, 0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); v = wrapf( 0.0, -0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); v = wrapf( -0.0, -0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); v = wrapf( 0.0, 0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -153,16 +153,16 @@ tape( 'the function returns `NaN` if provided a maximum value which is less than var v; v = wrapf( 3.14, 10.0, 0.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 10.0, 10.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 3.0, 1.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 1.0, 1.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( 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 index dc8f4707eeb1..e187abdffdd8 100644 --- 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 @@ -48,25 +48,25 @@ tape( 'if provided `NaN` for any argument, the function returns `NaN`', opts, fu var v; v = wrapf( NaN, 0.0, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 0.0, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, 5.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, 0.0, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( NaN, NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -75,16 +75,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma var v; v = wrapf( 3.14, 0.0, 5.0 ); - t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); v = wrapf( -3.14, -10.0, 15.0 ); - t.strictEqual( float64ToFloat32( v ), -3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); v = wrapf( 3.14, 3.14, 5.0 ); - t.strictEqual( float64ToFloat32( v ), 3.14, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); v = wrapf( 3.13, 0.0, 3.14 ); - t.strictEqual( float64ToFloat32( v ), 3.13, 'returns expected value' ); + t.equal( v, float64ToFloat32( 3.13 ), 'returns expected value' ); t.end(); }); @@ -144,16 +144,16 @@ tape( 'the function does not distinguish between positive and negative zero', op var v; v = wrapf( -0.0, 0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); v = wrapf( 0.0, -0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); v = wrapf( -0.0, -0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); v = wrapf( 0.0, 0.0, 5.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -162,16 +162,16 @@ tape( 'the function returns `NaN` if provided a maximum value which is less than var v; v = wrapf( 3.14, 10.0, 0.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 10.0, 10.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 3.0, 1.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); v = wrapf( 3.14, 1.0, 1.0 ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.equal( isnanf( v ), true, 'returns expected value' ); t.end(); }); From 1f0f48e8826a7c89767790dca8990f08bfc59443 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sun, 12 Jan 2025 09:17:51 +0000 Subject: [PATCH 10/17] feat: fix test cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js | 3 --- .../@stdlib/math/base/special/wrapf/test/test.native.js | 3 --- 2 files changed, 6 deletions(-) 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 index 5de0af7d9490..cffb84d4dac9 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -86,9 +86,6 @@ tape( 'if provided a value which less than a minimum value or greater than or eq v = wrapf( 13.00, 0.0, 5.0 ); t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); - v = wrapf( -3.1, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 1.90 ), 'returns expected value' ); - v = wrapf( -13.1, -10.0, 15.0 ); t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); 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 index e187abdffdd8..3dacc2db3fcc 100644 --- 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 @@ -95,9 +95,6 @@ tape( 'if provided a value which less than a minimum value or greater than or eq v = wrapf( 13.00, 0.0, 5.0 ); t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); - v = wrapf( -3.1, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 1.90 ), 'returns expected value' ); - v = wrapf( -13.1, -10.0, 15.0 ); t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); From f4fce9519961a83d7ccbb7c6b43ce3c844629341 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sun, 12 Jan 2025 10:12:11 +0000 Subject: [PATCH 11/17] chore: update copyright years --- lib/node_modules/@stdlib/math/base/special/wrapf/README.md | 2 +- .../@stdlib/math/base/special/wrapf/benchmark/benchmark.js | 2 +- .../math/base/special/wrapf/benchmark/benchmark.native.js | 2 +- .../@stdlib/math/base/special/wrapf/benchmark/c/Makefile | 2 +- .../@stdlib/math/base/special/wrapf/benchmark/c/benchmark.c | 2 +- .../@stdlib/math/base/special/wrapf/benchmark/c/native/Makefile | 2 +- .../math/base/special/wrapf/benchmark/c/native/benchmark.c | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp | 2 +- .../@stdlib/math/base/special/wrapf/docs/types/index.d.ts | 2 +- .../@stdlib/math/base/special/wrapf/docs/types/test.ts | 2 +- .../@stdlib/math/base/special/wrapf/examples/c/Makefile | 2 +- .../@stdlib/math/base/special/wrapf/examples/c/example.c | 2 +- .../@stdlib/math/base/special/wrapf/examples/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi | 2 +- .../base/special/wrapf/include/stdlib/math/base/special/wrapf.h | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c | 2 +- lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js | 2 +- .../@stdlib/math/base/special/wrapf/test/test.native.js | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md index 41e8bff1a58b..beeb90824532 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +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. 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 index 9db07fbece31..8d653acf39b3 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index a8da486fb995..d4a29c450429 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index f69e9da2b4d3..a4bd7b38fd74 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# 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. 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 index 2a2c45e73b1f..2336a2c32e70 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index f69e9da2b4d3..a4bd7b38fd74 100644 --- 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 @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# 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. 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 index b3b1976d4ca7..8eb3e18fbbe3 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp index ec3992233442..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# 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. 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 index 4050333c791c..682e62d50253 100644 --- 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 @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index e1f441799a49..482ad7fefb9e 100644 --- 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 @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index 6aed70daf167..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# 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. 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 index 547ee06db833..3ad69688a8f8 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index ff5b26021a91..d47c7d821cbe 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi b/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi index 575cb043c0bf..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h b/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h index fdbbb60e6c0c..18088194f6ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js index ecc7f56dc153..4fb64b6dbc7c 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js index ce11e044fc7d..857500bcb36c 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js index dfb919f7d4a7..be5c5e35c584 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile index bcf18aa46655..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# 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. 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 index 6e7a6df71364..f0c22f25dbbf 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index 81aa15a2b370..9195a6397df9 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index cffb84d4dac9..f5a1c7d14563 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. 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 index 3dacc2db3fcc..ae44df5922f1 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. From 97f09fb44e357369d5898eb8e94f3fd54a663ec7 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sun, 12 Jan 2025 10:28:19 +0000 Subject: [PATCH 12/17] fix: lint errors --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 9195a6397df9..00b51d3fbf6d 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -63,7 +63,7 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) { if ( minc <= vc && vc < maxc ) { return vc; } - + // Perform range reduction... delta = maxc - minc; if ( vc < minc ) { From a36eaf0162443924bb9dc593e0a95e01e44ef052 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 1 Jun 2025 12:55:58 -0700 Subject: [PATCH 13/17] refactor: apply suggestions from PR review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/wrapf/README.md | 34 +++++++------ .../base/special/wrapf/benchmark/benchmark.js | 6 ++- .../wrapf/benchmark/benchmark.native.js | 6 ++- .../special/wrapf/benchmark/c/benchmark.c | 12 ++--- .../wrapf/benchmark/c/native/benchmark.c | 6 +-- .../math/base/special/wrapf/docs/repl.txt | 4 +- .../base/special/wrapf/docs/types/index.d.ts | 2 +- .../base/special/wrapf/examples/c/example.c | 2 +- .../math/base/special/wrapf/examples/index.js | 20 ++++---- .../include/stdlib/math/base/special/wrapf.h | 2 +- .../math/base/special/wrapf/lib/index.js | 2 +- .../math/base/special/wrapf/lib/main.js | 31 +++++++----- .../math/base/special/wrapf/lib/native.js | 2 +- .../math/base/special/wrapf/package.json | 3 +- .../math/base/special/wrapf/src/addon.c | 1 - .../math/base/special/wrapf/src/main.c | 7 +-- .../math/base/special/wrapf/test/test.js | 48 +++++++++---------- .../base/special/wrapf/test/test.native.js | 48 +++++++++---------- 18 files changed, 120 insertions(+), 116 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md index beeb90824532..12d273559869 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md @@ -20,7 +20,7 @@ limitations under the License. # wrapf -> Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +> Wrap a single-precision floating-point value to the half-open interval `[min,max)`. @@ -42,7 +42,7 @@ var wrapf = require( '@stdlib/math/base/special/wrapf' ); #### wrapf( v, min, max ) -Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +Wraps a single-precision floating-point value to the half-open interval `[min,max)`. ```javascript var v = wrapf( 3.14, 0.0, 5.0 ); @@ -106,20 +106,18 @@ var v = wrapf( 3.14, 3.0, 3.0 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var wrapf = require( '@stdlib/math/base/special/wrapf' ); -var min; -var max; -var v; -var i; +var opts = { + 'dtype': 'float32' +}; +var min = uniform( 100, 0.0, 10.0, opts ); +var max = uniform( 100, 5.0, 15.0, opts ); +var v = uniform( 100, -20.0, 20.0, opts ); -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 ) ); -} +logEachMap( 'wrapf(%0.4f,%0.4f,%0.4f) => %0.4f', v, min, max, wrapf ); ``` @@ -154,14 +152,14 @@ for ( i = 0; i < 100; i++ ) { #### stdlib_base_wrapf( v, min, max ) -Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +Wrap a single-precision floating-point value to the half-open interval `[min,max)`. ```c -float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 ); -// returns ~3.14 +float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f ); +// returns ~3.14f -v = stdlib_base_wrapf( -3.14, 0.0, 5.0 ); -// returns ~1.86 +v = stdlib_base_wrapf( -3.14f, 0.0f, 5.0f ); +// returns ~1.86f ``` The function accepts the following arguments: 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 index 8d653acf39b3..c73ce5fc71d4 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var wrapf = require( './../lib' ); @@ -34,7 +34,9 @@ bench( pkg, function benchmark( b ) { var y; var i; - x = randu( 100, -10.0, 10.0 ); + x = uniform( 100, -10.0, 10.0, { + 'dtype': 'float32' + }); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 index d4a29c450429..9dcd598b9910 100644 --- 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 @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,7 +43,9 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - x = randu( 100, -10.0, 10.0 ); + x = uniform( 100, -10.0, 10.0, { + 'dtype': 'float32' + }); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 index 2336a2c32e70..5b312592535a 100644 --- 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 @@ -89,7 +89,7 @@ static float rand_float( void ) { * @param v value to wrap * @param min minimum value * @param max maximum value -* @return wrapped value +* @return wrapped value */ float wrapf( float v, float min, float max ) { float delta; @@ -99,9 +99,9 @@ float wrapf( float v, float min, float max ) { // Perform range reduction... delta = max - min; if ( v < min ) { - v += delta * ( truncf( ( min - v ) / delta ) + 1.0 ); + v += delta * ( truncf( (min-v)/delta ) + 1.0f ); } - return min + fmodf( ( v - min ), delta ); + return min + fmodf( (v-min), delta ); } /** @@ -111,18 +111,18 @@ float wrapf( float v, float min, float max ) { */ static double benchmark( void ) { double elapsed; - double t; float x[ 100 ]; + double t; float y; int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 20.0f * rand_float() ) - 10.0f; + x[ i ] = ( 20.0f*rand_float() ) - 10.0f; } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = wrapf( x[ i%100 ], -5.0, 5.0 ); + y = wrapf( x[ i%100 ], -5.0f, 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 index 8eb3e18fbbe3..929213f5d1e6 100644 --- 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 @@ -91,18 +91,18 @@ static float rand_float( void ) { */ static double benchmark( void ) { double elapsed; - double t; float x[ 100 ]; + double t; float y; int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 20.0f * rand_float() ) - 10.0f; + x[ i ] = ( 20.0f*rand_float() ) - 10.0f; } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_wrapf( x[ i%100 ], -5.0, 5.0 ); + y = stdlib_base_wrapf( x[ i%100 ], -5.0f, 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 index dfff6b456d31..986f99fff9d1 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( v, min, max ) - Wraps a value on the half-open interval `[min,max)` for single-precision - floating-point numbers. + Wraps a single-precision floating-point value to the half-open interval + `[min,max)`. The function does not distinguish between positive and negative zero. Where appropriate, the function returns positive zero. 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 index 682e62d50253..12256031d0a7 100644 --- 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 @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /** -* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +* Wraps a single-precision floating-point value to the half-open interval `[min,max)`. * * @param v - input value * @param min - minimum value 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 index 3ad69688a8f8..c311241355ec 100644 --- 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 @@ -28,6 +28,6 @@ int main( void ) { int i; for ( i = 0; i < 5; i++ ) { out = stdlib_base_wrapf( v[i], min[i], max[i] ); - printf( "wrap(%f,%f,%f) => %f\n", v[i], min[i], max[i], out ); + 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 index d47c7d821cbe..829123da4bb9 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js @@ -18,17 +18,15 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var wrapf = require( './../lib' ); -var min; -var max; -var v; -var i; +var opts = { + 'dtype': 'float32' +}; +var min = uniform( 100, 0.0, 10.0, opts ); +var max = uniform( 100, 5.0, 15.0, opts ); +var v = uniform( 100, -20.0, 20.0, opts ); -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 ) ); -} +logEachMap( 'wrapf(%0.4f,%0.4f,%0.4f) => %0.4f', v, min, max, wrapf ); diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h b/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h index 18088194f6ed..eb9e0ca98cbc 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -* Wraps a value on the half-open interval [min,max) for single-precision floating-point numbers. +* Wraps a single-precision floating-point value to the half-open interval [min,max). */ float stdlib_base_wrapf( const float v, const float min, const float max ); diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js index 4fb64b6dbc7c..b73d221cf5d0 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +* Wrap a single-precision floating-point value to the half-open interval `[min,max)`. * * @module @stdlib/math/base/special/wrapf * diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js index 857500bcb36c..9ab326c4c1fd 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js @@ -22,13 +22,19 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var truncf = require( '@stdlib/math/base/special/truncf' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// VARIABLES // + +var ZERO = f32( 0.0 ); +var ONE = f32( 1.0 ); // MAIN // /** -* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +* Wraps a single-precision floating-point value to the half-open interval `[min,max)`. * * @param {number} v - input value * @param {number} min - minimum value @@ -65,6 +71,10 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); */ function wrapf( v, min, max ) { var delta; + + v = f32( v ); + min = f32( min ); + max = f32( max ); if ( isnanf( v ) || isnanf( min ) || @@ -73,29 +83,26 @@ function wrapf( v, min, max ) { ) { return NaN; } - // Normalize +-0 to +0... if ( v === 0.0 ) { - v = 0.0; + v = ZERO; } if ( min === 0.0 ) { - min = 0.0; + min = ZERO; } if ( max === 0.0 ) { - max = 0.0; + max = ZERO; } - // Simple case where value is already within range... if ( min <= v && v < max ) { - return float64ToFloat32( v ); + return v; } - // Perform range reduction... - delta = max - min; + delta = f32( max - min ); if ( v < min ) { - v += delta * ( truncf( ( min - v ) / delta ) + 1.0 ); + v = f32( v + f32( delta * f32( truncf( f32(min-v) / f32(delta) ) + ONE ) ) ); } - return float64ToFloat32( float64ToFloat32( min ) + float64ToFloat32( float64ToFloat32( float64ToFloat32( v ) - float64ToFloat32( min ) ) % float64ToFloat32( delta ) ) ); + return f32( min + f32( f32( v-min ) % delta ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js index be5c5e35c584..e519307405fd 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers. +* Wraps a single-precision floating-point value to the half-open interval `[min,max)`. * * @private * @param {number} v - input value diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/package.json b/lib/node_modules/@stdlib/math/base/special/wrapf/package.json index 682b21921001..455211893642 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/wrapf", "version": "0.0.0", - "description": "Wrap a value on the half-open interval [min,max) for single-precision floating-point numbers", + "description": "Wrap a single-precision floating-point value to the half-open interval [min,max).", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -57,6 +57,7 @@ "mathematics", "math", "wrap", + "wrapf", "modulo", "mod", "range", 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 index f0c22f25dbbf..425a1b0da47e 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c @@ -19,5 +19,4 @@ #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 index 00b51d3fbf6d..5c1a5c7ce225 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c @@ -21,10 +21,9 @@ #include "stdlib/math/base/special/truncf.h" #include "stdlib/math/base/special/fmodf.h" #include "stdlib/math/base/assert/is_negative_zerof.h" -#include /** -* Wraps a value on the half-open interval [min,max) for single-precision floating-point numbers. +* Wraps a single-precision floating-point value to the half-open interval [min,max). * * @param v input value * @param min minimum value @@ -33,7 +32,7 @@ * * @example * float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f ); -* // returns ~3.14 +* // returns ~3.14f */ float stdlib_base_wrapf( const float v, const float min, const float max ) { float delta; @@ -58,12 +57,10 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) { 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 ) { 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 index f5a1c7d14563..d08c68277e02 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/test/test.js @@ -22,8 +22,8 @@ var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); var wrapf = require( './../lib' ); @@ -66,16 +66,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma var v; v = wrapf( 3.14, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); + t.equal( v, f32( 3.14 ), 'returns expected value' ); v = wrapf( -3.14, -10.0, 15.0 ); - t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); + t.equal( v, f32( -3.14 ), 'returns expected value' ); v = wrapf( 3.14, 3.14, 5.0 ); - t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); + t.equal( v, f32( 3.14 ), 'returns expected value' ); v = wrapf( 3.13, 0.0, 3.14 ); - t.equal( v, float64ToFloat32( 3.13 ), 'returns expected value' ); + t.equal( v, f32( 3.13 ), 'returns expected value' ); t.end(); }); @@ -84,46 +84,46 @@ tape( 'if provided a value which less than a minimum value or greater than or eq var v; v = wrapf( 13.00, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); + t.equal( v, f32( 3.00 ), 'returns expected value' ); v = wrapf( -13.1, -10.0, 15.0 ); - t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); + t.equal( v, f32( 11.90 ), 'returns expected value' ); v = wrapf( 10.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( -10.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, -5.0, 0.0 ); - t.equal( v, float64ToFloat32( -5.0 ), 'returns expected value' ); + t.equal( v, f32( -5.0 ), 'returns expected value' ); v = wrapf( 30.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( 31.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 1.0 ), 'returns expected value' ); + t.equal( v, f32( 1.0 ), 'returns expected value' ); v = wrapf( -31.0, -5.0, 0.0 ); - t.equal( v, float64ToFloat32( -1.0 ), 'returns expected value' ); + t.equal( v, f32( -1.0 ), 'returns expected value' ); v = wrapf( 0.0, -3.14, 0.0 ); - t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); + t.equal( v, f32( -3.14 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, -0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, 0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, 0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, -0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); t.end(); }); @@ -132,16 +132,16 @@ tape( 'the function does not distinguish between positive and negative zero', fu var v; v = wrapf( -0.0, 0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); v = wrapf( 0.0, -0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); v = wrapf( -0.0, -0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); v = wrapf( 0.0, 0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( 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 index ae44df5922f1..3e30405f384a 100644 --- 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 @@ -23,8 +23,8 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zerof' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -75,16 +75,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma var v; v = wrapf( 3.14, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); + t.equal( v, f32( 3.14 ), 'returns expected value' ); v = wrapf( -3.14, -10.0, 15.0 ); - t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); + t.equal( v, f32( -3.14 ), 'returns expected value' ); v = wrapf( 3.14, 3.14, 5.0 ); - t.equal( v, float64ToFloat32( 3.14 ), 'returns expected value' ); + t.equal( v, f32( 3.14 ), 'returns expected value' ); v = wrapf( 3.13, 0.0, 3.14 ); - t.equal( v, float64ToFloat32( 3.13 ), 'returns expected value' ); + t.equal( v, f32( 3.13 ), 'returns expected value' ); t.end(); }); @@ -93,46 +93,46 @@ tape( 'if provided a value which less than a minimum value or greater than or eq var v; v = wrapf( 13.00, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 3.00 ), 'returns expected value' ); + t.equal( v, f32( 3.00 ), 'returns expected value' ); v = wrapf( -13.1, -10.0, 15.0 ); - t.equal( v, float64ToFloat32( 11.90 ), 'returns expected value' ); + t.equal( v, f32( 11.90 ), 'returns expected value' ); v = wrapf( 10.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( -10.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( -30.0, -5.0, 0.0 ); - t.equal( v, float64ToFloat32( -5.0 ), 'returns expected value' ); + t.equal( v, f32( -5.0 ), 'returns expected value' ); v = wrapf( 30.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 0.0 ), 'returns expected value' ); + t.equal( v, f32( 0.0 ), 'returns expected value' ); v = wrapf( 31.0, 0.0, 5.0 ); - t.equal( v, float64ToFloat32( 1.0 ), 'returns expected value' ); + t.equal( v, f32( 1.0 ), 'returns expected value' ); v = wrapf( -31.0, -5.0, 0.0 ); - t.equal( v, float64ToFloat32( -1.0 ), 'returns expected value' ); + t.equal( v, f32( -1.0 ), 'returns expected value' ); v = wrapf( 0.0, -3.14, 0.0 ); - t.equal( v, float64ToFloat32( -3.14 ), 'returns expected value' ); + t.equal( v, f32( -3.14 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, -0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, 0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); v = wrapf( 0.0, -10.0, 0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); v = wrapf( -0.0, -10.0, -0.0 ); - t.equal( v, float64ToFloat32( -10.0 ), 'returns expected value' ); + t.equal( v, f32( -10.0 ), 'returns expected value' ); t.end(); }); @@ -141,16 +141,16 @@ tape( 'the function does not distinguish between positive and negative zero', op var v; v = wrapf( -0.0, 0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); v = wrapf( 0.0, -0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); v = wrapf( -0.0, -0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); v = wrapf( 0.0, 0.0, 5.0 ); - t.equal( isPositiveZero( v ), true, 'returns expected value' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); t.end(); }); From 2f59047fbdd0b8035e5b6be9c1922ab02fed7683 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 2 Jun 2025 15:23:51 -0700 Subject: [PATCH 14/17] docs: fix description Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/special/wrapf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md index 12d273559869..7ce1ae1ad06e 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/README.md @@ -152,7 +152,7 @@ logEachMap( 'wrapf(%0.4f,%0.4f,%0.4f) => %0.4f', v, min, max, wrapf ); #### stdlib_base_wrapf( v, min, max ) -Wrap a single-precision floating-point value to the half-open interval `[min,max)`. +Wraps a single-precision floating-point value to the half-open interval `[min,max)`. ```c float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f ); From d6b9e6949d89b260e8b539ab5746e3dabe46bed5 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 2 Jun 2025 15:25:37 -0700 Subject: [PATCH 15/17] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/wrapf/benchmark/c/benchmark.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 5b312592535a..3d93643fdc7f 100644 --- 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 @@ -91,7 +91,7 @@ static float rand_float( void ) { * @param max maximum value * @return wrapped value */ -float wrapf( float v, float min, float max ) { +static float wrapf( float v, float min, float max ) { float delta; if ( min <= v && v < max ) { return v; @@ -101,7 +101,7 @@ float wrapf( float v, float min, float max ) { if ( v < min ) { v += delta * ( truncf( (min-v)/delta ) + 1.0f ); } - return min + fmodf( (v-min), delta ); + return min + fmodf( v-min, delta ); } /** From fe1b10e0251b4b0f5c2b53fe6a1c0a875d3f9402 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 2 Jun 2025 15:29:01 -0700 Subject: [PATCH 16/17] docs: fix comment Signed-off-by: Athan --- .../base/special/wrapf/include/stdlib/math/base/special/wrapf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h b/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h index eb9e0ca98cbc..de3e98ebd38f 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h @@ -35,4 +35,4 @@ float stdlib_base_wrapf( const float v, const float min, const float max ); } #endif -#endif // !STDLIB_MATH_BASE_SPECIAL_WRAP_H +#endif // !STDLIB_MATH_BASE_SPECIAL_WRAPF_H From a249870f24d08b3e4702ceee6104c755d88041ae Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 2 Jun 2025 15:31:21 -0700 Subject: [PATCH 17/17] refactor: move parens Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js index 9ab326c4c1fd..e00450adbd6e 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js @@ -100,7 +100,7 @@ function wrapf( v, min, max ) { // Perform range reduction... delta = f32( max - min ); if ( v < min ) { - v = f32( v + f32( delta * f32( truncf( f32(min-v) / f32(delta) ) + ONE ) ) ); + v = f32( v + f32( delta * f32( truncf( f32( f32(min-v) / delta ) ) + ONE ) ) ); } return f32( min + f32( f32( v-min ) % delta ) ); }