@stdlib/math-base-special-gammasgnf
v0.1.1
Published
Computes the sign of the gamma function for a single-precision floating-point number.
Readme
gammasgnf
Sign of the gamma function for a single-precision floating-point number.
The sign of the gamma-function is defined as
The gamma function can be computed as the product of gammasgn(x) and exp(gammaln(x)).
Installation
npm install @stdlib/math-base-special-gammasgnfUsage
var gammasgnf = require( '@stdlib/math-base-special-gammasgnf' );gammasgnf( x )
Computes the sign of the gamma function for a single-precision floating-point number.
var v = gammasgnf( 1.0 );
// returns 1.0
v = gammasgnf( -2.5 );
// returns -1.0
v = gammasgnf( 0.0 );
// returns 0.0
v = gammasgnf( NaN );
// returns NaNNotes
- The gamma function is not defined for negative integer values (i.e.,
gamma(x) === NaNwhenxis a negative integer). The natural logarithm of the gamma function is defined for negative integer values (i.e.,gammaln(x) === Infinitywhenxis a negative integer). Accordingly, in order for the equalitygamma(x) === gammasgn(x) * exp(gammaln(x))to hold (i.e., returnNaN),gammasgnneeds to either returnNaNor0. By convention, this function returns0.
Examples
var logEachMap = require( '@stdlib/console-log-each-map' );
var uniform = require( '@stdlib/random-array-uniform' );
var gammasgnf = require( '@stdlib/math-base-special-gammasgnf' );
var x = uniform( 100, -10.0, 10.0, {
'dtype': 'float32'
});
logEachMap( 'x: %0.4f, f(x): %0.4f', x, gammasgnf );C APIs
Usage
#include "stdlib/math/base/special/gammasgnf.h"stdlib_base_gammasgnf( x )
Computes the sign of the gamma function for a single-precision floating-point number.
float out = stdlib_base_gammasgnf( 1.0f );
// returns 1.0f
out = stdlib_base_gammasgnf( -2.5f );
// returns -1.0fThe function accepts the following arguments:
- x:
[in] floatinput value.
float stdlib_base_gammasgnf( const float x );Examples
#include "stdlib/math/base/special/gammasgnf.h"
#include <stdlib.h>
#include <stdio.h>
int main( void ) {
float x;
float v;
int i;
for ( i = 0; i < 100; i++ ) {
x = ( (float)rand() / (float)RAND_MAX ) * 100.0f;
v = stdlib_base_gammasgnf( x );
printf( "gammasgnf(%f) = %f\n", x, v );
}
}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.
