diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md b/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md new file mode 100644 index 000000000000..5929b3574dd6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md @@ -0,0 +1,232 @@ + + +# bernoullif + +> Compute the nth [Bernoulli number][bernoulli-number] as a single-precision floating-point number. + +
+ + + +
+ +## Usage + +```javascript +var bernoullif = require( '@stdlib/math/base/special/bernoullif' ); +``` + +#### bernoullif( n ) + +Compute the nth [Bernoulli number][bernoulli-number] as a single-precision floating-point number. + +```javascript +var v = bernoullif( 0 ); +// returns 1.0 + +v = bernoullif( 1 ); +// returns 0.5 + +v = bernoullif( 2 ); +// returns ~0.167 + +v = bernoullif( 3 ); +// returns 0.0 + +v = bernoullif( 4 ); +// returns ~-0.033 + +v = bernoullif( 5 ); +// returns 0.0 + +v = bernoullif( 20 ); +// returns ~-529.124 +``` + +For even integers `n >= 66`, the function alternates between returning positive and negative infinity, as larger [Bernoulli numbers][bernoulli-number] cannot be safely represented in [single-precision floating-point format][ieee754] + +```javascript +var v = bernoullif( 66 ); +// returns Infinity + +v = bernoullif( 68 ); +// returns -Infinity + +v = bernoullif( 70 ); +// returns Infinity +``` + +If not provided a nonnegative integer value, the function returns `NaN`. + +```javascript +var v = bernoullif( 3.14 ); +// returns NaN + +v = bernoullif( -1 ); +// returns NaN +``` + +If provided `NaN`, the function returns `NaN`. + +```javascript +var v = bernoullif( NaN ); +// returns NaN +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoullif = require( '@stdlib/math/base/special/bernoullif' ); + +var v; +var i; + +for ( i = 0; i < 70; i++ ) { + v = bernoullif( i ); + console.log( v ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/bernoullif.h" +``` + +#### stdlib_base_bernoullif( n ) + +Compute the nth [Bernoulli number][bernoulli-number] as a single-precision floating-point number. + +```c +float out = stdlib_base_bernoullif( 0 ); +// returns 1.0 + +out = stdlib_base_bernoullif( 1 ); +// returns 0.5 +``` + +The function accepts the following arguments: + +- **n**: `[in] int32_t` input value. + +```c +float stdlib_base_bernoullif( const int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/bernoullif.h" +#include +#include + +int main( void ) { + int32_t i; + float v; + + for ( i = 0; i < 130; i++ ) { + v = stdlib_base_bernoullif( i ); + printf( "bernoullif(%d) = %f\n", i, v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/benchmark.js new file mode 100644 index 000000000000..fa239e813f0b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/benchmark.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var bernoullif = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = randu( 100, 0, 500 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = bernoullif( x[ i % x.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/benchmark.native.js new file mode 100644 index 000000000000..cd7d80415bb8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/benchmark.native.js @@ -0,0 +1,61 @@ +/** +* @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/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var bernoullif = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( bernoullif instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + x = randu( 100, 0, 500 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = bernoullif( x[ i % x.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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/bernoullif/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..8ce74387edff --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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. +*/ + +#include "stdlib/math/base/special/bernoullif.h" +#include +#include +#include +#include +#include + +#define NAME "bernoullif" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + float x[ 100 ]; + double t; + float y; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 500.0 * rand_float() ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_bernoullif( (int)( x[ i % 100 ] ) ); + 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/bernoullif/binding.gyp b/lib/node_modules/@stdlib/math/base/special/bernoullif/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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/bernoullif/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/repl.txt new file mode 100644 index 000000000000..7d48fe08ddc6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/repl.txt @@ -0,0 +1,45 @@ + +{{alias}}( n ) + Computes the nth Bernoulli number as a single-precision floating-point + number. + + If not provided a nonnegative integer value, the function returns `NaN`. + + If provided `NaN`, the function returns `NaN`. + + Parameters + ---------- + n: integer + Input value. + + Returns + ------- + y: number + Bernoulli number. + + Examples + -------- + > var y = {{alias}}( 0 ) + 1.0 + > y = {{alias}}( 1 ) + 0.5 + > y = {{alias}}( 2 ) + ~0.167 + > y = {{alias}}( 3 ) + 0.0 + > y = {{alias}}( 4 ) + ~-0.033 + > y = {{alias}}( 5 ) + 0.0 + > y = {{alias}}( 20 ) + ~-529.124 + > y = {{alias}}( 66 ) + Infinity + > y = {{alias}}( 68 ) + -Infinity + > y = {{alias}}( NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/index.d.ts new file mode 100644 index 000000000000..06fee1a8b605 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/index.d.ts @@ -0,0 +1,72 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Computes the nth Bernoulli number as a single-precision floating-point number. +* +* @param n - the Bernoulli number to compute +* @returns Bernoulli number +* +* @example +* var y = bernoullif( 0 ); +* // returns 1.0 +* +* @example +* var y = bernoullif( 1 ); +* // returns 0.5 +* +* @example +* var y = bernoullif( 2 ); +* // returns ~0.167 +* +* @example +* var y = bernoullif( 3 ); +* // returns 0.0 +* +* @example +* var y = bernoullif( 4 ); +* // returns ~-0.033 +* +* @example +* var y = bernoullif( 5 ); +* // returns 0.0 +* +* @example +* var y = bernoullif( 20 ); +* // returns ~-529.124 +* +* @example +* var y = bernoullif( 66 ); +* // returns Infinity +* +* @example +* var y = bernoullif( 68 ); +* // returns -Infinity +* +* @example +* var y = bernoullif( NaN ); +* // returns NaN +*/ +declare function bernoullif( n: number ): number; + + +// EXPORTS // + +export = bernoullif; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/test.ts new file mode 100644 index 000000000000..f72864ff4aa4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import bernoullif = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + bernoullif( 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + bernoullif( true ); // $ExpectError + bernoullif( false ); // $ExpectError + bernoullif( null ); // $ExpectError + bernoullif( undefined ); // $ExpectError + bernoullif( '5' ); // $ExpectError + bernoullif( [] ); // $ExpectError + bernoullif( {} ); // $ExpectError + bernoullif( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + bernoullif(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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/bernoullif/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/example.c new file mode 100644 index 000000000000..cb63122c4ed2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @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/bernoullif.h" +#include +#include + +int main( void ) { + int32_t i; + float v; + + for ( i = 0; i < 70; i++ ) { + v = stdlib_base_bernoullif( i ); + printf( "bernoulli(%d) = %f\n", i, v ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/index.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/index.js new file mode 100644 index 000000000000..7547fd476748 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/index.js @@ -0,0 +1,29 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var bernoullif = require( './../lib' ); + +var v; +var i; + +for ( i = 0; i < 70; i++ ) { + v = bernoullif( i ); + console.log( v ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/include.gypi b/lib/node_modules/@stdlib/math/base/special/bernoullif/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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': [ + ' + +/* +* 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 + +/** +* Computes the nth Bernoulli number as a single-precision floating-point number. +*/ +float stdlib_base_bernoullif( const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_BERNOULLIF_H diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/bernoullif.json b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/bernoullif.json new file mode 100644 index 000000000000..619bfaebd415 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/bernoullif.json @@ -0,0 +1,35 @@ +[ + 1.00000000000000000000000000000000000000000, + 0.166666666666666666666666666666666666666667, + -0.0333333333333333333333333333333333333333333, + 0.0238095238095238095238095238095238095238095, + -0.0333333333333333333333333333333333333333333, + 0.0757575757575757575757575757575757575757576, + -0.253113553113553113553113553113553113553114, + 1.16666666666666666666666666666666666666667, + -7.09215686274509803921568627450980392156863, + 54.9711779448621553884711779448621553884712, + -529.124242424242424242424242424242424242424, + 6192.12318840579710144927536231884057971014, + -86580.2531135531135531135531135531135531136, + 1.42551716666666666666666666666666666666667e6, + -2.72982310678160919540229885057471264367816e7, + 6.01580873900642368384303868174835916771401e8, + -1.51163157670921568627450980392156862745098e10, + 4.29614643061166666666666666666666666666667e11, + -1.37116552050883327721590879485616327721591e13, + 4.88332318973593166666666666666666666666667e14, + -1.92965793419400681486326681448632668144863e16, + 8.41693047573682615000553709856035437430786e17, + -4.03380718540594554130768115942028985507246e19, + 2.11507486380819916056014539007092198581560e21, + -1.20866265222965259346027311937082525317819e23, + 7.50086674607696436685572007575757575757576e24, + -5.03877810148106891413789303052201257861635e26, + 3.65287764848181233351104308429711779448622e28, + -2.84987693024508822262691464329106781609195e30, + 2.38654274996836276446459819192192149717514e32, + -2.13999492572253336658107447651910973926742e34, + 2.05009757234780975699217330956723102516667e36, + -2.09380059113463784090951852900279701847092e38 +] diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/index.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/index.js new file mode 100644 index 000000000000..ae50a89599ad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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'; + +/** +* Compute the nth Bernoulli number as a single-precision floating-point number. +* +* @module @stdlib/math/base/special/bernoullif +* +* @example +* var bernoullif = require( '@stdlib/math/base/special/bernoullif' ); +* +* var y = bernoullif( 0 ); +* // returns 1.0 +* +* y = bernoullif( 1 ); +* // returns 0.5 +* +* y = bernoullif( 2 ); +* // returns ~0.166 +* +* y = bernoullif( 3 ); +* // returns 0.0 +* +* y = bernoullif( 4 ); +* // returns ~-0.033 +* +* y = bernoullif( 5 ); +* // returns 0.0 +* +* y = bernoullif( 20 ); +* // returns ~-529.124 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js new file mode 100644 index 000000000000..64ec0fddcc1d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js @@ -0,0 +1,104 @@ +/** +* @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 isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isOdd = require( '@stdlib/math/base/assert/is-odd' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var BERNOULLIF = require( './bernoullif.json' ); + + +// VARIABLES // + +var MAX_BERNOULLI = 64|0; // asm type annotation + + +// MAIN // + +/** +* Computes the nth Bernoulli number as a single-precision floating-point number. +* +* @param {NonNegativeInteger} n - the Bernoulli number to compute +* @returns {number} Bernoulli number +* +* @example +* var y = bernoullif( 0 ); +* // returns 1.0 +* +* @example +* var y = bernoullif( 1 ); +* // returns 0.5 +* +* @example +* var y = bernoullif( 2 ); +* // returns ~0.167 +* +* @example +* var y = bernoullif( 3 ); +* // returns 0.0 +* +* @example +* var y = bernoullif( 4 ); +* // returns ~-0.033 +* +* @example +* var y = bernoullif( 5 ); +* // returns 0.0 +* +* @example +* var y = bernoullif( 20 ); +* // returns ~-529.124 +* +* @example +* var y = bernoullif( 66 ); +* // returns Infinity +* +* @example +* var y = bernoullif( 68 ); +* // returns -Infinity +* +* @example +* var y = bernoullif( NaN ); +* // returns NaN +*/ +function bernoullif( n ) { + if ( isnanf( n ) || !isNonNegativeInteger( n ) ) { + return NaN; + } + if ( n === 1 ) { + return 0.5; + } + if ( isOdd( n ) ) { + return 0.0; + } + if ( n > MAX_BERNOULLI ) { + return ( ( n / 2 ) & 1 ) ? PINF : NINF; + } + return float64ToFloat32( BERNOULLIF[ n / 2 ] ); +} + + +// EXPORTS // + +module.exports = bernoullif; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/native.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/native.js new file mode 100644 index 000000000000..b1d9bcd99cea --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/native.js @@ -0,0 +1,77 @@ +/** +* @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 // + +/** +* Computes the nth Bernoulli number as a single-precision floating-point number. +* +* @param {NonNegativeInteger} n - the Bernoulli number to compute +* @returns {number} Bernoulli number +* +* @example +* var y = bernoullif( 0 ); +* // returns 1.0 +* +* @example +* var y = bernoullif( 1 ); +* // returns 0.5 +* +* @example +* var y = bernoullif( 2 ); +* // returns ~0.167 +* +* @example +* var y = bernoullif( 3 ); +* // returns 0.0 +* +* @example +* var y = bernoullif( 4 ); +* // returns ~-0.033 +* +* @example +* var y = bernoullif( 5 ); +* // returns 0.0 +* +* @example +* var y = bernoullif( 20 ); +* // returns ~-529.124 +* +* @example +* var y = bernoullif( 66 ); +* // returns Infinity +* +* @example +* var y = bernoullif( 68 ); +* // returns -Infinity +*/ +function bernoullif( n ) { + return addon( n ); +} + + +// EXPORTS // + +module.exports = bernoullif; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json b/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json new file mode 100644 index 000000000000..15de4a2cf1ad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json @@ -0,0 +1,78 @@ +{ + "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/unary", + "@stdlib/math/base/assert/is-odd", + "@stdlib/constants/float32/ninf", + "@stdlib/constants/float32/pinf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-odd", + "@stdlib/constants/float32/ninf", + "@stdlib/constants/float32/pinf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-odd", + "@stdlib/constants/float32/ninf", + "@stdlib/constants/float32/pinf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/package.json b/lib/node_modules/@stdlib/math/base/special/bernoullif/package.json new file mode 100644 index 000000000000..57a8d2c44357 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/math/base/special/bernoullif", + "version": "0.0.0", + "description": "Compute the nth Bernoulli number as a single-precision floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "special functions", + "special", + "function", + "bernoulli", + "bernoullif", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/Makefile b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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/bernoullif/src/addon.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/addon.c new file mode 100644 index 000000000000..ce7d2000b694 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/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/bernoullif.h" +#include "stdlib/math/base/napi/unary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_bernoullif ) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c new file mode 100644 index 000000000000..eee13a8b97b8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c @@ -0,0 +1,87 @@ +/** +* @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/bernoullif.h" +#include "stdlib/math/base/assert/is_odd.h" +#include "stdlib/constants/float32/ninf.h" +#include "stdlib/constants/float32/pinf.h" + +static const float bernoulli_value[ 33 ] = { + 1.0000000000000000f, + 0.1666666666666666f, + -0.0333333333333333f, + 0.0238095238095238f, + -0.0333333333333333f, + 0.0757575757575757f, + -0.2531135531135531f, + 1.1666666666666666f, + -7.0921568627450980f, + 54.9711779448621553f, + -529.1242424242424242f, + 6192.1231884057971014f, + -86580.2531135531135531f, + 1.4255171666666666e+6f, + -2.7298231067816091e+7f, + 6.0158087390064236e+8f, + -1.5116315767092156e+10f, + 4.2961464306116666e+11f, + -1.3711655205088332e+13f, + 4.8833231897359316e+14f, + -1.9296579341940068e+16f, + 8.4169304757368261e+17f, + -4.0338071854059455e+19f, + 2.1150748638081991e+21f, + -1.2086626522296525e+23f, + 7.5008667460769643e+24f, + -5.0387781014810689e+26f, + 3.6528776484818123e+28f, + -2.8498769302450882e+30f, + 2.3865427499683627e+32f, + -2.1399949257225333e+34f, + 2.0500975723478097e+36f, + -2.0938006042234345e+38f +}; + + +static const int32_t MAX_BERNOULLI = 64; + +/** +* Computes the nth Bernoulli number as a single-precision floating-point number. +* +* @param n input value +* @return output value +* +* @example +* float out = stdlib_base_bernoullif( 0 ); +* // returns 1 +*/ +float stdlib_base_bernoullif( const int32_t n ) { + if ( n < 0 ) { + return 0.0 / 0.0; // NaN + } + if ( n == 1 ) { + return 0.5; + } + if ( stdlib_base_is_odd( n ) ) { + return 0.0; + } + if ( n > MAX_BERNOULLI ) { + return ( ( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; + } + return bernoulli_value[ n / 2 ]; +} diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.js new file mode 100644 index 000000000000..869571b0ca7e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.js @@ -0,0 +1,109 @@ +/** +* @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 float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var bernoullif = require( './../lib' ); + + +// FIXTURES // + +var BERNOULLIF = require( './../lib/bernoullif.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof bernoullif, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a negative number, the function returns `NaN`', function test( t ) { + var v; + var i; + + t.strictEqual( isnanf( bernoullif( -3.14 ) ), true, 'returns expected value' ); + + for ( i = -1; i > -50; i-- ) { + v = bernoullif( i ); + t.strictEqual( isnanf( v ), true, 'returns expected value when provided ' + i ); + } + t.end(); +}); + +tape( 'if provided `1`, the function returns `0.5`', function test( t ) { + var v = bernoullif( 1 ); + t.strictEqual( v, 0.5, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { + var v = bernoullif( NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) { + var v = bernoullif( 3.14 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the nth Bernoulli number for odd numbers', function test( t ) { + var v; + var i; + for ( i = 3; i < 500; i += 2 ) { + v = bernoullif( i ); + + // Odd Bernoulli numbers are equal to zero: + t.strictEqual( v, 0.0, 'returns the '+i+'th Bernoulli number' ); + } + t.end(); +}); + +tape( 'the function returns the nth Bernoulli number for even numbers', function test( t ) { + var v; + var i; + for ( i = 0; i < 66; i += 2 ) { + v = bernoullif( i ); + t.strictEqual( v, float64ToFloat32( BERNOULLIF[ i / 2 ] ), 'returns the '+i+'th Bernoulli number' ); + } + t.end(); +}); + +tape( 'the function returns +/- infinity for large integers', function test( t ) { + var v; + var i; + for ( i = 66; i < 500; i += 2 ) { + v = bernoullif( i ); + if ( i % 4 === 0 ) { + t.strictEqual( v, NINF, 'returns expected value' ); + } else { + t.strictEqual( v, PINF, 'returns expected value' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.native.js new file mode 100644 index 000000000000..9bc726bb5f74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.native.js @@ -0,0 +1,106 @@ +/** +* @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 float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var bernoullif = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( bernoullif instanceof Error ) +}; + + +// FIXTURES // + +var BERNOULLIF = require( './../lib/bernoullif.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof bernoullif, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a negative number, the function returns `NaN`', opts, function test( t ) { + var v; + var i; + + t.strictEqual( isnanf( bernoullif( -3.14 ) ), true, 'returns expected value' ); + + for ( i = -1; i > -50; i-- ) { + v = bernoullif( i ); + t.strictEqual( isnanf( v ), true, 'returns expected value when provided ' + i ); + } + t.end(); +}); + +tape( 'if provided `1`, the function returns `0.5`', opts, function test( t ) { + var v = bernoullif( 1 ); + t.strictEqual( v, 0.5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the nth Bernoulli number for odd numbers', opts, function test( t ) { + var v; + var i; + for ( i = 3; i < 500; i += 2 ) { + v = bernoullif( i ); + + // Odd Bernoulli numbers are equal to zero: + t.strictEqual( v, 0.0, 'returns the '+i+'th Bernoulli number' ); + } + t.end(); +}); + +tape( 'the function returns the nth Bernoulli number for even numbers', opts, function test( t ) { + var v; + var i; + for ( i = 0; i < 66; i += 2 ) { + v = bernoullif( i ); + t.strictEqual( v, float64ToFloat32( BERNOULLIF[ i / 2 ] ), 'returns the '+i+'th Bernoulli number' ); + } + t.end(); +}); + +tape( 'the function returns +/- infinity for large integers', opts, function test( t ) { + var v; + var i; + for ( i = 66; i < 500; i += 2 ) { + v = bernoullif( i ); + if ( i % 4 === 0 ) { + t.strictEqual( v, NINF, 'returns expected value' ); + } else { + t.strictEqual( v, PINF, 'returns expected value' ); + } + } + t.end(); +});