diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md b/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md index 853afbdf0404..3a60c3bab29a 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md @@ -30,25 +30,21 @@ limitations under the License. var ceilsd = require( '@stdlib/math/base/special/ceilsd' ); ``` -#### ceilsd( x, n\[, b] ) +#### ceilsd( x, n, b ) Rounds a `numeric` value to the nearest `number` toward positive infinity with `n` significant figures. ```javascript -var v = ceilsd( 3.141592653589793, 5 ); +var v = ceilsd( 3.141592653589793, 5, 10 ); // returns 3.1416 -v = ceilsd( 3.141592653589793, 1 ); +v = ceilsd( 3.141592653589793, 1, 10 ); // returns 4.0 -v = ceilsd( 12368.0, 2 ); +v = ceilsd( 12368.0, 2, 10 ); // returns 13000.0 -``` - -The default base is `10` (decimal). To round using a different base, provide a third argument. -```javascript -var v = ceilsd( 0.0313, 2, 2 ); +v = ceilsd( 0.0313, 2, 2 ); // returns 0.046875 ``` @@ -78,7 +74,7 @@ var i; for ( i = 0; i < 100; i++ ) { x = (randu()*10000.0) - 5000.0; - y = ceilsd( x, 5 ); + y = ceilsd( x, 5, 10 ); console.log( 'x: %d. Rounded: %d.', x, y ); } ``` @@ -87,6 +83,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/ceilsd.h" +``` + +#### stdlib_base_ceilsd( x, n, b ) + +Rounds a `numeric` value to the nearest `number` toward negative infinity with `n` significant figures. + +```c +double out = stdlib_base_ceilsd( 0.0313, 2, 2 ); +// returns 0.046875 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **n**: `[in] int32_t` number of significant figures. +- **b**: `[in] int32_t` base. + +```c +double stdlib_base_ceilsd( 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/ceilsd.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[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + 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_ceilsd( x[ i ], n[ i ], b[ i ] ); + printf( "ceilsd(%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/ceilsd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/benchmark/benchmark.native.js new file mode 100644 index 000000000000..128dca308fb0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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 ceilsd = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( ceilsd 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 = ceilsd( x, 2, 2 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/ceilsd/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ceilsd/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..e72a84aae826 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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 `ceilsd`. +*/ +#include "stdlib/math/base/special/ceilsd.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <time.h> +#include <sys/time.h> + +#define NAME "ceilsd" +#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_ceilsd( x, 2, 2 ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // 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/ceilsd/binding.gyp b/lib/node_modules/@stdlib/math/base/special/ceilsd/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/repl.txt index 0c7af106b7bd..04e983e112f2 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( x, n[, b] ) +{{alias}}( x, n, b ) Rounds a numeric value to the nearest number toward positive infinity with `n` significant figures. @@ -11,7 +11,7 @@ n: integer Number of significant figures. Must be greater than 0. - b: integer (optional) + b: integer Base. Must be greater than 0. Default: 10. Returns @@ -21,11 +21,11 @@ Examples -------- - > var y = {{alias}}( 3.14159, 5 ) + > var y = {{alias}}( 3.14159, 5, 10 ) 3.1416 - > y = {{alias}}( 3.14159, 1 ) + > y = {{alias}}( 3.14159, 1, 10 ) 4.0 - > y = {{alias}}( 12368.0, 2 ) + > y = {{alias}}( 12368.0, 2, 10 ) 13000.0 > y = {{alias}}( 0.0313, 2, 2 ) 0.046875 diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/index.d.ts index 4c49694e6415..2bcf166b3595 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/index.d.ts @@ -23,26 +23,26 @@ * * @param x - input value * @param n - number of significant figures -* @param b - base (default: 10) +* @param b - base * @returns rounded value * * @example -* var v = ceilsd( 3.141592653589793, 5 ); +* var v = ceilsd( 3.141592653589793, 5, 10 ); * // returns 3.1416 * * @example -* var v = ceilsd( 3.141592653589793, 1 ); +* var v = ceilsd( 3.141592653589793, 1, 10 ); * // returns 4.0 * * @example -* var v = ceilsd( 12368.0, 2 ); +* var v = ceilsd( 12368.0, 2, 10 ); * // returns 13000.0 * * @example * var v = ceilsd( 0.0313, 2, 2 ); * // returns 0.046875 */ -declare function ceilsd( x: number, n: number, b?: number ): number; +declare function ceilsd( x: number, n: number, b: number ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts index 74532ebe244e..7988ebb5cc3c 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts @@ -24,7 +24,6 @@ import ceilsd = require( './index' ); // The function returns a number... { ceilsd( 3.141592653589793, -4, 10 ); // $ExpectType number - ceilsd( 3.141592653589793, -4 ); // $ExpectType number } // The compiler throws an error if the function is provided values other than numbers... diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/c/example.c new file mode 100644 index 000000000000..414566c65edd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd.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[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + 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_ceilsd( x[ i ], n[ i ], b[ i ] ); + printf( "ceilsd(%lf, %d, %d) = %lf\n", x[ i ], n[ i ], b[ i ], v ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js index 6e2e8c7230ea..c963430fa476 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js @@ -27,6 +27,6 @@ var i; for ( i = 0; i < 100; i++ ) { x = (randu()*10000.0) - 5000.0; - y = ceilsd( x, 5 ); + y = ceilsd( x, 5, 10 ); console.log( 'x: %d. Rounded: %d.', x, y ); } diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/include.gypi b/lib/node_modules/@stdlib/math/base/special/ceilsd/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd/include/stdlib/math/base/special/ceilsd.h b/lib/node_modules/@stdlib/math/base/special/ceilsd/include/stdlib/math/base/special/ceilsd.h new file mode 100644 index 000000000000..a02de2189e08 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/include/stdlib/math/base/special/ceilsd.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_CEILSD_H +#define STDLIB_MATH_BASE_SPECIAL_CEILSD_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 number toward positive infinity with \\(n\\) significant figures. +*/ +double stdlib_base_ceilsd( const double x, const int32_t n, const int32_t b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_CEILSD_H diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/index.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/index.js index cc115a59f767..c06dd293f6ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/index.js @@ -26,13 +26,13 @@ * @example * var ceilsd = require( '@stdlib/math/base/special/ceilsd' ); * -* var v = ceilsd( 3.141592653589793, 5 ); +* var v = ceilsd( 3.141592653589793, 5, 10 ); * // returns 3.1416 * -* v = ceilsd( 3.141592653589793, 1 ); +* v = ceilsd( 3.141592653589793, 1, 10 ); * // returns 4.0 * -* v = ceilsd( 12368.0, 2 ); +* v = ceilsd( 12368.0, 2, 10 ); * // returns 13000.0 * * v = ceilsd( 0.0313, 2, 2 ); diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/main.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/main.js index 9794f20fb4d0..03748f5ef321 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/main.js @@ -38,19 +38,19 @@ var ceil = require( '@stdlib/math/base/special/ceil' ); * * @param {number} x - input value * @param {PositiveInteger} n - number of significant figures -* @param {PositiveInteger} [b=10] - base +* @param {PositiveInteger} b - base * @returns {number} rounded value * * @example -* var v = ceilsd( 3.141592653589793, 5 ); +* var v = ceilsd( 3.141592653589793, 5, 10 ); * // returns 3.1416 * * @example -* var v = ceilsd( 3.141592653589793, 1 ); +* var v = ceilsd( 3.141592653589793, 1, 10 ); * // returns 4.0 * * @example -* var v = ceilsd( 12368.0, 2 ); +* var v = ceilsd( 12368.0, 2, 10 ); * // returns 13000.0 * * @example @@ -58,7 +58,6 @@ var ceil = require( '@stdlib/math/base/special/ceil' ); * // returns 0.046875 */ function ceilsd( x, n, b ) { - var base; var exp; var s; var y; @@ -66,36 +65,27 @@ function ceilsd( x, n, b ) { isnan( x ) || isnan( n ) || n < 1 || - isInfinite( n ) + isInfinite( n ) || + isnan( b ) || + b <= 0 || + isInfinite( b ) ) { return NaN; } - if ( arguments.length > 2 ) { - if ( - isnan( b ) || - b <= 0 || - isInfinite( b ) - ) { - return NaN; - } - base = b; - } else { - base = 10; - } if ( isInfinite( x ) || x === 0.0 ) { return x; } - if ( base === 10 ) { + if ( b === 10 ) { exp = log10( abs( x ) ); } - else if ( base === 2 ) { + else if ( b === 2 ) { exp = exponent( abs( x ) ); } else { - exp = ln( abs(x) ) / ln( base ); + exp = ln( abs(x) ) / ln( b ); } exp = floor( exp - n + 1.0 ); - s = pow( base, abs( exp ) ); + s = pow( b, abs( exp ) ); // Check for overflow: if ( isInfinite( s ) ) { diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/native.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/native.js new file mode 100644 index 000000000000..9b828dfa828f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/lib/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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds a numeric value to the nearest number toward positive infinity with \\(n\\) significant figures. +* +* @private +* @param {number} x - input value +* @param {PositiveInteger} n - number of significant figures +* @param {PositiveInteger} b - base +* @returns {number} rounded value +* +* @example +* var v = ceilsd( 3.141592653589793, 5, 10 ); +* // returns 3.1416 +* +* @example +* var v = ceilsd( 3.141592653589793, 1, 10 ); +* // returns 4.0 +* +* @example +* var v = ceilsd( 12368.0, 2, 10 ); +* // returns 13000.0 +* +* @example +* var v = ceilsd( 0.0313, 2, 2 ); +* // returns 0.046875 +*/ +function ceilsd( x, n, b ) { + return addon( x, n, b ); +} + + +// EXPORTS // + +module.exports = ceilsd; diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/manifest.json b/lib/node_modules/@stdlib/math/base/special/ceilsd/manifest.json new file mode 100644 index 000000000000..8cc013511057 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/manifest.json @@ -0,0 +1,96 @@ +{ + "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/pow", + "@stdlib/math/base/special/log10", + "@stdlib/math/base/special/ln", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/ceil", + "@stdlib/number/float64/base/exponent" + ] + }, + { + "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/pow", + "@stdlib/math/base/special/log10", + "@stdlib/math/base/special/ln", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/ceil", + "@stdlib/number/float64/base/exponent" + ] + }, + { + "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/pow", + "@stdlib/math/base/special/log10", + "@stdlib/math/base/special/ln", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/ceil", + "@stdlib/number/float64/base/exponent" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/src/Makefile b/lib/node_modules/@stdlib/math/base/special/ceilsd/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd/src/addon.c b/lib/node_modules/@stdlib/math/base/special/ceilsd/src/addon.c new file mode 100644 index 000000000000..58586e48a607 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/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/ceilsd.h" +#include "stdlib/math/base/napi/ternary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DII_D( stdlib_base_ceilsd ) diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c b/lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c new file mode 100644 index 000000000000..a4367b4050ab --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c @@ -0,0 +1,81 @@ +/** +* @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/ceilsd.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/assert/is_infinite.h" +#include "stdlib/math/base/special/pow.h" +#include "stdlib/math/base/special/log10.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/math/base/special/floor.h" +#include "stdlib/math/base/special/ceil.h" +#include "stdlib/number/float64/base/exponent.h" +#include <stdint.h> + +/** +* Rounds a numeric value to the nearest number toward positive infinity with \\(n\\) significant figures. +* +* @param x input value +* @param n number of significant figures +* @param b base +* @return rounded value +* +* @example +* double out = stdlib_base_ceilsd( 3.141592653589793, 5, 10 ); +* // returns 3.1416 +*/ +double stdlib_base_ceilsd( const double x, const int32_t n, const int32_t b ) { + double exp; + double s; + double y; + + if ( stdlib_base_is_nan( x ) || n < 1 || b <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( stdlib_base_is_infinite( x ) || x == 0.0 ) { + return x; + } + if ( b == 10 ) { + exp = stdlib_base_log10( stdlib_base_abs( x ) ); + } else if ( b == 2 ) { + exp = stdlib_base_float64_exponent( stdlib_base_abs( x ) ); + } else { + exp = stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( b ); + } + exp = stdlib_base_floor( exp - n + 1.0 ); + s = stdlib_base_pow( b, stdlib_base_abs( exp ) ); + + // Check for overflow: + if ( stdlib_base_is_infinite( s ) ) { + return x; + } + + // To avoid numerical stability issues due to floating-point rounding error (e.g., 3.55/0.1-35.5 = -7.105427357601e-15 and 3.55*10-35.5 = 0), we must treat positive and negative exponents separately. + if ( exp < 0 ) { + y = stdlib_base_ceil( x * s ) / s; + } else { + 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/ceilsd/test/test.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.js index 135aaba4791b..d4442b7bbc90 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.js @@ -41,13 +41,13 @@ tape( 'main export is a function', function test( t ) { tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v; - v = ceilsd( NaN, 2 ); + v = ceilsd( NaN, 2, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); - v = ceilsd( 12368.0, NaN ); + v = ceilsd( 12368.0, NaN, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); - v = ceilsd( NaN, NaN ); + v = ceilsd( NaN, NaN, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); v = ceilsd( NaN, NaN, 10 ); @@ -68,10 +68,10 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { tape( 'the function returns `NaN` if provided `n = +-infinity`', function test( t ) { var v; - v = ceilsd( PI, PINF ); + v = ceilsd( PI, PINF, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); - v = ceilsd( PI, NINF ); + v = ceilsd( PI, NINF, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); t.end(); @@ -80,10 +80,10 @@ tape( 'the function returns `NaN` if provided `n = +-infinity`', function test( tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) { var v; - v = ceilsd( PI, 0 ); + v = ceilsd( PI, 0, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); - v = ceilsd( PI, -1 ); + v = ceilsd( PI, -1, 10 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); t.end(); @@ -114,13 +114,13 @@ tape( 'the function returns `NaN` if provided `b <= 0`', function test( t ) { }); tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { - var v = ceilsd( PINF, 5 ); + var v = ceilsd( PINF, 5, 10 ); t.strictEqual( v, PINF, 'returns +infinity' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { - var v = ceilsd( NINF, 3 ); + var v = ceilsd( NINF, 3, 10 ); t.strictEqual( v, NINF, 'returns -infinity' ); t.end(); }); @@ -128,10 +128,10 @@ tape( 'the function returns `-infinity` if provided `-infinity`', function test( tape( 'the function returns `-0` if provided `-0`', function test( t ) { var v; - v = ceilsd( -0.0, 1 ); + v = ceilsd( -0.0, 1, 10 ); t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); - v = ceilsd( -0.0, 2 ); + v = ceilsd( -0.0, 2, 10 ); t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); t.end(); @@ -140,32 +140,15 @@ tape( 'the function returns `-0` if provided `-0`', function test( t ) { tape( 'the function returns `+0` if provided `+0`', function test( t ) { var v; - v = ceilsd( 0.0, 1 ); + v = ceilsd( 0.0, 1, 10 ); t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); - v = ceilsd( +0.0, 2 ); + v = ceilsd( +0.0, 2, 10 ); t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); t.end(); }); -tape( 'the function supports rounding a numeric value with a specified number of significant figures', function test( t ) { - t.strictEqual( ceilsd( PI, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( ceilsd( -PI, 1 ), -3.0, 'returns expected value' ); - t.strictEqual( ceilsd( PI, 2 ), 3.2, 'returns expected value' ); - t.strictEqual( ceilsd( -PI, 2 ), -3.1, 'returns expected value' ); - t.strictEqual( ceilsd( PI, 3 ), 3.15, 'returns expected value' ); - t.strictEqual( ceilsd( -PI, 3 ), -3.14, 'returns expected value' ); - t.strictEqual( ceilsd( PI, 5 ), 3.1416, 'returns expected value' ); - t.strictEqual( ceilsd( -PI, 5 ), -3.1415, 'returns expected value' ); - t.strictEqual( ceilsd( 0.0, 2 ), 0.0, 'returns expected value' ); - t.strictEqual( ceilsd( 12368.0, 3 ), 12400.0, 'returns expected value' ); - t.strictEqual( ceilsd( -12368.0, 3 ), -12300.0, 'returns expected value' ); - t.strictEqual( ceilsd( 12368.0, 2 ), 13000.0, 'returns expected value' ); - t.strictEqual( ceilsd( -12368.0, 2 ), -12000.0, 'returns expected value' ); - t.end(); -}); - tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 10)', function test( t ) { t.strictEqual( ceilsd( PI, 1, 10 ), 4.0, 'returns expected value' ); t.strictEqual( ceilsd( -PI, 1, 10 ), -3.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.native.js new file mode 100644 index 000000000000..61c410d0b61e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.native.js @@ -0,0 +1,171 @@ +/** +* @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 PI = require( '@stdlib/constants/float64/pi' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ceilsd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ceilsd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var v; + + v = ceilsd( NaN, 2, 10 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) { + var v; + + v = ceilsd( PI, 0, 10 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = ceilsd( PI, -1, 10 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `b <= 0`', function test( t ) { + var v; + + v = ceilsd( PI, 2, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = ceilsd( PI, 2, -1 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { + var v = ceilsd( PINF, 5, 10 ); + t.strictEqual( v, PINF, 'returns +infinity' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var v = ceilsd( NINF, 3, 10 ); + t.strictEqual( v, NINF, 'returns -infinity' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', function test( t ) { + var v; + + v = ceilsd( -0.0, 1, 10 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + + v = ceilsd( -0.0, 2, 10 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', function test( t ) { + var v; + + v = ceilsd( 0.0, 1, 10 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + v = ceilsd( +0.0, 2, 10 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + t.end(); +}); + +tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 10)', function test( t ) { + t.strictEqual( ceilsd( PI, 1, 10 ), 4.0, 'returns expected value' ); + t.strictEqual( ceilsd( -PI, 1, 10 ), -3.0, 'returns expected value' ); + t.strictEqual( ceilsd( PI, 2, 10 ), 3.2, 'returns expected value' ); + t.strictEqual( ceilsd( -PI, 2, 10 ), -3.1, 'returns expected value' ); + t.strictEqual( ceilsd( PI, 3, 10 ), 3.15, 'returns expected value' ); + t.strictEqual( ceilsd( -PI, 3, 10 ), -3.14, 'returns expected value' ); + t.strictEqual( ceilsd( PI, 5, 10 ), 3.1416, 'returns expected value' ); + t.strictEqual( ceilsd( -PI, 5, 10 ), -3.1415, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0, 2, 10 ), 0.0, 'returns expected value' ); + t.strictEqual( ceilsd( 12368.0, 3, 10 ), 12400.0, 'returns expected value' ); + t.strictEqual( ceilsd( -12368.0, 3, 10 ), -12300.0, 'returns expected value' ); + t.strictEqual( ceilsd( 12368.0, 2, 10 ), 13000.0, 'returns expected value' ); + t.strictEqual( ceilsd( -12368.0, 2, 10 ), -12000.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 2)', function test( t ) { + t.strictEqual( ceilsd( 0.0313, 1, 2 ), 0.0625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 2, 2 ), 0.046875, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 3, 2 ), 0.0390625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 4, 2 ), 0.03515625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 5, 2 ), 0.033203125, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 6, 2 ), 0.0322265625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 7, 2 ), 0.03173828125, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 8, 2 ), 0.031494140625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 9, 2 ), 0.0313720703125, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 10, 2 ), 0.03131103515625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 11, 2 ), 0.03131103515625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 12, 2 ), 0.03131103515625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 13, 2 ), 0.03130340576171875, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 14, 2 ), 0.03130340576171875, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding a numeric value with a specified number of significant figures using an arbitrary base', function test( t ) { + t.strictEqual( ceilsd( 0.0313, 1, 16 ), 0.03515625, 'returns expected value' ); + t.strictEqual( ceilsd( 0.0313, 5, 16 ), 0.03130000829696655, 'returns expected value' ); + t.end(); +}); + +tape( 'if the function encounters overflow, the function returns the input value', function test( t ) { + var x; + var v; + + x = 3.1468234343023397; + v = ceilsd( x, 1000, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = -3.1468234343023397; + v = ceilsd( x, 1000, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = 9007199254740000; + v = ceilsd( x, 320, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + x = -9007199254740000; + v = ceilsd( x, 320, 10 ); + t.strictEqual( v, x, 'returns the input value' ); + + t.end(); +});