diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/README.md b/lib/node_modules/@stdlib/math/base/special/ceilb/README.md index 19ca631bf71d..164983ab8eb4 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilb/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/README.md @@ -102,6 +102,96 @@ for ( i = 0; i < 100; i++ ) { <!-- /.examples --> +<!-- C interface documentation. --> + +* * * + +<section class="c"> + +## C APIs + +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> + +<section class="intro"> + +</section> + +<!-- /.intro --> + +<!-- C usage documentation. --> + +<section class="usage"> + +### Usage + +```c +#include "stdlib/math/base/special/ceilb.h" +``` + +#### stdlib_base_ceilb( x, n, b ) + +Rounds a `numeric` value to the nearest multiple of `b^n` toward positive infinity. + +```c +double out = stdlib_base_ceilb( 3.141592653589793, -4, 10 ); +// returns 3.1416 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **n**: `[in] int32_t` power. +- **b**: `[in] int32_t` base. + +```c +double stdlib_base_ceilb( const double x, const int32_t n, const int32_t b ); +``` + +</section> + +<!-- /.usage --> + +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> + +<section class="notes"> + +</section> + +<!-- /.notes --> + +<!-- C API usage examples. --> + +<section class="examples"> + +### Examples + +```c +#include "stdlib/math/base/special/ceilb.h" +#include <stdio.h> +#include <stdint.h> + +int main( void ) { + const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 }; + const int32_t n[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 }; + const int32_t b[] = { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 }; + + double v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_ceilb( x[ i ], n[ i ], b[ i ] ); + printf( "ceilb(%lf, %d, %d) = %lf\n", x[ i ], n[ i ], b[ i ], v ); + } +} +``` + +</section> + +<!-- /.examples --> + +</section> + +<!-- /.c --> + <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> <section class="related"> diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/ceilb/benchmark/benchmark.native.js new file mode 100644 index 000000000000..e16a591db04c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var ceilb = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( ceilb 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() * 1.0e7 ) - 5.0e6; + y = ceilb( x, 2, 20 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/ceilb/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/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/ceilb/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ceilb/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..1819b5f57ef8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/benchmark/c/native/benchmark.c @@ -0,0 +1,136 @@ +/** +* @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. +*/ + +/** +* Benchmark `ceilb`. +*/ +#include "stdlib/math/base/special/ceilb.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <time.h> +#include <sys/time.h> + +#define NAME "ceilb" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +void print_version() { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +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 +*/ +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 +*/ +double tic() { + 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 +*/ +double rand_double() { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double x; + double y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 1.0e7 * rand_double() ) - 5.0e6; + y = stdlib_base_ceilb( x, 2, 20 ); + 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::native::%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/ceilb/binding.gyp b/lib/node_modules/@stdlib/math/base/special/ceilb/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/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/ceilb/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/ceilb/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/ceilb/examples/c/example.c new file mode 100644 index 000000000000..86a3be3be3ff --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/examples/c/example.c @@ -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. +*/ + +#include "stdlib/math/base/special/ceilb.h" +#include <stdio.h> +#include <stdint.h> + +int main( void ) { + const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 }; + const int32_t n[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 }; + const int32_t b[] = { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 }; + + double v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_ceilb( x[ i ], n[ i ], b[ i ] ); + printf( "ceilb(%lf, %d, %d) = %lf\n", x[ i ], n[ i ], b[ i ], v ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/include.gypi b/lib/node_modules/@stdlib/math/base/special/ceilb/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/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': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Add-on destination directory: + 'addon_output_dir': './src', + + # Source files: + 'src_files': [ + '<(src_dir)/addon.c', + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Library dependencies: + 'libraries': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Library directories: + 'library_dirs': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + }, # end variables +} diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/include/stdlib/math/base/special/ceilb.h b/lib/node_modules/@stdlib/math/base/special/ceilb/include/stdlib/math/base/special/ceilb.h new file mode 100644 index 000000000000..91673337b056 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/include/stdlib/math/base/special/ceilb.h @@ -0,0 +1,40 @@ +/** +* @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. +*/ + +#ifndef STDLIB_MATH_BASE_SPECIAL_CEILB_H +#define STDLIB_MATH_BASE_SPECIAL_CEILB_H + +#include <stdint.h> + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Rounds a numeric value to the nearest multiple of \\(b^n\\) toward positive infinity. +*/ +double stdlib_base_ceilb( const double x, const int32_t n, const int32_t b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_CEILB_H diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/lib/native.js b/lib/node_modules/@stdlib/math/base/special/ceilb/lib/native.js new file mode 100644 index 000000000000..c12b36893e5f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/lib/native.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds a numeric value to the nearest multiple of \\(b^n\\) toward positive infinity. +* +* @private +* @param {number} x - input value +* @param {integer} n - integer power +* @param {PositiveInteger} b - base +* @returns {number} rounded value +* +* @example +* // Round a value to 4 decimal places: +* var v = ceilb( 3.141592653589793, -4, 10 ); +* // returns 3.1416 +* +* @example +* // If n = 0 or b = 1, `ceilb` behaves like `ceil`: +* var v = ceilb( 3.141592653589793, 0, 2 ); +* // returns 4.0 +* +* @example +* // Round a value to the nearest multiple of two toward positive infinity: +* var v = ceilb( 5.0, 1, 2 ); +* // returns 6.0 +*/ +function ceilb( x, n, b ) { + return addon( x, n, b ); +} + + +// EXPORTS // + +module.exports = ceilb; diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/manifest.json b/lib/node_modules/@stdlib/math/base/special/ceilb/manifest.json new file mode 100644 index 000000000000..0ecff79da0d4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/manifest.json @@ -0,0 +1,84 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/ternary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/special/ceil", + "@stdlib/math/base/special/ceiln", + "@stdlib/math/base/special/pow" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/special/ceil", + "@stdlib/math/base/special/ceiln", + "@stdlib/math/base/special/pow" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-infinite", + "@stdlib/math/base/special/ceil", + "@stdlib/math/base/special/ceiln", + "@stdlib/math/base/special/pow" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/src/Makefile b/lib/node_modules/@stdlib/math/base/special/ceilb/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/src/addon.c b/lib/node_modules/@stdlib/math/base/special/ceilb/src/addon.c new file mode 100644 index 000000000000..c378a25c5faa --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/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/ceilb.h" +#include "stdlib/math/base/napi/ternary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DII_D( stdlib_base_ceilb ) diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/src/main.c b/lib/node_modules/@stdlib/math/base/special/ceilb/src/main.c new file mode 100644 index 000000000000..fd3bb060f180 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/src/main.c @@ -0,0 +1,68 @@ +/** +* @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/ceilb.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/assert/is_infinite.h" +#include "stdlib/math/base/special/ceil.h" +#include "stdlib/math/base/special/ceiln.h" +#include "stdlib/math/base/special/pow.h" +#include <stdint.h> + +/** +* Rounds a numeric value to the nearest multiple of \\(b^n\\) toward positive infinity. +* +* @param x input value +* @param n integer power +* @param b base +* @return rounded value +* +* @example +* double out = stdlib_base_ceilb( 3.141592653589793, -4, 10 ); +* // returns 3.1416 +*/ +double stdlib_base_ceilb( const double x, const int32_t n, const int32_t b ) { + double y; + double s; + + if ( stdlib_base_is_nan( x ) || b <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( stdlib_base_is_infinite( x ) || x == 0.0 ) { + return x; + } + if ( b == 10 ) { + return stdlib_base_ceiln( x, n ); + } + if ( n == 0 || b == 1 ) { + return stdlib_base_ceil( x ); + } + s = stdlib_base_pow( b, -n ); + + // Check for overflow: + if ( stdlib_base_is_infinite( s ) ) { + return x; + } + y = stdlib_base_ceil( x * s ) / s; + + // Check for overflow: + if ( stdlib_base_is_infinite( y ) ) { + return x; + } + return y; +} diff --git a/lib/node_modules/@stdlib/math/base/special/ceilb/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/ceilb/test/test.native.js new file mode 100644 index 000000000000..00e1fa544d11 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilb/test/test.native.js @@ -0,0 +1,326 @@ +/** +* @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 PI = require( '@stdlib/constants/float64/pi' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var ceil = require( '@stdlib/math/base/special/ceil' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var ceilb = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( ceilb instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ceilb, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var v; + + v = ceilb( NaN, -2, 1 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `b <= 0`', opts, function test( t ) { + var v; + + v = ceilb( PI, 5, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = ceilb( PI, 5, -1 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { + var v = ceilb( PINF, 5, 10 ); + t.strictEqual( v, PINF, 'returns +infinity' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { + var v = ceilb( NINF, -3, 10 ); + t.strictEqual( v, NINF, 'returns -infinity' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { + var v; + + v = ceilb( -0.0, 0, 10 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + + v = ceilb( -0.0, -2, 10 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + + v = ceilb( -0.0, 2, 10 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { + var v; + + v = ceilb( 0.0, 0, 10 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + v = ceilb( +0.0, -2, 10 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + v = ceilb( +0.0, 2, 10 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + t.end(); +}); + +tape( 'the function supports rounding a numeric value to a desired number of decimals', opts, function test( t ) { + t.strictEqual( ceilb( PI, -2, 10 ), 3.15, 'returns expected value' ); + t.strictEqual( ceilb( -PI, -2, 10 ), -3.14, 'returns expected value' ); + t.strictEqual( ceilb( 9.99999, -2, 10 ), 10.0, 'returns expected value' ); + t.strictEqual( ceilb( -9.99999, -2, 10 ), -9.99, 'returns expected value' ); + t.strictEqual( ceilb( 0.0, 2, 10 ), 0.0, 'returns expected value' ); + t.strictEqual( ceilb( 12368.0, -3, 10 ), 12368.0, 'returns expected value' ); + t.strictEqual( ceilb( -12368.0, -3, 10 ), -12368.0, 'returns expected value' ); + t.end(); +}); + +tape( 'due to floating-point rounding error, rounding a numeric value can result in unexpected behavior', opts, function test( t ) { + var x; + + x = 0.2 + 0.1; // => 0.30000000000000004 + t.strictEqual( ceilb( x, -16, 10 ), 0.3000000000000001, 'equals 0.3000000000000001 and not 0.3' ); + + x = 24.616838129811768; + t.strictEqual( ceilb( x, 2, 7 ), 48.99999999999999, 'equals 48.99999999999999 and not 49' ); + + t.end(); +}); + +tape( 'the function supports rounding a numeric value to a desired number of digits', opts, function test( t ) { + t.strictEqual( ceilb( PI, 4, 10 ), 10000.0, 'returns expected value' ); + t.strictEqual( ceilb( 12368.0, 3, 10 ), 13000.0, 'returns expected value' ); + t.strictEqual( ceilb( 12368.0, 1, 10 ), 12370.0, 'returns expected value' ); + t.strictEqual( ceilb( PI, 3, 10 ), 1000, 'returns expected value' ); + t.strictEqual( isNegativeZero( ceilb( -PI, 3, 10 ) ), true, 'returns expected value' ); + t.strictEqual( ceilb( -12368.0, 3, 10 ), -12000.0, 'returns expected value' ); + t.strictEqual( ceilb( -12368.0, 1, 10 ), -12360.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if `x` is too large a double to have decimals and `n < 0`, the input value is returned', opts, function test( t ) { + var sign; + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + sign = ( randu()<0.5 ) ? -1.0 : 1.0; + exp = 54 + round( randu()*254.0 ); + x = sign * (1.0+randu()) * pow( 10.0, exp ); + n = -( round( randu()*324.0) ); + v = ceilb( x, n, 10 ); + t.strictEqual( x, v, ' returns input value when provided x='+x+', n='+n+'.' ); + } + t.end(); +}); + +tape( 'if `b^n` is too large and `x > 0`, the function returns `+infinity`', opts, function test( t ) { + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*307.0 ); + x = (1.0+randu()) * pow( 10.0, exp ); + n = round( randu()*100.0 ) + 309; + v = ceilb( x, n, 10 ); + t.strictEqual( v, PINF, ' returns +infinity when provided x='+x+', n='+n+'.' ); + } + t.end(); +}); + +tape( 'if `b^n` is too large and `x < 0`, the function returns `-0` (sign preserving)', opts, function test( t ) { + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*307.0 ); + x = -(1.0+randu()) * pow( 10.0, exp ); + n = round( randu()*100.0 ) + 309; + v = ceilb( x, n, 10 ); + t.strictEqual( isNegativeZero( v ), true, ' returns +0 when provided x='+x+', n='+n+'.' ); + } + t.end(); +}); + +tape( 'the function supports rounding very small numbers (including subnormals)', opts, function test( t ) { + var expected; + var delta; + var tol; + var x; + var n; + var v; + var i; + + x = 3.1468234343023397 * pow( 10.0, -308 ); + + n = []; + for ( i = -308; i > -325; i-- ) { + n.push( i ); + } + expected = [ + 4e-308, + 3.2e-308, + 3.15e-308, + 3.147e-308, + 3.1469e-308, + 3.14683e-308, + 3.146824e-308, + 3.1468235e-308, + 3.14682344e-308, + 3.146823435e-308, + 3.1468234344e-308, + 3.14682343431e-308, + 3.146823434303e-308, + 3.1468234343024e-308, + 3.14682343430234e-308, + 3.146823434302340e-308, + 3.1468234343023397e-308 + ]; + + for ( i = 0; i < n.length; i++ ) { + v = ceilb( x, n[i], 10 ); + if ( v === expected[i] ) { + t.strictEqual( v, expected[ i ], 'returns '+expected[i]+' when provided x='+x+' and n='+n[i]+'.' ); + } else { + delta = abs( v - expected[i] ); + tol = EPS * abs( expected[i] ); + t.strictEqual( delta <= tol, true, 'x: '+x+'. n: '+n[i]+'. v: '+v+'. expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol ); + } + } + t.end(); +}); + +tape( 'if the function encounters overflow, the function returns the input value', opts, function test( t ) { + var x; + var v; + + x = 3.1468234343023397; + v = ceilb( x, -314, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = -3.1468234343023397; + v = ceilb( x, -314, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = 9007199254740000; + v = ceilb( x, -300, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = -9007199254740000; + v = ceilb( x, -300, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + t.end(); +}); + +tape( 'if `n = 0`, the function exhibits standard ceil behavior', opts, function test( t ) { + var x; + var v; + var i; + + for ( i = 0; i < 200; i++ ) { + x = (randu()*1000.0) - 500.0; + v = ceilb( x, 0, 2 ); + t.strictEqual( v, ceil( x ), 'returns expected value' ); + } + t.end(); +}); + +tape( 'if `b = 1`, the function exhibits standard ceil behavior', opts, function test( t ) { + var x; + var v; + var i; + + for ( i = 0; i < 200; i++ ) { + x = (randu()*1000.0) - 500.0; + v = ceilb( x, 100, 1 ); + t.strictEqual( v, ceil( x ), 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function supports arbitrary rounding', opts, function test( t ) { + t.strictEqual( ceilb( 5.0, 1, 2 ), 6.0, 'returns expected value' ); + t.strictEqual( ceilb( 38.5, 1, 6 ), 42.0, 'returns expected value' ); + t.strictEqual( ceilb( 0.425, -2, 2 ), 0.50, 'returns expected value' ); + t.strictEqual( ceilb( 60.0, 1, 40.0 ), 80.0, 'returns expected value' ); + t.strictEqual( ceilb( -21.54, -1, 5 ), -21.4, 'returns expected value' ); + t.strictEqual( ceilb( 35.037, -4, 2 ), 35.0625, 'returns expected value' ); + t.end(); +}); + +tape( 'if the function overflows, the function returns the input value', opts, function test( t ) { + var x; + var v; + + x = 12.5; + v = ceilb( x, -308, 10 ); + t.strictEqual( v, x, 'returns expected value' ); + + x = 12.5; + v = ceilb( x, -1022, 2 ); + t.strictEqual( v, x, 'returns expected value' ); + + x = 12.5; + v = ceilb( x, -1074, 2 ); + t.strictEqual( v, x, 'returns expected value' ); + + t.end(); +});