Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Nov 17, 2023
1 parent 20001dc commit acddb72
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion base/special/factorial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
-->

# Factorial
# factorial

> [Factorial][factorial-function] function.
Expand Down
10 changes: 2 additions & 8 deletions base/special/factorial/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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' );
}
Expand All @@ -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' );
}
Expand Down
14 changes: 7 additions & 7 deletions base/special/factorial/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down
9 changes: 9 additions & 0 deletions base/special/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acddb72

Please sign in to comment.