Skip to content

Latest commit

 

History

History
216 lines (132 loc) · 4.33 KB

File metadata and controls

216 lines (132 loc) · 4.33 KB

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.

Usage

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 3840

If 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 Infinity

If not provided a nonnegative integer value, the function returns NaN.

var v = factorial2f( 3.14 );
// returns NaN

v = factorial2f( -1 );
// returns NaN

If provided NaN, the function returns NaN.

var v = factorial2f( NaN );
// returns NaN

Examples

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 );
// returns 3.0f

The function accepts the following arguments:

  • n: [in] int32_t input value.
float stdlib_base_factorial2f( const int32_t n );

Examples

#include "stdlib/math/base/special/factorial2f.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
    const int32_t x[] = { 1, 10, 50, 56, 57 };

    float b;
    int i;
    for ( i = 0; i < 5; i++ ) {
        b = stdlib_base_factorial2f( x[ i ] );
        printf ( "factorial2f(%d) = %f\n", x[ i ], b );
    }
}