diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2/README.md b/lib/node_modules/@stdlib/math/base/special/factorial2/README.md new file mode 100644 index 000000000000..83a0d7bd00df --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/README.md @@ -0,0 +1,112 @@ + + +# 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 ] ) ); +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/factorial2/benchmark/benchmark.js new file mode 100644 index 000000000000..50e9d3a6916f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/benchmark/cpp/boost/Makefile b/lib/node_modules/@stdlib/math/base/special/factorial2/benchmark/cpp/boost/Makefile new file mode 100644 index 000000000000..a4c3c2c9bc0d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/benchmark/cpp/boost/benchmark.cpp b/lib/node_modules/@stdlib/math/base/special/factorial2/benchmark/cpp/boost/benchmark.cpp new file mode 100644 index 000000000000..f1c136873ebd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/benchmark/cpp/boost/benchmark.cpp @@ -0,0 +1,137 @@ +/** +* @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 Boost `double_factorial`. +*/ +#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/factorial2/benchmark/python/scipy/benchmark.py b/lib/node_modules/@stdlib/math/base/special/factorial2/benchmark/python/scipy/benchmark.py new file mode 100755 index 000000000000..7c7a672cb57d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/factorial2/docs/repl.txt new file mode 100644 index 000000000000..343a619d8f7b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/factorial2/docs/types/index.d.ts new file mode 100644 index 000000000000..f4fdc4abc1c7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/factorial2/docs/types/test.ts new file mode 100644 index 000000000000..b9e649dc57a0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/examples/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2/examples/index.js new file mode 100644 index 000000000000..4c6273deb3ce --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/lib/index.js b/lib/node_modules/@stdlib/math/base/special/factorial2/lib/index.js new file mode 100644 index 000000000000..b7ca6f105b97 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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. +* +* @module @stdlib/math/base/special/factorial2 +* +* @example +* var factorial2 = require( '@stdlib/math/base/special/factorial2' ); +* +* var v = factorial2( 3 ); +* // returns 3 +* +* v = factorial2( 4 ); +* // returns 8 +* +* v = factorial2( -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/factorial2/lib/main.js b/lib/node_modules/@stdlib/math/base/special/factorial2/lib/main.js new file mode 100644 index 000000000000..90771ddbff09 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/lib/main.js @@ -0,0 +1,91 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var isEven = require( '@stdlib/math/base/assert/is-even' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); + + +// VARIABLES // + +var MAX_FACTORIAL2 = 301; // TODO: consider extracting as a constant + + +// MAIN // + +/** +* Evaluates the double factorial of `n`. +* +* @param {number} n - input value +* @returns {(NonNegativeInteger|number)} double factorial +* +* @example +* var v = factorial2( 3 ); +* // returns 3 +* +* @example +* var v = factorial2( 4 ); +* // returns 8 +* +* @example +* var v = factorial2( 5 ); +* // returns 15 +* +* @example +* var v = factorial2( 301 ); +* // returns Infinity +*/ +function factorial2( n ) { + var last; + var out; + var v; + var i; + if ( isnan( n ) ) { + return NaN; + } + if ( n > MAX_FACTORIAL2 ) { + return PINF; + } + if ( n < 0 || isInteger( n ) === false ) { + return NaN; + } + v = n|0; // asm type annotation + if ( v === 0|0 || v === 1|0 ) { + return 1|0; // asm type annotation + } + if ( isEven( 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 = factorial2; diff --git a/lib/node_modules/@stdlib/math/base/special/factorial2/package.json b/lib/node_modules/@stdlib/math/base/special/factorial2/package.json new file mode 100644 index 000000000000..3dcbf7ba4f44 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/package.json @@ -0,0 +1,67 @@ +{ + "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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "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/factorial2/test/fixtures/integers.json b/lib/node_modules/@stdlib/math/base/special/factorial2/test/fixtures/integers.json new file mode 100644 index 000000000000..4fd06bac55ad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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/factorial2/test/test.js b/lib/node_modules/@stdlib/math/base/special/factorial2/test/test.js new file mode 100644 index 000000000000..6cae14a08035 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/factorial2/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(); +});