'use strict';

/*
* The code is adapted from the Fortran routine from [netlib]{@link http://www.netlib.no/netlib/fn/d9lgmc.f}.
*
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain software.
*/

// MODULES //

var pow = require( '@stdlib/math/base/special/pow' );
var dceval = require( './dceval.js' );


// CONSTANTS //

var ALGMCS = [
	+0.1666389480451863247205729650822e+0,
	-0.1384948176067563840732986059135e-4,
	+0.9810825646924729426157171547487e-8,
	-0.1809129475572494194263306266719e-10,
	+0.6221098041892605227126015543416e-13,
	-0.3399615005417721944303330599666e-15,
	+0.2683181998482698748957538846666e-17,
	-0.2868042435334643284144622399999e-19,
	+0.3962837061046434803679306666666e-21,
	-0.6831888753985766870111999999999e-23,
	+0.1429227355942498147573333333333e-24,
	-0.3547598158101070547199999999999e-26,
	+0.1025680058010470912000000000000e-27,
	-0.3401102254316748799999999999999e-29,
	+0.1276642195630062933333333333333e-30
];
var XBIG = 94906265.62425156;
var XMAX = 3.745194030963158e306;


// GAMMA CORRECTION //

/**
* Compute the log gamma correction factor for x >= 10 so that
*
* ``` tex
* \log(\gamma(x)) = \log(\sqrt{2*\Pi}) + (x-0.5) \cdot \log(x) - x \operatorname{R9LGMC}(x).
* ```
*
* @private
* @param {number} x - input value
* @returns {number} correction value
*/
function gamma_correction( x ) {
	if ( x < 10.0 ) {
		return NaN;
	}
	// Checking for underflow...
	if ( x >= XMAX ) {
		return 0.0;
	}
	if ( x < XBIG ) {
		return dceval( 2 * pow( 10.0 / x, 2 ) - 1, ALGMCS ) / x;
	}
	return 1.0 / (x * 12.0);
} // end FUNCTION gamma_correction()


// EXPORTS //

module.exports = gamma_correction;

'use strict';

/*
* The code is adapted from the Fortran routine from [netlib]{@link http://www.netlib.no/netlib/fn/d9lgmc.f}.
*
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain software.
*/

// MODULES //

var pow = require( '@stdlib/math/base/special/pow' );
var dceval = require( './dceval.js' );


// CONSTANTS //

var ALGMCS = [
	+0.1666389480451863247205729650822e+0,
	-0.1384948176067563840732986059135e-4,
	+0.9810825646924729426157171547487e-8,
	-0.1809129475572494194263306266719e-10,
	+0.6221098041892605227126015543416e-13,
	-0.3399615005417721944303330599666e-15,
	+0.2683181998482698748957538846666e-17,
	-0.2868042435334643284144622399999e-19,
	+0.3962837061046434803679306666666e-21,
	-0.6831888753985766870111999999999e-23,
	+0.1429227355942498147573333333333e-24,
	-0.3547598158101070547199999999999e-26,
	+0.1025680058010470912000000000000e-27,
	-0.3401102254316748799999999999999e-29,
	+0.1276642195630062933333333333333e-30
];
var XBIG = 94906265.62425156;
var XMAX = 3.745194030963158e306;


// GAMMA CORRECTION //

/**
* Compute the log gamma correction factor for x >= 10 so that
*
* ``` tex
* \log(\gamma(x)) = \log(\sqrt{2*\Pi}) + (x-0.5) \cdot \log(x) - x \operatorname{R9LGMC}(x).
* ```
*
* @private
* @param {number} x - input value
* @returns {number} correction value
*/
function gamma_correction( x ) {
	if ( x < 10.0 ) {
		return NaN;
	}
	// Checking for underflow...
	if ( x >= XMAX ) {
		return 0.0;
	}
	if ( x < XBIG ) {
		return dceval( 2.0 * pow( 10.0 / x, 2.0 ) - 1.0, ALGMCS ) / x;
	}
	return 1.0 / (x * 12.0);
} // end FUNCTION gamma_correction()


// EXPORTS //

module.exports = gamma_correction;

Add decimal points to make use of floating-point numbers explicit