@stdlib/math-base-special-gamma-lanczos-sum-expg-scaledf
v0.1.1
Published
Calculate a scaled Lanczos sum for the approximation of the gamma function as a single precision floating-point number.
Readme
Gamma Scaled Lanczos Sum
Calculate a scaled Lanczos sum for the approximation of the gamma function as a single precision floating-point number.
The Lanczos approximation for the gamma function can be written in partial fraction form as follows:
where g is an arbitrary constant and L_g(n) is the Lanczos sum. The scaled Lanczos sum is given by
Installation
npm install @stdlib/math-base-special-gamma-lanczos-sum-expg-scaledfUsage
var gammaLanczosSumExpGScaledf = require( '@stdlib/math-base-special-gamma-lanczos-sum-expg-scaledf' );gammaLanczosSumExpGScaledf( x )
Calculates the Lanczos sum for the approximation of the gamma function (scaled by exp(-g), where g = 1.42845618724823) as a single precision floating-point number.
var v = gammaLanczosSumExpGScaledf( 4.0 );
// returns ~0.748
v = gammaLanczosSumExpGScaledf( -1.5 );
// returns ~0.193
v = gammaLanczosSumExpGScaledf( -0.5 );
// returns ~-0.558
v = gammaLanczosSumExpGScaledf( 0.5 );
// returns ~1.772
v = gammaLanczosSumExpGScaledf( 0.0 );
// returns Infinity
v = gammaLanczosSumExpGScaledf( NaN );
// returns NaNExamples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var gammaLanczosSumExpGScaledf = require( '@stdlib/math-base-special-gamma-lanczos-sum-expg-scaledf' );
var opts = {
'dtype': 'float32'
};
var x = uniform( 100, -10.0, 10.0, opts );
logEachMap( 'x: %0.4f, f(x): %0.4f', x, gammaLanczosSumExpGScaledf );C APIs
Usage
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h"stdlib_base_gamma_lanczos_sum_expg_scaledf( x )
Calculates the Lanczos sum for the approximation of the gamma function (scaled by exp(-g), where g = 1.42845618724823) as a single precision floating-point number.
float out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0f );
// returns ~0.748f
out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5f );
// returns ~0.193fThe function accepts the following arguments:
- x:
[in] floatinput value.
float stdlib_base_gamma_lanczos_sum_expg_scaledf( const float x );Examples
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f };
float y;
int i;
for ( i = 0; i < 4; i++ ) {
y = stdlib_base_gamma_lanczos_sum_expg_scaledf( x[ i ] );
printf( "gamma_lanczos_sum_expg_scaledf(%f) = %f\n", x[ i ], y );
}
}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
Copyright
Copyright © 2016-2026. The Stdlib Authors.
