From acddb72c5a34c7cd20a681f6e75ddaff2b0c60d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 17 Nov 2023 01:41:44 +0000 Subject: [PATCH] Auto-generated commit --- base/special/factorial/README.md | 2 +- base/special/factorial/benchmark/benchmark.js | 10 ++-------- base/special/factorial/test/test.js | 14 +++++++------- base/special/lib/index.js | 9 +++++++++ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/base/special/factorial/README.md b/base/special/factorial/README.md index e9d74182a..df62c86b6 100644 --- a/base/special/factorial/README.md +++ b/base/special/factorial/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# Factorial +# factorial > [Factorial][factorial-function] function. diff --git a/base/special/factorial/benchmark/benchmark.js b/base/special/factorial/benchmark/benchmark.js index f62ef012d..7886b8ddd 100644 --- a/base/special/factorial/benchmark/benchmark.js +++ b/base/special/factorial/benchmark/benchmark.js @@ -21,8 +21,6 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var floor = require( './../../../../base/special/floor' ); var isnan = require( './../../../../base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var factorial = require( './../lib' ); @@ -31,14 +29,12 @@ var factorial = require( './../lib' ); // MAIN // bench( pkg+'::integers', function benchmark( b ) { - var x; var y; var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*171.0 ); - y = factorial( x ); + y = factorial( i%171 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -52,14 +48,12 @@ bench( pkg+'::integers', function benchmark( b ) { }); bench( pkg+'::decimals', function benchmark( b ) { - var x; var y; var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*171.0 ) - 0.0; - y = factorial( x ); + y = factorial( (i%171)*0.68163 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/base/special/factorial/test/test.js b/base/special/factorial/test/test.js index 23ddc4621..89dddcdd8 100644 --- a/base/special/factorial/test/test.js +++ b/base/special/factorial/test/test.js @@ -52,26 +52,26 @@ tape( 'if provided a negative integer, the function returns `NaN`', function tes values = incrspace( -1.0, -1000.0, -1.0 ); for ( i = 0; i < values.length; i++ ) { v = factorial( values[ i ] ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + 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 = factorial( NINF ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided negative infinity' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'if provided positive infinity, the function returns `+infinity`', function test( t ) { var v = factorial( PINF ); - t.strictEqual( v, PINF, 'returns +infinity when provided +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { var v = factorial( NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided a NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -83,7 +83,7 @@ tape( 'if `x > 170.6144...`, the function returns positive infinity', function t values = incrspace( 170.615, 1000.0, 10.1234 ); for ( i = 0; i < values.length; i++ ) { v = factorial( values[ i ] ); - t.strictEqual( v, PINF, 'returns +infinity when provided ' + values[ i ] ); + t.strictEqual( v, PINF, 'returns expected value when provided ' + values[ i ] ); } t.end(); }); @@ -96,7 +96,7 @@ tape( 'if `x < -171.56749...`, the function returns zero', function test( t ) { values = incrspace( -171.57, -1000.0, -10.1234 ); for ( i = 0; i < values.length; i++ ) { v = factorial( values[ i ] ); - t.strictEqual( v, 0.0, 'returns 0 when provided ' + values[ i ] ); + t.strictEqual( v, 0.0, 'returns expected value when provided ' + values[ i ] ); } t.end(); }); @@ -129,7 +129,7 @@ tape( 'if provided positive integers greater than `170`, the function returns po var v; for ( i = 171; i < 500; i++ ) { v = factorial( i ); - t.strictEqual( v, PINF, 'returns +infinity when provided ' + i ); + t.strictEqual( v, PINF, 'returns expected value when provided ' + i ); } t.end(); }); diff --git a/base/special/lib/index.js b/base/special/lib/index.js index 163ea18b2..edb881d6b 100644 --- a/base/special/lib/index.js +++ b/base/special/lib/index.js @@ -954,6 +954,15 @@ setReadOnly( special, 'expm1rel', require( './../../../base/special/expm1rel' ) */ setReadOnly( special, 'factorial', require( './../../../base/special/factorial' ) ); +/** +* @name factorial2 +* @memberof special +* @readonly +* @type {Function} +* @see {@link module:@stdlib/math/base/special/factorial2} +*/ +setReadOnly( special, 'factorial2', require( './../../../base/special/factorial2' ) ); + /** * @name factorialln * @memberof special