@stdlib/math-base-special-factorial2f
v0.1.1
Published
Evaluate the double factorial function as a single-precision floating-point number.
Readme
factorial2f
Evaluate the double factorial function as a single-precision floating-point number.
The 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.
Installation
npm install @stdlib/math-base-special-factorial2fUsage
var factorial2f = require( '@stdlib/math-base-special-factorial2f' );factorial2f( n )
Evaluates the double factorial of n as a single-precision floating-point number.
var v = factorial2f( 3 );
// returns 3
v = factorial2f( 4 );
// returns 8
v = factorial2f( 10 );
// returns 3840If n > 56, the function returns NaN, as larger double factorial values cannot be safely represented in single-precision floating-point format.
var v = factorial2f( 57 );
// returns InfinityIf not provided a nonnegative integer value, the function returns NaN.
var v = factorial2f( 3.14 );
// returns NaN
v = factorial2f( -1 );
// returns NaNIf provided NaN, the function returns NaN.
var v = factorial2f( NaN );
// returns NaNExamples
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 x = discreteUniform( 10, 0, 56, {
'dtype': 'int32'
});
logEachMap( 'factorial2f(%d) = %0.1f', x, factorial2f );C APIs
Usage
#include "stdlib/math/base/special/factorial2f.h"stdlib_base_factorial2f( n )
Evaluates the double factorial of n as a single-precision floating-point number.
float out = stdlib_base_factorial2f( 3.0f );
// returns 3.0fThe function accepts the following arguments:
- n:
[in] floatinput value.
float stdlib_base_factorial2f( const float n );Examples
#include "stdlib/math/base/special/factorial2f.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 1.0f, 10.0f, 50.0f, 56.0f, 57.0f };
float b;
int i;
for ( i = 0; i < 5; i++ ) {
b = stdlib_base_factorial2f( x[ i ] );
printf ( "factorial2f(%f) = %f\n", x[ i ], b );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
