Skip to content

Commit d8a20bb

Browse files
chore: use FLOAT64_MAX_SAFE_NTH_FACTORIAL
PR-URL: #6370 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 3bc9214 commit d8a20bb

File tree

1 file changed

+3
-7
lines changed
  • lib/node_modules/@stdlib/math/base/special/gammainc/lib

1 file changed

+3
-7
lines changed

lib/node_modules/@stdlib/math/base/special/gammainc/lib/main.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var FLOAT64_MAX = require( '@stdlib/constants/float64/max' );
4848
var SQRT_TWO_PI = require( '@stdlib/constants/float64/sqrt-two-pi' );
4949
var MAX_LN = require( '@stdlib/constants/float64/max-ln' );
5050
var PINF = require( '@stdlib/constants/float64/pinf' );
51+
var FLOAT64_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-factorial' ); // eslint-disable-line id-length
5152
var finiteGammaQ = require( './finite_gamma_q.js' );
5253
var finiteHalfGammaQ = require( './finite_half_gamma_q.js' );
5354
var fullIGammaPrefix = require( './full_igamma_prefix.js' );
@@ -58,19 +59,14 @@ var tgammaSmallUpperPart = require( './tgamma_small_upper_part.js' );
5859
var upperGammaFraction = require( './upper_gamma_fraction.js' );
5960

6061

61-
// VARIABLES //
62-
63-
var MAX_FACTORIAL = 170; // TODO: consider extracting as a constant
64-
65-
6662
// MAIN //
6763

6864
/**
6965
* Computes the regularized incomplete gamma function. The upper tail is calculated via the modified Lentz's method for computing continued fractions, the lower tail using a power expansion.
7066
*
7167
* ## Notes
7268
*
73-
* - When `a >= MAX_FACTORIAL` and computing the non-normalized incomplete gamma, result is rather hard to compute unless we use logs. There are really two options a) if `x` is a long way from `a` in value then we can reliably use methods 2 and 4 below in logarithmic form and go straight to the result. Otherwise we let the regularized gamma take the strain (the result is unlikely to underflow in the central region anyway) and combine with `lgamma` in the hopes that we get a finite result.
69+
* - When `a >= FLOAT64_MAX_SAFE_NTH_FACTORIAL` and computing the non-normalized incomplete gamma, result is rather hard to compute unless we use logs. There are really two options a) if `x` is a long way from `a` in value then we can reliably use methods 2 and 4 below in logarithmic form and go straight to the result. Otherwise we let the regularized gamma take the strain (the result is unlikely to underflow in the central region anyway) and combine with `lgamma` in the hopes that we get a finite result.
7470
*
7571
* @param {NonNegativeNumber} x - function parameter
7672
* @param {PositiveNumber} a - function parameter
@@ -101,7 +97,7 @@ function gammainc( x, a, regularized, upper ) {
10197
normalized = ( regularized === void 0 ) ? true : regularized;
10298
invert = upper;
10399
result = 0.0;
104-
if ( a >= MAX_FACTORIAL && !normalized ) {
100+
if ( a >= FLOAT64_MAX_SAFE_NTH_FACTORIAL && !normalized ) {
105101
if ( invert && ( a * 4.0 < x ) ) {
106102
// This is method 4 below, done in logs:
107103
result = ( a * ln(x) ) - x;

0 commit comments

Comments
 (0)