From 9e94d1f411e22d0be612ef92a1f6a5151051df9c Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 29 Mar 2025 14:31:54 -0700 Subject: [PATCH 01/16] feat: temp commit --- .../math/base/special/factorial2f/README.md | 210 ++++++++++++++++++ .../factorial2f/benchmark/benchmark.js | 48 ++++ .../factorial2f/benchmark/benchmark.native.js | 57 +++++ .../factorial2f/benchmark/c/native/Makefile | 146 ++++++++++++ .../benchmark/c/native/benchmark.c | 134 +++++++++++ .../factorial2f/benchmark/cpp/boost/Makefile | 110 +++++++++ .../benchmark/cpp/boost/benchmark.cpp | 134 +++++++++++ .../benchmark/python/scipy/benchmark.py | 97 ++++++++ .../math/base/special/factorial2f/binding.gyp | 170 ++++++++++++++ .../base/special/factorial2f/docs/repl.txt | 32 +++ .../special/factorial2f/docs/types/index.d.ts | 53 +++++ .../special/factorial2f/docs/types/test.ts | 44 ++++ .../special/factorial2f/examples/c/Makefile | 146 ++++++++++++ .../special/factorial2f/examples/c/example.c | 32 +++ .../special/factorial2f/examples/index.js | 29 +++ .../base/special/factorial2f/include.gypi | 53 +++++ .../stdlib/math/base/special/factorial2f.h | 40 ++++ .../base/special/factorial2f/lib/index.js | 49 ++++ .../math/base/special/factorial2f/lib/main.js | 88 ++++++++ .../base/special/factorial2f/lib/native.js | 58 +++++ .../base/special/factorial2f/manifest.json | 84 +++++++ .../base/special/factorial2f/package.json | 70 ++++++ .../base/special/factorial2f/src/Makefile | 70 ++++++ .../math/base/special/factorial2f/src/addon.c | 22 ++ .../math/base/special/factorial2f/src/main.c | 65 ++++++ .../factorial2f/test/fixtures/integers.json | 1 + .../base/special/factorial2f/test/test.js | 99 +++++++++ .../special/factorial2f/test/test.native.js | 89 ++++++++ 28 files changed, 2230 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp create mode 100755 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/include/stdlib/math/base/special/factorial2f.h create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md new file mode 100644 index 000000000000..f6e4bd0882ba --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md @@ -0,0 +1,210 @@ + + +# factorial2 + +> [Double factorial][double-factorial] function. + +
+ +The [double factorial][double-factorial] of a number `n`, denoted `n!!`, is defined as the product of all the positive integers up to `n` that have the same parity (odd or even) as `n`. + +Thus, for example, `5!!` is `5 * 3 * 1 = 15` and `8!!` is `8 * 6 * 4 * 2 = 384`. + +
+ + + +
+ +## Usage + +```javascript +var factorial2 = require( '@stdlib/math/base/special/factorial2' ); +``` + +#### factorial2( n ) + +Evaluates the [double factorial][double-factorial] of `n`. + +```javascript +var v = factorial2( 2 ); +// returns 2 + +v = factorial2( 3 ); +// returns 3 + +v = factorial2( 0 ); +// returns 1 + +v = factorial2( 4 ); +// returns 8 + +v = factorial2( 5 ); +// returns 15 + +v = factorial2( NaN ); +// returns NaN + +v = factorial2( 301 ); +// returns Infinity +``` + +
+ + + +
+ +## Examples + + + +```javascript +var oneTo = require( '@stdlib/array/base/one-to' ); +var factorial2 = require( '@stdlib/math/base/special/factorial2' ); + +var values = oneTo( 300 ); + +var i; +for ( i = 0; i < values.length; i++ ) { + console.log( 'f(%d): %d', values[ i ], factorial2( values[ i ] ) ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/factorial2.h" +``` + +#### stdlib_base_factorial2( n ) + +Evaluates the [double factorial][double-factorial] of `n`. + +```c +double out = stdlib_base_factorial2( 3 ); +// returns 3 +``` + +The function accepts the following arguments: + +- **n**: `[in] int32_t` input value. + +```c +double stdlib_base_factorial2( const int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/factorial2.h" +#include +#include + +int main( void ) { + const int32_t x[] = { 1, 10, 1, 301, 302 }; + + double b; + int i; + for ( i = 0; i < 5; i++ ){ + b = stdlib_base_factorial2( x[ i ] ); + printf ( "factorial2(%d) = %lf\n", x[ i ], b ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js new file mode 100644 index 000000000000..50e9d3a6916f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var factorial2 = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = factorial2( i%301 ); + 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/factorial2f/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js new file mode 100644 index 000000000000..1005cff2615b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var factorial2 = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( factorial2 instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = factorial2( i % 301 ); + 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/factorial2f/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/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/factorial2f/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..01b814df4cbb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c @@ -0,0 +1,134 @@ +/** +* @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/factorial2.h" +#include +#include +#include +#include +#include +#include + +#define NAME "factorial2" +#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 double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + int32_t x; + double y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = (int32_t)(rand_double() * 301); + y = stdlib_base_factorial2( x ); + 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/factorial2f/benchmark/cpp/boost/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile new file mode 100644 index 000000000000..a4c3c2c9bc0d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile @@ -0,0 +1,110 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2023 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +endif + +# Specify the path to Boost: +BOOST ?= + +# Determine the OS: +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +endif +endif +endif + +# Define the program used for compiling C++ source files: +ifdef CXX_COMPILER + CXX := $(CXX_COMPILER) +else + CXX := g++ +endif + +# Define the command-line options when compiling C++ files: +CXXFLAGS ?= \ + -std=c++11 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate [position independent code][1]: +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of C++ targets: +cxx_targets := benchmark.out + + +# TARGETS # + +# Default target. +# +# This target is the default target. + +all: $(cxx_targets) + +.PHONY: all + + +# Compile C++ source. +# +# This target compiles C++ source files. + +$(cxx_targets): %.out: %.cpp $(BOOST) + $(QUIET) $(CXX) $(CXXFLAGS) $(fPIC) -I $(BOOST) -o $@ $< -lm + + +# Run a benchmark. +# +# This target runs a benchmark. + +run: $(cxx_targets) + $(QUIET) ./$< + +.PHONY: run + + +# Perform clean-up. +# +# This target removes generated files. + +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp new file mode 100644 index 000000000000..098066090835 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp @@ -0,0 +1,134 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::random::uniform_int_distribution; +using boost::random::uniform_real_distribution; +using boost::random::mt19937; + +#define NAME "factorial2" +#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; +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double y; + double t; + int x; + int i; + + // Define a new pseudorandom number generator: + mt19937 rng; + + // Define a uniform distribution for generating pseudorandom numbers as "integers" between a minimum value (inclusive) and a maximum value (exclusive): + uniform_int_distribution<> randu( 0, 100 ); + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = randu( rng ); + y = (double)boost::math::double_factorial( x ); + 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; + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# cpp::boost::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py new file mode 100755 index 000000000000..7c7a672cb57d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# +# @license Apache-2.0 +# +# Copyright (c) 2023 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 scipy.special.factorial2.""" + +from __future__ import print_function +import timeit + +NAME = "factorial2" +REPEATS = 3 +ITERATIONS = 1000000 + + +def print_version(): + """Print the TAP version.""" + print("TAP version 13") + + +def print_summary(total, passing): + """Print the benchmark summary. + + # Arguments + + * `total`: total number of tests + * `passing`: number of passing tests + + """ + print("#") + print("1.." + str(total)) # TAP plan + print("# total " + str(total)) + print("# pass " + str(passing)) + print("#") + print("# ok") + + +def print_results(elapsed): + """Print benchmark results. + + # Arguments + + * `elapsed`: elapsed time (in seconds) + + # Examples + + ``` python + python> print_results(0.131009101868) + ``` + """ + rate = ITERATIONS / elapsed + + print(" ---") + print(" iterations: " + str(ITERATIONS)) + print(" elapsed: " + str(elapsed)) + print(" rate: " + str(rate)) + print(" ...") + + +def benchmark(): + """Run the benchmark and print benchmark results.""" + setup = "from scipy.special import factorial2; from math import floor; from random import random;" + stmt = "y = factorial2(floor(301.0*random()), exact=True)" + + t = timeit.Timer(stmt, setup=setup) + + print_version() + + for i in range(REPEATS): + print("# python::scipy::" + NAME) + elapsed = t.timeit(number=ITERATIONS) + print_results(elapsed) + print("ok " + str(i+1) + " benchmark finished") + + print_summary(REPEATS, REPEATS) + + +def main(): + """Run the benchmark.""" + benchmark() + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp b/lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/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/factorial2f/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt new file mode 100644 index 000000000000..343a619d8f7b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( n ) + Evaluates the double factorial of `n`. + + If provided `NaN`, the function returns `NaN`. + + Parameters + ---------- + n: number + Input value. + + Returns + ------- + y: number + Double factorial. + + Examples + -------- + > var y = {{alias}}( 3 ) + 3 + > y = {{alias}}( 5 ) + 15 + > y = {{alias}}( 6 ) + 48 + > y = {{alias}}( 301 ) + Infinity + > y = {{alias}}( NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts new file mode 100644 index 000000000000..fbc462935078 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts @@ -0,0 +1,53 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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 + +/** +* Evaluates the double factorial of `n`. +* +* @param n - input value +* @returns double factorial +* +* @example +* var v = factorial2( 3 ); +* // returns 3 +* +* @example +* var v = factorial2( 4 ); +* // returns 8 +* +* @example +* var v = factorial2( -10 ); +* // returns NaN +* +* @example +* var v = factorial2( 301 ); +* // returns Infinity +* +* @example +* var v = factorial2( NaN ); +* // returns NaN +*/ +declare function factorial2( n: number ): number; + + +// EXPORTS // + +export = factorial2; + diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts new file mode 100644 index 000000000000..b9e649dc57a0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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 factorial2 = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + factorial2( 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + factorial2( true ); // $ExpectError + factorial2( false ); // $ExpectError + factorial2( null ); // $ExpectError + factorial2( undefined ); // $ExpectError + factorial2( '5' ); // $ExpectError + factorial2( [] ); // $ExpectError + factorial2( {} ); // $ExpectError + factorial2( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + factorial2(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/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/factorial2f/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c new file mode 100644 index 000000000000..f2e0f6c2de94 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c @@ -0,0 +1,32 @@ +/** +* @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/factorial2.h" +#include +#include + +int main( void ) { + const int32_t x[] = { 1, 10, 1, 301, 302 }; + + double b; + int i; + for ( i = 0; i < 5; i++ ) { + b = stdlib_base_factorial2( x[ i ] ); + printf ( "factorial2(%d) = %lf\n", x[ i ], b ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js new file mode 100644 index 000000000000..4c6273deb3ce --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js @@ -0,0 +1,29 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 oneTo = require( '@stdlib/array/base/one-to' ); +var factorial2 = require( './../lib' ); + +var values = oneTo( 300 ); + +var i; +for ( i = 0; i < values.length; i++ ) { + console.log( 'f(%d): %d', values[ i ], factorial2( values[ i ] ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi b/lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/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 + +/** +* Evaluates the double factorial of `n` as a single-precision floating-point number. +*/ +float stdlib_base_factorial2f( const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_FACTORIAL2F_H diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js new file mode 100644 index 000000000000..62493349912d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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'; + +/** +* Evaluate the double factorial as a single-precision floating-point number. +* +* @module @stdlib/math/base/special/factorial2f +* +* @example +* var factorial2f = require( '@stdlib/math/base/special/factorial2f' ); +* +* var v = factorial2f( 3 ); +* // returns 3 +* +* v = factorial2f( 4 ); +* // returns 8 +* +* v = factorial2f( -10 ); +* // returns NaN +* +* v = factorial( NaN ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js new file mode 100644 index 000000000000..b85acef67ece --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); +var isEvenf = require( '@stdlib/math/base/assert/is-evenf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float32/max-safe-nth-double-factorial' ); // eslint-disable-line id-length + + +// MAIN // + +/** +* Evaluates the double factorial of `n` as a single-precision floating-point number. +* +* @param {number} n - input value +* @returns {(NonNegativeInteger|number)} double factorial +* +* @example +* var v = factorial2f( 3 ); +* // returns 3 +* +* @example +* var v = factorial2f( 4 ); +* // returns 8 +* +* @example +* var v = factorial2f( 5 ); +* // returns 15 +* +* @example +* var v = factorial2f( 301 ); +* // returns Infinity +*/ +function factorial2f( n ) { + var last; + var out; + var v; + var i; + + if ( isnanf( n ) ) { + return NaN; + } + if ( n > FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL ) { + return PINF; + } + if ( n < 0 || isIntegerf( n ) === false ) { + return NaN; + } + v = n|0; // asm type annotation + if ( v === 0|0 || v === 1|0 ) { + return 1|0; // asm type annotation + } + if ( isEvenf( v ) ) { + last = 2|0; // asm type annotation + } else { + last = 3|0; // asm type annotation + } + out = 1; + for ( i = v|0; i >= last; i -= 2|0 ) { + out *= i|0; // asm type annotation + } + return out; +} + + +// EXPORTS // + +module.exports = factorial2f; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js new file mode 100644 index 000000000000..f24115dc1c17 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.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'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the double factorial of `n` as a single-precision floating-point number. +* +* @private +* @param {number} n - input value +* @returns {(NonNegativeInteger|number)} double factorial +* +* @example +* var v = factorial2f( 3 ); +* // returns 3 +* +* @example +* var v = factorial2f( 4 ); +* // returns 8 +* +* @example +* var v = factorial2f( 5 ); +* // returns 15 +* +* @example +* var v = factorial2f( 301 ); +* // returns Infinity +*/ +function factorial2f( n ) { + return addon( n ); +} + + +// EXPORTS // + +module.exports = factorial2f; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json new file mode 100644 index 000000000000..e919c0549ad8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json @@ -0,0 +1,84 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/unary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-integer", + "@stdlib/math/base/assert/is-even", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/max-safe-nth-double-factorial" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-integer", + "@stdlib/math/base/assert/is-even", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/max-safe-nth-double-factorial" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-integer", + "@stdlib/math/base/assert/is-even", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/max-safe-nth-double-factorial" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json new file mode 100644 index 000000000000..d634235026d1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/math/base/special/factorial2", + "version": "0.0.0", + "description": "Evaluate the double factorial.", + "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", + "factorial", + "fact", + "dfact", + "factorial2", + "combinatorics", + "double", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/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/factorial2f/src/addon.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c new file mode 100644 index 000000000000..f909faf513be --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c @@ -0,0 +1,22 @@ +/** +* @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/factorial2f.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_factorial2f ) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c new file mode 100644 index 000000000000..dc84967db771 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c @@ -0,0 +1,65 @@ +/** +* @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/factorial2f.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/assert/is_integerf.h" +#include "stdlib/math/base/assert/is_evenf.h" +#include "stdlib/constants/float32/pinf.h" +#include "stdlib/constants/float32/max_safe_nth_double_factorial.h" +#include + +/** +* Evaluates the double factorial of `n` as a single-precision floating-point number. +* +* @param x input value +* @return double factorial +* +* @example +* float v = stdlib_base_factorial2f( 3 ); +* // returns 3.0f +*/ +float stdlib_base_factorial2f( const int32_t n ) { + int32_t last; + float out; + int32_t v; + int32_t i; + if ( stdlib_base_is_nanf( n ) ) { + return 0.0f / 0.0f; // NaN + } + if ( n > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL ) { + return STDLIB_CONSTANT_FLOAT32_PINF; + } + if ( n < 0 || !stdlib_base_is_integerf( n ) ) { + return 0.0f / 0.0f; // NaN + } + v = n; + if ( v == 0 || v == 1 ) { + return 1.0f; + } + if ( stdlib_base_is_evenf( v ) ) { + last = 2; + } else { + last = 3; + } + out = 1.0f; + for ( i = v; i >= last; i -= 2 ) { + out *= i; + } + return out; +} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json new file mode 100644 index 000000000000..4fd06bac55ad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json @@ -0,0 +1 @@ +{"expected":[1,1,2,3,8,15,48,105,384,945,3840,10395,46080,135135,645120,2027025,10321920,34459425,185794560,654729075,3715891200,13749310575,81749606400,316234143225,1961990553600,7905853580625,51011754393600,213458046676875,1428329123020800,6190283353629375,42849873690624000,191898783962510660,1371195958099968000,6332659870762851000,46620662575398910000,221643095476699730000,1.6783438527143608e+21,8.200794532637892e+21,6.377706640314571e+22,3.198309867728777e+23,2.5510826561258285e+24,1.3113070457687992e+25,1.071454715572848e+26,5.638620296805836e+26,4.714400748520531e+27,2.5373791335626256e+28,2.1686243443194444e+29,1.1925681927744343e+30,1.0409396852733332e+31,5.843584144594729e+31,5.2046984263666655e+32,2.980227913743312e+33,2.706443181710667e+34,1.5795207942839554e+35,1.4614793181237598e+36,8.68736436856175e+36,8.184284181493054e+37,4.951797690080199e+38,4.7468848252659714e+39,2.9215606371473157e+40,2.8481308951595837e+41,1.7821519886598634e+42,1.7658411549989418e+43,1.122755752855714e+44,1.1301383391993227e+45,7.297912393562142e+45,7.458913038715532e+46,4.889601303686633e+47,5.072060866326559e+48,3.3738248995437775e+49,3.5504426064285917e+50,2.3954156786760817e+51,2.556318676628587e+52,1.7486534454335405e+53,1.891675820705154e+54,1.3114900840751548e+55,1.4376736237359167e+56,1.0098473647378693e+57,1.1213854265140154e+58,7.97779418142917e+58,8.971083412112124e+59,6.462013286957625e+60,7.356288397931937e+61,5.36347102817483e+62,6.17928225426283e+63,4.558950373948604e+64,5.314182738666034e+65,3.966286825335286e+66,4.6764808100261105e+67,3.5299952745484044e+68,4.208832729023499e+69,3.2122956998390475e+70,3.8721261107016185e+71,2.9874350008503146e+72,3.6397985440595225e+73,2.838063250807798e+74,3.494206602297139e+75,2.752921353283565e+76,3.4243224702511995e+77,2.725392139750729e+78,3.4243224702511973e+79,2.752646061148237e+80,3.49280891965622e+81,2.8352254429826852e+82,3.6325212764424714e+83,2.9769867151318193e+84,3.850472553029017e+85,3.1853757851910447e+86,4.158510357271338e+87,3.4720596058582394e+88,4.57436139299847e+89,3.853986162502647e+90,5.123284760158289e+91,4.3550043636279923e+92,5.840544626580453e+93,5.008255018172187e+94,6.775031766833325e+95,5.859658371261462e+96,7.994537484863321e+97,6.972993461801133e+98,9.593444981835987e+99,8.437322088779378e+100,1.17040028778399e+102,1.037790616919863e+103,1.4512963568521482e+104,1.297238271149829e+105,1.8286334096337062e+106,1.647492604360282e+107,2.340650764331144e+108,2.125265459624765e+109,3.042845993630488e+110,2.784097752108442e+111,4.016556711592245e+112,3.702850010304227e+113,5.38218599353361e+114,4.998847513910709e+115,7.319772951205704e+116,6.848421094057669e+117,1.010128667266387e+119,9.51930532074016e+119,1.4141801341729423e+121,1.3422220502243633e+122,2.0081357905255783e+123,1.9193775318208374e+124,2.8917155383568337e+125,2.783097421140216e+126,4.2219046860009767e+127,4.091153209076121e+128,6.248418935281444e+129,6.095818281523413e+130,9.372628402922167e+131,9.204685605100356e+132,1.4246395172441694e+134,1.4083168975803545e+135,2.193944856556021e+136,2.182891191249551e+137,3.422553976227391e+138,3.4271391702617923e+139,5.407635282439282e+140,5.44915128071625e+141,8.652216451902846e+142,8.77313356195316e+143,1.4016590652082614e+145,1.430020770598365e+146,2.298720866941549e+147,2.3595342714873052e+148,3.8158766391229716e+149,3.940422233383796e+150,6.410672753726591e+151,6.659313574418614e+152,1.0898143681335199e+154,1.138742621225583e+155,1.8744807131896557e+156,1.9700247347202608e+157,3.261596440949998e+158,3.4475432857604565e+159,5.740409736071998e+160,6.102151615796e+161,1.0217929330208161e+163,1.0922851392274846e+164,1.8392272794374673e+165,1.977036102001747e+166,3.3473936485761936e+167,3.617976066663198e+168,6.159204313380194e+169,6.693255723326915e+170,1.1456120022887156e+172,1.2516388202621332e+173,2.1537505643027855e+174,2.3655973702954314e+175,4.0921260721752947e+176,4.5182909772642765e+177,7.85688205857656e+178,8.720301586120049e+179,1.5242351193638541e+181,1.7004588092934085e+182,2.987500833953153e+183,3.3499038543080163e+184,5.915251651227243e+185,6.666308670072953e+186,1.1830503302454489e+188,1.3399280426846627e+189,2.3897616670958062e+190,2.720053926649867e+191,4.875113800875444e+192,5.576110549632227e+193,1.0042734429803413e+195,1.1542548837738706e+196,2.0888887613991112e+197,2.412392707087392e+198,4.386666398938133e+199,5.090148611954389e+200,9.299732765748842e+201,1.0842016543462863e+203,1.9901428118702507e+204,2.3310335568445134e+205,4.298708473639744e+206,5.0583428183525975e+207,9.371184472534645e+208,1.1077770772192188e+210,2.0616605839576203e+211,2.4481873406544742e+212,4.5768864963859216e+213,5.459457769659478e+214,1.0252225751904463e+216,1.2283779981733826e+217,2.3170030199304077e+218,2.7884180558535752e+219,5.282766885441326e+220,6.385477347904693e+221,1.215036383651505e+223,1.4750452673659832e+224,2.8188844100714938e+225,3.436855472962742e+226,6.596189519567293e+227,8.076610361462444e+228,1.556700726617881e+230,1.9141566556665982e+231,3.704947729350558e+232,4.574834407043174e+233,8.891874550441349e+234,1.1025350920974053e+236,2.151833641206804e+237,2.679160273796695e+238,5.2504740845446015e+239,6.5639426708019e+240,1.2916166247979722e+242,1.6212938396880689e+243,3.203209229498971e+244,4.0370216608232914e+245,8.008023073747427e+246,1.0132924368666467e+248,2.0180218145843526e+249,2.5636298652726167e+250,5.125775409044258e+251,6.537256156445165e+252,1.31219850471533e+254,1.6800748322064072e+255,3.385472142165548e+256,4.351393815414601e+257,8.802227569630424e+258,1.1357137858232108e+260,2.306183623243169e+261,2.9869272567150425e+262,6.088324765361969e+263,7.915357230294858e+264,1.6194943875862835e+266,2.1134003804887267e+267,4.3402449587312456e+268,5.685047023514677e+269,1.171866138857435e+271,1.540647743372478e+272,3.1874758976922244e+273,4.205968339406865e+274,8.73368395967669e+275,1.1566412933368878e+277,2.410496772870766e+278,3.203896382543182e+279,6.701181028580735e+280,8.93887090729547e+281,1.8763306880026056e+283,2.5118227249500288e+284,5.291252540167349e+285,7.108458311608575e+286,1.5027157214075273e+288,2.0259106188084445e+289,4.297766963225523e+290,5.814363475980235e+291,1.2377568854089524e+293,1.6803510445582872e+294,3.589494967685959e+295,4.889821539664618e+296,1.0481325305643003e+298,1.4327177111217326e+299,3.081509639859045e+300,4.2265172478091117e+301,9.121268533982761e+302,1.2552756225993057e+304,2.718138023126864e+305,3.753274111571923e+306,8.154414069380598e+307],"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300]} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js new file mode 100644 index 000000000000..6cae14a08035 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrspace = require( '@stdlib/array/base/incrspace' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var factorial2 = require( './../lib' ); + + +// FIXTURES // + +var integers = require( './fixtures/integers.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factorial2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a negative integer, the function returns `NaN`', function test( t ) { + var values; + var v; + var i; + + values = incrspace( -1.0, -1000.0, -25.0 ); + for ( i = 0; i < values.length; i++ ) { + v = factorial2( values[ i ] ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'if provided negative infinity, the function returns `NaN`', function test( t ) { + var v = factorial2( NINF ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided positive infinity, the function returns `+infinity`', function test( t ) { + var v = factorial2( PINF ); + t.strictEqual( v, PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { + var v = factorial2( NaN ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function evaluates the double factorial', function test( t ) { + var expected; + var x; + var v; + var i; + + x = integers.x; + expected = integers.expected; + + for ( i = 0; i < x.length; i++ ) { + v = factorial2( x[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value when provided ' + x[ i ] ); + } + t.end(); +}); + +tape( 'if provided integers greater than `300`, the function returns positive infinity', function test( t ) { + var i; + var v; + for ( i = 301; i < 500; i++ ) { + v = factorial2( i ); + t.strictEqual( v, PINF, 'returns expected value when provided ' + i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js new file mode 100644 index 000000000000..b19461c169ef --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js @@ -0,0 +1,89 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrspace = require( '@stdlib/array/base/incrspace' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// FIXTURES // + +var integers = require( './fixtures/integers.json' ); + + +// VARIABLES // + +var factorial2 = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( factorial2 instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factorial2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a negative integer, the function returns `NaN`', opts, function test( t ) { + var values; + var v; + var i; + + values = incrspace( -1.0, -1000.0, -25.0 ); + for ( i = 0; i < values.length; i++ ) { + v = factorial2( values[ i ] ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function evaluates the double factorial', opts, function test( t ) { + var expected; + var x; + var v; + var i; + + x = integers.x; + expected = integers.expected; + + for ( i = 0; i < x.length; i++ ) { + v = factorial2( x[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value when provided ' + x[ i ] ); + } + t.end(); +}); + +tape( 'if provided integers greater than `300`, the function returns `+infinity`', opts, function test( t ) { + var i; + var v; + for ( i = 301; i < 500; i++ ) { + v = factorial2( i ); + t.strictEqual( v, PINF, 'returns expected value when provided ' + i ); + } + t.end(); +}); From 137d3e77766456c9787e69eacae0a7ed0f058583 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 19 Apr 2025 16:45:56 -0700 Subject: [PATCH 02/16] feat: add complete implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/factorial2f/README.md | 96 +++++++------ .../factorial2f/benchmark/benchmark.js | 18 ++- .../factorial2f/benchmark/benchmark.native.js | 20 ++- .../benchmark/c/native/benchmark.c | 21 +-- .../factorial2f/benchmark/cpp/boost/Makefile | 110 -------------- .../benchmark/cpp/boost/benchmark.cpp | 134 ------------------ .../benchmark/python/scipy/benchmark.py | 97 ------------- .../base/special/factorial2f/docs/repl.txt | 19 ++- .../special/factorial2f/docs/types/index.d.ts | 27 ++-- .../special/factorial2f/docs/types/test.ts | 24 ++-- .../special/factorial2f/examples/c/example.c | 12 +- .../special/factorial2f/examples/index.js | 14 +- .../base/special/factorial2f/lib/index.js | 3 + .../math/base/special/factorial2f/lib/main.js | 12 +- .../base/special/factorial2f/lib/native.js | 8 +- .../base/special/factorial2f/package.json | 7 +- .../math/base/special/factorial2f/src/main.c | 5 +- .../factorial2f/test/fixtures/integers.json | 1 - .../test/fixtures/python/data.json | 1 + .../test/fixtures/python/runner.py | 71 ++++++++++ .../base/special/factorial2f/test/test.js | 50 ++++--- .../special/factorial2f/test/test.native.js | 24 +++- 22 files changed, 283 insertions(+), 491 deletions(-) delete mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile delete mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp delete mode 100755 lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py delete mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/data.json create mode 100644 lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md index f6e4bd0882ba..ac21c38767f9 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# factorial2 +# factorial2f -> [Double factorial][double-factorial] function. +> Evaluate the [double factorial][double-factorial] function as a single-precision floating-point number.
@@ -37,36 +37,48 @@ Thus, for example, `5!!` is `5 * 3 * 1 = 15` and `8!!` is `8 * 6 * 4 * 2 = 384`. ## Usage ```javascript -var factorial2 = require( '@stdlib/math/base/special/factorial2' ); +var factorial2f = require( '@stdlib/math/base/special/factorial2f' ); ``` -#### factorial2( n ) +#### factorial2f( n ) -Evaluates the [double factorial][double-factorial] of `n`. +Evaluates the [double factorial][double-factorial] of `n` as a single-precision floating-point number. ```javascript -var v = factorial2( 2 ); -// returns 2 - -v = factorial2( 3 ); +v = factorial2f( 3 ); // returns 3 -v = factorial2( 0 ); -// returns 1 - -v = factorial2( 4 ); +v = factorial2f( 4 ); // returns 8 -v = factorial2( 5 ); -// returns 15 +v = factorial2f( 10 ); +// returns 3840 +``` -v = factorial2( NaN ); -// returns NaN +If `n > 56`, the function returns `NaN`, as larger [double factorial][double-factorial] values cannot be safely represented in [single-precision floating-point format][ieee754]. -v = factorial2( 301 ); +```javascript +var v = factorial2f( 57 ); // returns Infinity ``` +If not provided a nonnegative integer value, the function returns `NaN`. + +```javascript +var v = factorial2f( 3.14 ); +// returns NaN + +v = factorial2f( -1 ); +// returns NaN +``` + +If provided `NaN`, the function returns `NaN`. + +```javascript +var v = factorial2f( NaN ); +// returns NaN +``` +
@@ -78,15 +90,15 @@ v = factorial2( 301 ); ```javascript -var oneTo = require( '@stdlib/array/base/one-to' ); -var factorial2 = require( '@stdlib/math/base/special/factorial2' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var factorial2f = require( '@stdlib/math/base/special/factorial2f' ); -var values = oneTo( 300 ); +var x = discreteUniform( 10, 0, 56, { + 'dtype': 'int32' +}); -var i; -for ( i = 0; i < values.length; i++ ) { - console.log( 'f(%d): %d', values[ i ], factorial2( values[ i ] ) ); -} +logEachMap( 'factorial2f(%d) = %0.1f', x, factorial2f ); ``` @@ -116,16 +128,16 @@ for ( i = 0; i < values.length; i++ ) { ### Usage ```c -#include "stdlib/math/base/special/factorial2.h" +#include "stdlib/math/base/special/factorial2f.h" ``` -#### stdlib_base_factorial2( n ) +#### stdlib_base_factorial2f( n ) -Evaluates the [double factorial][double-factorial] of `n`. +Evaluates the [double factorial][double-factorial] of `n` as a single-precision floating-point number. ```c -double out = stdlib_base_factorial2( 3 ); -// returns 3 +float out = stdlib_base_factorial2f( 3 ); +// returns 3.0f ``` The function accepts the following arguments: @@ -133,7 +145,7 @@ The function accepts the following arguments: - **n**: `[in] int32_t` input value. ```c -double stdlib_base_factorial2( const int32_t n ); +float stdlib_base_factorial2f( const int32_t n ); ``` @@ -155,18 +167,18 @@ double stdlib_base_factorial2( const int32_t n ); ### Examples ```c -#include "stdlib/math/base/special/factorial2.h" +#include "stdlib/math/base/special/factorial2f.h" #include #include int main( void ) { - const int32_t x[] = { 1, 10, 1, 301, 302 }; + const int32_t x[] = { 1, 10, 50, 56, 57 }; - double b; + float b; int i; - for ( i = 0; i < 5; i++ ){ - b = stdlib_base_factorial2( x[ i ] ); - printf ( "factorial2(%d) = %lf\n", x[ i ], b ); + for ( i = 0; i < 5; i++ ) { + b = stdlib_base_factorial2f( x[ i ] ); + printf ( "factorial2f(%d) = %f\n", x[ i ], b ); } } ``` @@ -183,12 +195,6 @@ int main( void ) { @@ -199,9 +205,9 @@ int main( void ) { [double-factorial]: https://en.wikipedia.org/wiki/Double_factorial - +[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 -[@stdlib/math/base/special/factorial]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/factorial + diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js index 50e9d3a6916f..97b43ab19652 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,26 +21,32 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var pkg = require( './../package.json' ).name; -var factorial2 = require( './../lib' ); +var factorial2f = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { + var x; var y; var i; + x = discreteUniform( 100, 0, 56, { + 'dtype': 'int32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = factorial2( i%301 ); - if ( isnan( y ) ) { + y = factorial2f( x[ i%x.length ] ); + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( y ) ) { + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js index 1005cff2615b..697038c4d45a 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,34 +22,40 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; // VARIABLES // -var factorial2 = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var factorial2f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { - 'skip': ( factorial2 instanceof Error ) + 'skip': ( factorial2f instanceof Error ) }; // MAIN // bench( pkg+'::native', opts, function benchmark( b ) { + var x; var y; var i; + x = discreteUniform( 100, 0, 56, { + 'dtype': 'int32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = factorial2( i % 301 ); - if ( isnan( y ) ) { + y = factorial2f( x[ i%x.length ] ); + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( y ) ) { + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c index 01b814df4cbb..3dce326fbd78 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/benchmark.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * limitations under the License. */ -#include "stdlib/math/base/special/factorial2.h" +#include "stdlib/math/base/special/factorial2f.h" #include #include #include @@ -24,7 +24,7 @@ #include #include -#define NAME "factorial2" +#define NAME "factorial2f" #define ITERATIONS 1000000 #define REPEATS 3 @@ -80,9 +80,9 @@ static double tic( void ) { * * @return random number */ -static double rand_double( void ) { +static float rand_float( void ) { int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); + return (float)r / ( (float)RAND_MAX + 1.0f ); } /** @@ -91,16 +91,19 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + int32_t x[ 100 ]; double elapsed; - int32_t x; - double y; double t; + float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = (int32_t)( 56*rand_float() ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = (int32_t)(rand_double() * 301); - y = stdlib_base_factorial2( x ); + y = stdlib_base_factorial2f( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile deleted file mode 100644 index a4c3c2c9bc0d..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/Makefile +++ /dev/null @@ -1,110 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2023 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -endif - -# Specify the path to Boost: -BOOST ?= - -# Determine the OS: -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -endif -endif -endif - -# Define the program used for compiling C++ source files: -ifdef CXX_COMPILER - CXX := $(CXX_COMPILER) -else - CXX := g++ -endif - -# Define the command-line options when compiling C++ files: -CXXFLAGS ?= \ - -std=c++11 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate [position independent code][1]: -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of C++ targets: -cxx_targets := benchmark.out - - -# TARGETS # - -# Default target. -# -# This target is the default target. - -all: $(cxx_targets) - -.PHONY: all - - -# Compile C++ source. -# -# This target compiles C++ source files. - -$(cxx_targets): %.out: %.cpp $(BOOST) - $(QUIET) $(CXX) $(CXXFLAGS) $(fPIC) -I $(BOOST) -o $@ $< -lm - - -# Run a benchmark. -# -# This target runs a benchmark. - -run: $(cxx_targets) - $(QUIET) ./$< - -.PHONY: run - - -# Perform clean-up. -# -# This target removes generated files. - -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp deleted file mode 100644 index 098066090835..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/cpp/boost/benchmark.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using boost::random::uniform_int_distribution; -using boost::random::uniform_real_distribution; -using boost::random::mt19937; - -#define NAME "factorial2" -#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; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - double y; - double t; - int x; - int i; - - // Define a new pseudorandom number generator: - mt19937 rng; - - // Define a uniform distribution for generating pseudorandom numbers as "integers" between a minimum value (inclusive) and a maximum value (exclusive): - uniform_int_distribution<> randu( 0, 100 ); - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - x = randu( rng ); - y = (double)boost::math::double_factorial( x ); - 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; - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# cpp::boost::%s\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); - return 0; -} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py deleted file mode 100755 index 7c7a672cb57d..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/python/scipy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2023 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 scipy.special.factorial2.""" - -from __future__ import print_function -import timeit - -NAME = "factorial2" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "from scipy.special import factorial2; from math import floor; from random import random;" - stmt = "y = factorial2(floor(301.0*random()), exact=True)" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::scipy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt index 343a619d8f7b..8f362fe7b25b 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/repl.txt @@ -1,6 +1,13 @@ {{alias}}( n ) - Evaluates the double factorial of `n`. + Evaluates the double factorial of `n` as a single-precision floating-point + number. + + If `n` is greater than `56`, the function returns `NaN`, as larger double + factorial values cannot be accurately represented due to limitations of + single-precision floating-point format. + + If not provided a nonnegative integer value, the function returns `NaN`. If provided `NaN`, the function returns `NaN`. @@ -18,12 +25,12 @@ -------- > var y = {{alias}}( 3 ) 3 - > y = {{alias}}( 5 ) - 15 - > y = {{alias}}( 6 ) - 48 - > y = {{alias}}( 301 ) + > y = {{alias}}( 4 ) + 8 + > y = {{alias}}( 57 ) Infinity + > y = {{alias}}( -10 ) + NaN > y = {{alias}}( NaN ) NaN diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts index fbc462935078..b886be047623 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,35 +19,40 @@ // TypeScript Version: 4.1 /** -* Evaluates the double factorial of `n`. +* Evaluates the double factorial of `n` as a single-precision floating-point number. +* +* ## Notes +* +* - If `n` is greater than `56`, the function returns `NaN`, as larger double factorial values cannot be accurately represented due to limitations of single-precision floating-point format. +* - If not provided a nonnegative integer value, the function returns `NaN`. * * @param n - input value * @returns double factorial * * @example -* var v = factorial2( 3 ); +* var v = factorial2f( 3 ); * // returns 3 * * @example -* var v = factorial2( 4 ); +* var v = factorial2f( 4 ); * // returns 8 * * @example -* var v = factorial2( -10 ); -* // returns NaN +* var v = factorial2f( 57 ); +* // returns Infinity * * @example -* var v = factorial2( 301 ); -* // returns Infinity +* var v = factorial2f( -10 ); +* // returns NaN * * @example -* var v = factorial2( NaN ); +* var v = factorial2f( NaN ); * // returns NaN */ -declare function factorial2( n: number ): number; +declare function factorial2f( n: number ): number; // EXPORTS // -export = factorial2; +export = factorial2f; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts index b9e649dc57a0..377778944f99 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,29 +16,29 @@ * limitations under the License. */ -import factorial2 = require( './index' ); +import factorial2f = require( './index' ); // TESTS // // The function returns a number... { - factorial2( 2 ); // $ExpectType number + factorial2f( 2 ); // $ExpectType number } // The compiler throws an error if the function is provided a value other than a number... { - factorial2( true ); // $ExpectError - factorial2( false ); // $ExpectError - factorial2( null ); // $ExpectError - factorial2( undefined ); // $ExpectError - factorial2( '5' ); // $ExpectError - factorial2( [] ); // $ExpectError - factorial2( {} ); // $ExpectError - factorial2( ( x: number ): number => x ); // $ExpectError + factorial2f( true ); // $ExpectError + factorial2f( false ); // $ExpectError + factorial2f( null ); // $ExpectError + factorial2f( undefined ); // $ExpectError + factorial2f( '5' ); // $ExpectError + factorial2f( [] ); // $ExpectError + factorial2f( {} ); // $ExpectError + factorial2f( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments... { - factorial2(); // $ExpectError + factorial2f(); // $ExpectError } diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c index f2e0f6c2de94..91ee56b05395 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,17 @@ * limitations under the License. */ -#include "stdlib/math/base/special/factorial2.h" +#include "stdlib/math/base/special/factorial2f.h" #include #include int main( void ) { - const int32_t x[] = { 1, 10, 1, 301, 302 }; + const int32_t x[] = { 1, 10, 50, 56, 57 }; - double b; + float b; int i; for ( i = 0; i < 5; i++ ) { - b = stdlib_base_factorial2( x[ i ] ); - printf ( "factorial2(%d) = %lf\n", x[ i ], b ); + b = stdlib_base_factorial2f( x[ i ] ); + printf ( "factorial2f(%d) = %f\n", x[ i ], b ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js index 4c6273deb3ce..bff4fa4c77ca 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js @@ -18,12 +18,12 @@ 'use strict'; -var oneTo = require( '@stdlib/array/base/one-to' ); -var factorial2 = require( './../lib' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var factorial2f = require( './../lib' ); -var values = oneTo( 300 ); +var x = discreteUniform( 10, 0, 56, { + 'dtype': 'int32' +}); -var i; -for ( i = 0; i < values.length; i++ ) { - console.log( 'f(%d): %d', values[ i ], factorial2( values[ i ] ) ); -} +logEachMap( 'factorial2f(%d) = %0.1f', x, factorial2f ); diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js index 62493349912d..e8aa7c7ec9b9 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js @@ -32,6 +32,9 @@ * v = factorial2f( 4 ); * // returns 8 * +* v = factorial2f( 57 ); +* // returns Infinity +* * v = factorial2f( -10 ); * // returns NaN * diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js index b85acef67ece..6e9832b93c9d 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -44,12 +44,16 @@ var FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float32/ * // returns 8 * * @example -* var v = factorial2f( 5 ); -* // returns 15 +* var v = factorial2f( 57 ); +* // returns Infinity * * @example -* var v = factorial2f( 301 ); -* // returns Infinity +* var v = factorial2f( -10 ); +* // returns NaN +* +* @example +* var v = factorial2f( NaN ); +* // returns NaN */ function factorial2f( n ) { var last; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js index f24115dc1c17..11694617b46d 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js @@ -41,12 +41,12 @@ var addon = require( './../src/addon.node' ); * // returns 8 * * @example -* var v = factorial2f( 5 ); -* // returns 15 +* var v = factorial2f( 57 ); +* // returns Infinity * * @example -* var v = factorial2f( 301 ); -* // returns Infinity +* var v = factorial2f( -10 ); +* // returns NaN */ function factorial2f( n ) { return addon( n ); diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json index d634235026d1..a3ef951a9087 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/math/base/special/factorial2", + "name": "@stdlib/math/base/special/factorial2f", "version": "0.0.0", - "description": "Evaluate the double factorial.", + "description": "Evaluate the double factorial as a single-precision floating-point number.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -62,7 +62,8 @@ "factorial", "fact", "dfact", - "factorial2", + "factorialf", + "factorial2f", "combinatorics", "double", "number" diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c index dc84967db771..0a42190d1f3f 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,10 @@ */ float stdlib_base_factorial2f( const int32_t n ) { int32_t last; - float out; int32_t v; int32_t i; + float out; + if ( stdlib_base_is_nanf( n ) ) { return 0.0f / 0.0f; // NaN } diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json deleted file mode 100644 index 619b03b8b6a6..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/integers.json +++ /dev/null @@ -1 +0,0 @@ -{"expected":[1,1,2,3,8,15,48,105,384,945,3840,10395,46080,135135,645120,2027025,10321920,34459425,185794560,654729075,3715891200,13749310575,81749606400,316234143225,1961990553600,7905853580625,51011754393600,213458046676875,1428329123020800,6190283353629375,42849873690624000,191898783962510660,1371195958099968000,6332659870762851000,46620662575398910000,221643095476699730000,1.6783438527143608e+21,8.200794532637892e+21,6.377706640314571e+22,3.198309867728777e+23,2.5510826561258285e+24,1.3113070457687992e+25,1.071454715572848e+26,5.638620296805836e+26,4.714400748520531e+27,2.5373791335626256e+28,2.1686243443194444e+29,1.1925681927744343e+30,1.0409396852733332e+31,5.843584144594729e+31,5.2046984263666655e+32,2.980227913743312e+33,2.706443181710667e+34,1.5795207942839554e+35,1.4614793181237598e+36,8.68736436856175e+36,8.184284181493054e+37],"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56]} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/data.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/data.json new file mode 100644 index 000000000000..516310e2be8e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/data.json @@ -0,0 +1 @@ +{"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56], "expected": [1.0, 2.0, 3.0, 8.0, 15.0, 48.0, 105.0, 384.0, 945.0, 3840.0, 10395.0, 46080.0, 135135.0, 645120.0, 2027025.0, 10321920.0, 34459424.0, 185794560.0, 654729088.0, 3715891200.0, 13749310464.0, 81749606400.0, 316234137600.0, 1961990553600.0, 7905853571072.0, 51011754393600.0, 213458045894656.0, 1428329089466368.0, 6190283213504512.0, 4.284987509991014e+16, 1.9189877800802714e+17, 1.3711960031971246e+18, 6.332659760164241e+18, 4.662066081016735e+19, 2.21643089956481e+20, 1.6783438067582108e+21, 8.200794275613239e+21, 6.377706859746168e+22, 3.198309818154659e+23, 2.5510826718408733e+24, 1.3113070938981246e+25, 1.0714546875855216e+26, 5.638620319294495e+26, 4.7144007360567597e+27, 2.537379221158848e+28, 2.1686244035186486e+29, 1.1925682221387423e+30, 1.0409396532426603e+31, 5.843584250700905e+31, 5.204698387105884e+32, 2.980227992035978e+33, 2.7064431922435605e+34, 1.5795207738820664e+35, 1.4614792891492016e+36, 8.687364216737284e+36, 8.184284399530709e+37]} diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py new file mode 100644 index 000000000000..08d4557e15c8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Generate fixtures.""" + +import os +import json +import numpy as np +from scipy.special import factorial2 + +# Get the file path: +FILE = os.path.realpath(__file__) + +# Extract the directory in which this file resides: +DIR = os.path.dirname(FILE) + + +def gen(x, name): + """Generate fixture data and write to file. + + # Arguments + + * `x`: domain + * `name::str`: output filename + + # Examples + + ``` python + python> x = linspace(-1000, 1000, 2001) + python> gen(x, './data.json') + ``` + """ + y = factorial2(x, exact=False) + + # Store data to be written to file as a dictionary: + data = { + "x": x.tolist(), + "expected": y.tolist() + } + + # Based on the script directory, create an output filepath: + filepath = os.path.join(DIR, name) + + # Write the data to the output filepath as JSON: + with open(filepath, "w", encoding="utf-8") as outfile: + json.dump(data, outfile) + + +def main(): + """Generate fixture data.""" + x = np.arange(1, 57, dtype=np.int32) + gen(x, "data.json") + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js index b601ec367f7d..df9776fe8d41 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js @@ -21,23 +21,25 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var incrspace = require( '@stdlib/array/base/incrspace' ); -var PINF = require( '@stdlib/constants/float64/pinf' ); -var NINF = require( '@stdlib/constants/float64/ninf' ); -var factorial2 = require( './../lib' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var factorial2f = require( './../lib' ); // FIXTURES // -var integers = require( './fixtures/integers.json' ); +var data = require( './fixtures/python/data.json' ); // TESTS // tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof factorial2, 'function', 'main export is a function' ); + t.strictEqual( typeof factorial2f, 'function', 'main export is a function' ); t.end(); }); @@ -48,52 +50,60 @@ tape( 'if provided a negative integer, the function returns `NaN`', function tes values = incrspace( -1.0, -1000.0, -25.0 ); for ( i = 0; i < values.length; i++ ) { - v = factorial2( values[ i ] ); - t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + values[ i ] ); + v = factorial2f( values[ i ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); } t.end(); }); tape( 'if provided negative infinity, the function returns `NaN`', function test( t ) { - var v = factorial2( NINF ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + var v = factorial2f( NINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'if provided positive infinity, the function returns `+infinity`', function test( t ) { - var v = factorial2( PINF ); + var v = factorial2f( PINF ); t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { - var v = factorial2( NaN ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + var v = factorial2f( NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function evaluates the double factorial', function test( t ) { var expected; + var delta; + var tol; var x; var v; var i; - x = integers.x; - expected = integers.expected; + x = data.x; + expected = data.expected; for ( i = 0; i < x.length; i++ ) { - v = factorial2( x[ i ] ); - t.strictEqual( v, expected[ i ], 'returns expected value when provided ' + x[ i ] ); + v = factorial2f( x[ i ] ); + if ( v === expected[ i ] ) { + t.strictEqual( v, expected[ i ], 'returns expected value' ); + } else { + delta = absf( v - expected[i] ); + tol = 1.0 * EPS * absf( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. v: '+v+'. e: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } } t.end(); }); -tape( 'if provided integers greater than `56`, the function returns positive infinity', function test( t ) { +tape( 'if provided data greater than `56`, the function returns positive infinity', function test( t ) { var i; var v; for ( i = 57; i < 100; i++ ) { - v = factorial2( i ); - t.strictEqual( v, PINF, 'returns expected value when provided ' + i ); + v = factorial2f( i ); + t.strictEqual( v, PINF, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js index 5243f037a31e..a5c4fbc08d88 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js @@ -23,14 +23,16 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var absf = require( '@stdlib/math/base/special/absf' ); var incrspace = require( '@stdlib/array/base/incrspace' ); var PINF = require( '@stdlib/constants/float32/pinf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); var tryRequire = require( '@stdlib/utils/try-require' ); // FIXTURES // -var integers = require( './fixtures/integers.json' ); +var data = require( './fixtures/python/data.json' ); // VARIABLES // @@ -57,33 +59,41 @@ tape( 'if provided a negative integer, the function returns `NaN`', opts, functi values = incrspace( -1.0, -1000.0, -25.0 ); for ( i = 0; i < values.length; i++ ) { v = factorial2f( values[ i ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value when provided ' + values[ i ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the double factorial', opts, function test( t ) { var expected; + var delta; + var tol; var x; var v; var i; - x = integers.x; - expected = integers.expected; + x = data.x; + expected = data.expected; for ( i = 0; i < x.length; i++ ) { v = factorial2f( x[ i ] ); - t.strictEqual( v, expected[ i ], 'returns expected value when provided ' + x[ i ] ); + if ( v === expected[ i ] ) { + t.strictEqual( v, expected[ i ], 'returns expected value' ); + } else { + delta = absf( v - expected[i] ); + tol = 2.4 * EPS * absf( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. v: '+v+'. e: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } } t.end(); }); -tape( 'if provided integers greater than `56`, the function returns `+infinity`', opts, function test( t ) { +tape( 'if provided data greater than `56`, the function returns positive infinity', opts, function test( t ) { var i; var v; for ( i = 57; i < 100; i++ ) { v = factorial2f( i ); - t.strictEqual( v, PINF, 'returns expected value when provided ' + i ); + t.strictEqual( v, PINF, 'returns expected value' ); } t.end(); }); From 1f5957bfbac3ef88b4d00fbac77132bc7b5caa0e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 19 Apr 2025 16:48:30 -0700 Subject: [PATCH 03/16] chore: update copyright years --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/README.md | 2 +- .../math/base/special/factorial2f/benchmark/c/native/Makefile | 2 +- .../@stdlib/math/base/special/factorial2f/binding.gyp | 2 +- .../@stdlib/math/base/special/factorial2f/examples/c/Makefile | 2 +- .../@stdlib/math/base/special/factorial2f/examples/index.js | 2 +- .../@stdlib/math/base/special/factorial2f/include.gypi | 2 +- .../factorial2f/include/stdlib/math/base/special/factorial2f.h | 2 +- .../@stdlib/math/base/special/factorial2f/lib/index.js | 2 +- .../@stdlib/math/base/special/factorial2f/lib/main.js | 2 +- .../@stdlib/math/base/special/factorial2f/lib/native.js | 2 +- .../@stdlib/math/base/special/factorial2f/src/Makefile | 2 +- .../@stdlib/math/base/special/factorial2f/src/addon.c | 2 +- .../@stdlib/math/base/special/factorial2f/test/test.js | 2 +- .../@stdlib/math/base/special/factorial2f/test/test.native.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md index ac21c38767f9..a85f6eccadbf 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2023 The Stdlib Authors. +Copyright (c) 2025 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/Makefile index f69e9da2b4d3..a4bd7b38fd74 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/benchmark/c/native/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp b/lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp index ec3992233442..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile index 6aed70daf167..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js index bff4fa4c77ca..3417202ea467 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi b/lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi index 575cb043c0bf..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/include/stdlib/math/base/special/factorial2f.h b/lib/node_modules/@stdlib/math/base/special/factorial2f/include/stdlib/math/base/special/factorial2f.h index 8771c30efe1e..1bfbb69a936c 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/include/stdlib/math/base/special/factorial2f.h +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/include/stdlib/math/base/special/factorial2f.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js index e8aa7c7ec9b9..d9b1a66648f5 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js index 6e9832b93c9d..54542b3496ce 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js index 11694617b46d..6c24b01a46bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile index bcf18aa46655..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c index f909faf513be..b2b2f522d3c3 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js index df9776fe8d41..fa293a01133b 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js index a5c4fbc08d88..90c4fffd5030 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 13b838b8433d897d979fe9ee47c01b0792645612 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 19 Apr 2025 16:54:35 -0700 Subject: [PATCH 04/16] docs: fix variable declaration --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md index a85f6eccadbf..9966b952667e 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md @@ -45,7 +45,7 @@ var factorial2f = require( '@stdlib/math/base/special/factorial2f' ); Evaluates the [double factorial][double-factorial] of `n` as a single-precision floating-point number. ```javascript -v = factorial2f( 3 ); +var v = factorial2f( 3 ); // returns 3 v = factorial2f( 4 ); From a4cbab595f4edbe76d93e60a627a40cd98c7468f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 19 Apr 2025 17:00:49 -0700 Subject: [PATCH 05/16] fix: convert the JS result to float32 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/lib/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js index 54542b3496ce..41eb74c11ee1 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -23,6 +23,7 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); var isEvenf = require( '@stdlib/math/base/assert/is-evenf' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float32/max-safe-nth-double-factorial' ); // eslint-disable-line id-length @@ -83,7 +84,7 @@ function factorial2f( n ) { for ( i = v|0; i >= last; i -= 2|0 ) { out *= i|0; // asm type annotation } - return out; + return float64ToFloat32( out ); } From c14397f7a2e89e78386c11786bbbb2b1c7e6bbb9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 20 Apr 2025 01:06:49 -0700 Subject: [PATCH 06/16] chore: apply suggestions from review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/README.md | 2 +- .../@stdlib/math/base/special/factorial2f/lib/index.js | 2 +- .../@stdlib/math/base/special/factorial2f/package.json | 2 +- .../@stdlib/math/base/special/factorial2f/src/main.c | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md index 9966b952667e..f936d65577d8 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md @@ -20,7 +20,7 @@ limitations under the License. # factorial2f -> Evaluate the [double factorial][double-factorial] function as a single-precision floating-point number. +> Evaluate the [double factorial][double-factorial] function for a single-precision floating-point number.
diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js index d9b1a66648f5..fbd17b68c7bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Evaluate the double factorial as a single-precision floating-point number. +* Evaluate the double factorial function for a single-precision floating-point number. * * @module @stdlib/math/base/special/factorial2f * diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json index a3ef951a9087..c6d3c374645c 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/factorial2f", "version": "0.0.0", - "description": "Evaluate the double factorial as a single-precision floating-point number.", + "description": "Evaluate the double factorial function for a single-precision floating-point number.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c index 0a42190d1f3f..c580a14cf0cc 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c @@ -36,7 +36,6 @@ */ float stdlib_base_factorial2f( const int32_t n ) { int32_t last; - int32_t v; int32_t i; float out; @@ -49,17 +48,16 @@ float stdlib_base_factorial2f( const int32_t n ) { if ( n < 0 || !stdlib_base_is_integerf( n ) ) { return 0.0f / 0.0f; // NaN } - v = n; - if ( v == 0 || v == 1 ) { + if ( n == 0 || n == 1 ) { return 1.0f; } - if ( stdlib_base_is_evenf( v ) ) { + if ( stdlib_base_is_evenf( n ) ) { last = 2; } else { last = 3; } out = 1.0f; - for ( i = v; i >= last; i -= 2 ) { + for ( i = n; i >= last; i -= 2 ) { out *= i; } return out; From 07f0a62c0afe19c847cb6b2039cae4c839e1e022 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 20 Apr 2025 01:16:14 -0700 Subject: [PATCH 07/16] test: remove the approx check in JS tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/factorial2f/test/test.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js index fa293a01133b..6442ba3ff70b 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js @@ -21,12 +21,10 @@ // MODULES // var tape = require( 'tape' ); -var absf = require( '@stdlib/math/base/special/absf' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var incrspace = require( '@stdlib/array/base/incrspace' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); -var EPS = require( '@stdlib/constants/float32/eps' ); var factorial2f = require( './../lib' ); @@ -76,8 +74,6 @@ tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { tape( 'the function evaluates the double factorial', function test( t ) { var expected; - var delta; - var tol; var x; var v; var i; @@ -87,13 +83,7 @@ tape( 'the function evaluates the double factorial', function test( t ) { for ( i = 0; i < x.length; i++ ) { v = factorial2f( x[ i ] ); - if ( v === expected[ i ] ) { - t.strictEqual( v, expected[ i ], 'returns expected value' ); - } else { - delta = absf( v - expected[i] ); - tol = 1.0 * EPS * absf( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. v: '+v+'. e: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( v, expected[ i ], 'returns expected value' ); } t.end(); }); From c539eacc2c1a598291ae7d6c0b6101936b0d37f9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 20 Apr 2025 01:47:46 -0700 Subject: [PATCH 08/16] fix: convert the accumulated result to float32 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/lib/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js index 41eb74c11ee1..32c78dfa4d8a 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -80,9 +80,10 @@ function factorial2f( n ) { } else { last = 3|0; // asm type annotation } - out = 1; + out = float64ToFloat32( 1 ); for ( i = v|0; i >= last; i -= 2|0 ) { out *= i|0; // asm type annotation + out = float64ToFloat32( out ); } return float64ToFloat32( out ); } From d442f2ea75d1db12829a6de6d47b3d703294dc38 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 20 Apr 2025 01:48:21 -0700 Subject: [PATCH 09/16] test: revert the changes to include approx tests in JS --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../factorial2f/test/fixtures/python/runner.py | 2 +- .../math/base/special/factorial2f/test/test.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py index 08d4557e15c8..60be06e89fa9 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/fixtures/python/runner.py @@ -45,7 +45,7 @@ def gen(x, name): python> gen(x, './data.json') ``` """ - y = factorial2(x, exact=False) + y = factorial2(x, exact=False).astype(np.float32) # Store data to be written to file as a dictionary: data = { diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js index 6442ba3ff70b..4a3dacaaf715 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js @@ -22,9 +22,11 @@ var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var absf = require( '@stdlib/math/base/special/absf' ); var incrspace = require( '@stdlib/array/base/incrspace' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); var factorial2f = require( './../lib' ); @@ -74,6 +76,8 @@ tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { tape( 'the function evaluates the double factorial', function test( t ) { var expected; + var delta; + var tol; var x; var v; var i; @@ -83,7 +87,13 @@ tape( 'the function evaluates the double factorial', function test( t ) { for ( i = 0; i < x.length; i++ ) { v = factorial2f( x[ i ] ); - t.strictEqual( v, expected[ i ], 'returns expected value' ); + if ( v === expected[ i ] ) { + t.strictEqual( v, expected[ i ], 'returns expected value' ); + } else { + delta = absf( v - expected[i] ); + tol = 2.4 * EPS * absf( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. v: '+v+'. e: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } } t.end(); }); From a4194ccd7fd8605b0751641385ba899e7fa0c363 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 22 Apr 2025 15:52:40 -0700 Subject: [PATCH 10/16] fix: correct imports to use `max-nth-double-factorial` constant --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/lib/main.js | 4 ++-- .../@stdlib/math/base/special/factorial2f/manifest.json | 6 +++--- .../@stdlib/math/base/special/factorial2f/src/main.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js index 32c78dfa4d8a..c86a802f2df4 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -25,7 +25,7 @@ var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); var isEvenf = require( '@stdlib/math/base/assert/is-evenf' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var PINF = require( '@stdlib/constants/float32/pinf' ); -var FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float32/max-safe-nth-double-factorial' ); // eslint-disable-line id-length +var FLOAT32_MAX_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float32/max-nth-double-factorial' ); // eslint-disable-line id-length // MAIN // @@ -65,7 +65,7 @@ function factorial2f( n ) { if ( isnanf( n ) ) { return NaN; } - if ( n > FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL ) { + if ( n > FLOAT32_MAX_NTH_DOUBLE_FACTORIAL ) { return PINF; } if ( n < 0 || isIntegerf( n ) === false ) { diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json index e6291b7850bc..3101aef99561 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json @@ -41,7 +41,7 @@ "@stdlib/math/base/assert/is-integerf", "@stdlib/math/base/assert/is-evenf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/max-safe-nth-double-factorial" + "@stdlib/constants/float32/max-nth-double-factorial" ] }, { @@ -59,7 +59,7 @@ "@stdlib/math/base/assert/is-integerf", "@stdlib/math/base/assert/is-evenf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/max-safe-nth-double-factorial" + "@stdlib/constants/float32/max-nth-double-factorial" ] }, { @@ -77,7 +77,7 @@ "@stdlib/math/base/assert/is-integerf", "@stdlib/math/base/assert/is-evenf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/max-safe-nth-double-factorial" + "@stdlib/constants/float32/max-nth-double-factorial" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c index c580a14cf0cc..0de0acfc1c02 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c @@ -21,7 +21,7 @@ #include "stdlib/math/base/assert/is_integerf.h" #include "stdlib/math/base/assert/is_evenf.h" #include "stdlib/constants/float32/pinf.h" -#include "stdlib/constants/float32/max_safe_nth_double_factorial.h" +#include "stdlib/constants/float32/max_nth_double_factorial.h" #include /** @@ -42,7 +42,7 @@ float stdlib_base_factorial2f( const int32_t n ) { if ( stdlib_base_is_nanf( n ) ) { return 0.0f / 0.0f; // NaN } - if ( n > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_DOUBLE_FACTORIAL ) { + if ( n > STDLIB_CONSTANT_FLOAT32_MAX_NTH_DOUBLE_FACTORIAL ) { return STDLIB_CONSTANT_FLOAT32_PINF; } if ( n < 0 || !stdlib_base_is_integerf( n ) ) { From 856cdbd621b2aada829aabddd459a9fcab323477 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 22 Apr 2025 18:53:48 -0700 Subject: [PATCH 11/16] docs: update desc Signed-off-by: Athan --- .../@stdlib/math/base/special/factorial2f/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md index f936d65577d8..9966b952667e 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/README.md @@ -20,7 +20,7 @@ limitations under the License. # factorial2f -> Evaluate the [double factorial][double-factorial] function for a single-precision floating-point number. +> Evaluate the [double factorial][double-factorial] function as a single-precision floating-point number.
From 0e78fa0e6257708a88a8bd0b639d2b7d71473722 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 22 Apr 2025 18:56:34 -0700 Subject: [PATCH 12/16] docs: update desc Signed-off-by: Athan --- .../@stdlib/math/base/special/factorial2f/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js index fbd17b68c7bf..749f4c17b0cf 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Evaluate the double factorial function for a single-precision floating-point number. +* Evaluate the double factorial function as a single-precision floating-point number. * * @module @stdlib/math/base/special/factorial2f * From 711080d61d0276b7195d0f6f2887a0bfbbe6078f Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 22 Apr 2025 18:56:57 -0700 Subject: [PATCH 13/16] docs: update desc Signed-off-by: Athan --- .../@stdlib/math/base/special/factorial2f/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json index c6d3c374645c..d0bb10defedb 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/factorial2f", "version": "0.0.0", - "description": "Evaluate the double factorial function for a single-precision floating-point number.", + "description": "Evaluate the double factorial function as a single-precision floating-point number.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 84eb0821347204615f91fa48c4a0792d0c5cbd96 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 22 Apr 2025 18:59:34 -0700 Subject: [PATCH 14/16] refactor: simplify expressions Signed-off-by: Athan --- .../@stdlib/math/base/special/factorial2f/lib/main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js index c86a802f2df4..df43a587c86e 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/lib/main.js @@ -82,10 +82,9 @@ function factorial2f( n ) { } out = float64ToFloat32( 1 ); for ( i = v|0; i >= last; i -= 2|0 ) { - out *= i|0; // asm type annotation - out = float64ToFloat32( out ); + out = float64ToFloat32( out * i ); } - return float64ToFloat32( out ); + return out; } From 7d24f69c5265edbfcfb6e593862163682a433c08 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 22 Apr 2025 19:41:26 -0700 Subject: [PATCH 15/16] fix: use correct imports and remove redundant checks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/factorial2f/manifest.json | 12 +++--------- .../@stdlib/math/base/special/factorial2f/src/main.c | 11 +++-------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json b/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json index 3101aef99561..e908a7d99888 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/manifest.json @@ -37,9 +37,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/unary", - "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/assert/is-integerf", - "@stdlib/math/base/assert/is-evenf", + "@stdlib/math/base/assert/int32-is-even", "@stdlib/constants/float32/pinf", "@stdlib/constants/float32/max-nth-double-factorial" ] @@ -55,9 +53,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/assert/is-integerf", - "@stdlib/math/base/assert/is-evenf", + "@stdlib/math/base/assert/int32-is-even", "@stdlib/constants/float32/pinf", "@stdlib/constants/float32/max-nth-double-factorial" ] @@ -73,9 +69,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/assert/is-integerf", - "@stdlib/math/base/assert/is-evenf", + "@stdlib/math/base/assert/int32-is-even", "@stdlib/constants/float32/pinf", "@stdlib/constants/float32/max-nth-double-factorial" ] diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c index 0de0acfc1c02..21420f00973e 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c @@ -17,9 +17,7 @@ */ #include "stdlib/math/base/special/factorial2f.h" -#include "stdlib/math/base/assert/is_nanf.h" -#include "stdlib/math/base/assert/is_integerf.h" -#include "stdlib/math/base/assert/is_evenf.h" +#include "stdlib/math/base/assert/int32_is_even.h" #include "stdlib/constants/float32/pinf.h" #include "stdlib/constants/float32/max_nth_double_factorial.h" #include @@ -39,19 +37,16 @@ float stdlib_base_factorial2f( const int32_t n ) { int32_t i; float out; - if ( stdlib_base_is_nanf( n ) ) { - return 0.0f / 0.0f; // NaN - } if ( n > STDLIB_CONSTANT_FLOAT32_MAX_NTH_DOUBLE_FACTORIAL ) { return STDLIB_CONSTANT_FLOAT32_PINF; } - if ( n < 0 || !stdlib_base_is_integerf( n ) ) { + if ( n < 0 ) { return 0.0f / 0.0f; // NaN } if ( n == 0 || n == 1 ) { return 1.0f; } - if ( stdlib_base_is_evenf( n ) ) { + if ( stdlib_base_int32_is_even( n ) ) { last = 2; } else { last = 3; From 1deff7c2a664797bf0a5c3d845ea43b8c064fc72 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 22 Apr 2025 21:13:29 -0700 Subject: [PATCH 16/16] test: add comment on the use of approximate equality --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/factorial2f/test/test.js | 2 ++ .../@stdlib/math/base/special/factorial2f/test/test.native.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js index 4a3dacaaf715..7a771934da50 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.js @@ -91,6 +91,8 @@ tape( 'the function evaluates the double factorial', function test( t ) { t.strictEqual( v, expected[ i ], 'returns expected value' ); } else { delta = absf( v - expected[i] ); + + // NOTE: We use approximate equality because expected values from SciPy are computed using gamma function approximations instead of iterative single-precision computation. tol = 2.4 * EPS * absf( expected[i] ); t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. v: '+v+'. e: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js index 90c4fffd5030..cf6cd8bdc4c5 100644 --- a/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/factorial2f/test/test.native.js @@ -81,6 +81,8 @@ tape( 'the function evaluates the double factorial', opts, function test( t ) { t.strictEqual( v, expected[ i ], 'returns expected value' ); } else { delta = absf( v - expected[i] ); + + // NOTE: We use approximate equality because expected values from SciPy are computed using gamma function approximations instead of iterative single-precision computation. tol = 2.4 * EPS * absf( expected[i] ); t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. v: '+v+'. e: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); }