Skip to content

Latest commit

 

History

History
234 lines (143 loc) · 4.71 KB

File metadata and controls

234 lines (143 loc) · 4.71 KB

factorialf

Evaluate the Factorial function of a single-precision floating-point number.

The factorial function may be defined as the product

$$n! = \prod_{k=1}^n k$$

or according to the recurrence relation

$$n! = \begin{cases}1 & \textrm{if } n = 0,\\(n-1)! \times n & \textrm{if } n > 1\end{cases}$$

Following the convention for an empty product, in all definitions,

$$0! = 1$$

The Gamma function extends the factorial function for non-integer values.

$$n! = \Gamma(n+1)$$

The factorial of a negative integer is not defined.

Usage

var factorialf = require( '@stdlib/math/base/special/factorialf' );

factorialf( x )

Evaluates the factorial function of a single-precision floating-point number.

var v = factorialf( 3.0 );
// returns 6.0

v = factorialf( -1.5 );
// returns ~-3.545

v = factorialf( -0.5 );
// returns ~1.772

v = factorialf( 0.5 );
// returns ~0.886

v = factorialf( -10.0 );
// returns NaN

v = factorialf( 34.0 );
// returns ~2.952e38

v = factorialf( 35.0 );
// returns Infinity

v = factorialf( NaN );
// returns NaN

Examples

var incrspace = require( '@stdlib/array/base/incrspace' );
var factorialf = require( '@stdlib/math/base/special/factorialf' );

var x = incrspace( -10.0, 50.0, 1.0 );

var i;
for ( i = 0; i < x.length; i++ ) {
    console.log( 'x: %d, f(x): %d', x[ i ], factorialf( x[ i ] ) );
}

C APIs

Usage

#include "stdlib/math/base/special/factorialf.h"

stdlib_base_factorialf( x )

Evaluates the factorial function of a single-precision floating-point number.

float out = stdlib_base_factorialf( 3.0f );
// returns 6.0f

out = stdlib_base_factorialf( -1.5f );
// returns ~-3.545f

The function accepts the following arguments:

  • x: [in] float input value.
float stdlib_base_factorialf( const float x );

Examples

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

int main( void ) {
    const float x[] = { 2.0f, 3.0f, 5.0f, 8.0f };

    float y;
    int i;
    for ( i = 0; i < 4; i++ ) {
        y = stdlib_base_factorialf( x[ i ] );
        printf( "factorialf(%f) = %f\n", x[ i ], y );
    }
}

See Also