UNPKG

@stdlib/math-base-special-gammaln

Version:

Natural logarithm of the gamma function.

8 lines (7 loc) 32.2 kB
{ "version": 3, "sources": ["../lib/polyval_a1.js", "../lib/polyval_a2.js", "../lib/polyval_r.js", "../lib/polyval_s.js", "../lib/polyval_t1.js", "../lib/polyval_t2.js", "../lib/polyval_t3.js", "../lib/polyval_u.js", "../lib/polyval_v.js", "../lib/polyval_w.js", "../lib/main.js", "../lib/index.js"], "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.06735230105312927;\n\t}\n\treturn 0.06735230105312927 + (x * (0.007385550860814029 + (x * (0.0011927076318336207 + (x * (0.00022086279071390839 + (x * 0.000025214456545125733))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.020580808432516733;\n\t}\n\treturn 0.020580808432516733 + (x * (0.0028905138367341563 + (x * (0.0005100697921535113 + (x * (0.00010801156724758394 + (x * 0.000044864094961891516))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 1.3920053346762105;\n\t}\n\treturn 1.3920053346762105 + (x * (0.7219355475671381 + (x * (0.17193386563280308 + (x * (0.01864591917156529 + (x * (0.0007779424963818936 + (x * 0.000007326684307446256))))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.21498241596060885;\n\t}\n\treturn 0.21498241596060885 + (x * (0.325778796408931 + (x * (0.14635047265246445 + (x * (0.02664227030336386 + (x * (0.0018402845140733772 + (x * 0.00003194753265841009))))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn -0.032788541075985965;\n\t}\n\treturn -0.032788541075985965 + (x * (0.006100538702462913 + (x * (-0.0014034646998923284 + (x * 0.00031563207090362595))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.01797067508118204;\n\t}\n\treturn 0.01797067508118204 + (x * (-0.0036845201678113826 + (x * (0.000881081882437654 + (x * -0.00031275416837512086))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn -0.010314224129834144;\n\t}\n\treturn -0.010314224129834144 + (x * (0.0022596478090061247 + (x * (-0.0005385953053567405 + (x * 0.0003355291926355191))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.6328270640250934;\n\t}\n\treturn 0.6328270640250934 + (x * (1.4549225013723477 + (x * (0.9777175279633727 + (x * (0.22896372806469245 + (x * 0.013381091853678766))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 2.4559779371304113;\n\t}\n\treturn 2.4559779371304113 + (x * (2.128489763798934 + (x * (0.7692851504566728 + (x * (0.10422264559336913 + (x * 0.003217092422824239))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.08333333333333297;\n\t}\n\treturn 0.08333333333333297 + (x * (-0.0027777777772877554 + (x * (0.0007936505586430196 + (x * (-0.00059518755745034 + (x * (0.0008363399189962821 + (x * -0.0016309293409657527))))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/e_lgamma_r.c}. The implementation follows the original, but has been modified for JavaScript.\n*\n* ```text\n* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar isInfinite = require( '@stdlib/math-base-assert-is-infinite' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar trunc = require( '@stdlib/math-base-special-trunc' );\nvar sinpi = require( '@stdlib/math-base-special-sinpi' );\nvar PI = require( '@stdlib/constants-float64-pi' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar polyvalA1 = require( './polyval_a1.js' );\nvar polyvalA2 = require( './polyval_a2.js' );\nvar polyvalR = require( './polyval_r.js' );\nvar polyvalS = require( './polyval_s.js' );\nvar polyvalT1 = require( './polyval_t1.js' );\nvar polyvalT2 = require( './polyval_t2.js' );\nvar polyvalT3 = require( './polyval_t3.js' );\nvar polyvalU = require( './polyval_u.js' );\nvar polyvalV = require( './polyval_v.js' );\nvar polyvalW = require( './polyval_w.js' );\n\n\n// VARIABLES //\n\nvar A1C = 7.72156649015328655494e-02; // 0x3FB3C467E37DB0C8\nvar A2C = 3.22467033424113591611e-01; // 0x3FD4A34CC4A60FAD\nvar RC = 1.0;\nvar SC = -7.72156649015328655494e-02; // 0xBFB3C467E37DB0C8\nvar T1C = 4.83836122723810047042e-01; // 0x3FDEF72BC8EE38A2\nvar T2C = -1.47587722994593911752e-01; // 0xBFC2E4278DC6C509\nvar T3C = 6.46249402391333854778e-02; // 0x3FB08B4294D5419B\nvar UC = -7.72156649015328655494e-02; // 0xBFB3C467E37DB0C8\nvar VC = 1.0;\nvar WC = 4.18938533204672725052e-01; // 0x3FDACFE390C97D69\nvar YMIN = 1.461632144968362245;\nvar TWO52 = 4503599627370496; // 2**52\nvar TWO58 = 288230376151711744; // 2**58\nvar TINY = 8.470329472543003e-22;\nvar TC = 1.46163214496836224576e+00; // 0x3FF762D86356BE3F\nvar TF = -1.21486290535849611461e-01; // 0xBFBF19B9BCC38A42\nvar TT = -3.63867699703950536541e-18; // 0xBC50C7CAA48A971F => TT = -(tail of TF)\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the gamma function.\n*\n* ## Method\n*\n* 1. Argument reduction for \\\\(0 < x \\leq 8\\\\). Since \\\\(\\Gamma(1+s) = s \\Gamma(s)\\\\), for \\\\(x \\in \\[0,8]\\\\), we may reduce \\\\(x\\\\) to a number in \\\\(\\[1.5,2.5]\\\\) by\n*\n* ```tex\n* \\operatorname{lgamma}(1+s) = \\ln(s) + \\operatorname{lgamma}(s)\n* ```\n*\n* For example,\n*\n* ```tex\n* \\begin{align*}\n* \\operatorname{lgamma}(7.3) &= \\ln(6.3) + \\operatorname{lgamma}(6.3) \\\\\n* &= \\ln(6.3 \\cdot 5.3) + \\operatorname{lgamma}(5.3) \\\\\n* &= \\ln(6.3 \\cdot 5.3 \\cdot 4.3 \\cdot 3.3 \\cdot2.3) + \\operatorname{lgamma}(2.3)\n* \\end{align*}\n* ```\n*\n* 2. Compute a polynomial approximation of \\\\(\\mathrm{lgamma}\\\\) around its minimum (\\\\(\\mathrm{ymin} = 1.461632144968362245\\\\)) to maintain monotonicity. On the interval \\\\(\\[\\mathrm{ymin} - 0.23, \\mathrm{ymin} + 0.27]\\\\) (i.e., \\\\(\\[1.23164,1.73163]\\\\)), we let \\\\(z = x - \\mathrm{ymin}\\\\) and use\n*\n* ```tex\n* \\operatorname{lgamma}(x) = -1.214862905358496078218 + z^2 \\cdot \\operatorname{poly}(z)\n* ```\n*\n* where \\\\(\\operatorname{poly}(z)\\\\) is a \\\\(14\\\\) degree polynomial.\n*\n* 3. Compute a rational approximation in the primary interval \\\\(\\[2,3]\\\\). Let \\\\( s = x - 2.0 \\\\). We can thus use the approximation\n*\n* ```tex\n* \\operatorname{lgamma}(x) = \\frac{s}{2} + s\\frac{\\operatorname{P}(s)}{\\operatorname{Q}(s)}\n* ```\n*\n* with accuracy\n*\n* ```tex\n* \\biggl|\\frac{\\mathrm{P}}{\\mathrm{Q}} - \\biggr(\\operatorname{lgamma}(x)-\\frac{s}{2}\\biggl)\\biggl| < 2^{-61.71}\n* ```\n*\n* The algorithms are based on the observation\n*\n* ```tex\n* \\operatorname{lgamma}(2+s) = s(1 - \\gamma) + \\frac{\\zeta(2) - 1}{2} s^2 - \\frac{\\zeta(3) - 1}{3} s^3 + \\ldots\n* ```\n*\n* where \\\\(\\zeta\\\\) is the zeta function and \\\\(\\gamma = 0.5772156649...\\\\) is the Euler-Mascheroni constant, which is very close to \\\\(0.5\\\\).\n*\n* 4. For \\\\(x \\geq 8\\\\),\n*\n* ```tex\n* \\operatorname{lgamma}(x) \\approx \\biggl(x-\\frac{1}{2}\\biggr) \\ln(x) - x + \\frac{\\ln(2\\pi)}{2} + \\frac{1}{12x} - \\frac{1}{360x^3} + \\ldots\n* ```\n*\n* which can be expressed\n*\n* ```tex\n* \\operatorname{lgamma}(x) \\approx \\biggl(x-\\frac{1}{2}\\biggr)(\\ln(x)-1)-\\frac{\\ln(2\\pi)-1}{2} + \\ldots\n* ```\n*\n* Let \\\\(z = \\frac{1}{x}\\\\). We can then use the approximation\n*\n* ```tex\n* f(z) = \\operatorname{lgamma}(x) - \\biggl(x-\\frac{1}{2}\\biggr)(\\ln(x)-1)\n* ```\n*\n* by\n*\n* ```tex\n* w = w_0 + w_1 z + w_2 z^3 + w_3 z^5 + \\ldots + w_6 z^{11}\n* ```\n*\n* where\n*\n* ```tex\n* |w - f(z)| < 2^{-58.74}\n* ```\n*\n* 5. For negative \\\\(x\\\\), since\n*\n* ```tex\n* -x \\Gamma(-x) \\Gamma(x) = \\frac{\\pi}{\\sin(\\pi x)}\n* ```\n*\n* where \\\\(\\Gamma\\\\) is the gamma function, we have\n*\n* ```tex\n* \\Gamma(x) = \\frac{\\pi}{\\sin(\\pi x)(-x)\\Gamma(-x)}\n* ```\n*\n* Since \\\\(\\Gamma(-x)\\\\) is positive,\n*\n* ```tex\n* \\operatorname{sign}(\\Gamma(x)) = \\operatorname{sign}(\\sin(\\pi x))\n* ```\n*\n* for \\\\(x < 0\\\\). Hence, for \\\\(x < 0\\\\),\n*\n* ```tex\n* \\mathrm{signgam} = \\operatorname{sign}(\\sin(\\pi x))\n* ```\n*\n* and\n*\n* ```tex\n* \\begin{align*}\n* \\operatorname{lgamma}(x) &= \\ln(|\\Gamma(x)|) \\\\\n* &= \\ln\\biggl(\\frac{\\pi}{|x \\sin(\\pi x)|}\\biggr) - \\operatorname{lgamma}(-x)\n* \\end{align*}\n* ```\n*\n* <!-- <note> -->\n*\n* Note that one should avoid computing \\\\(\\pi (-x)\\\\) directly in the computation of \\\\(\\sin(\\pi (-x))\\\\).\n*\n* <!-- </note> -->\n*\n* ## Special Cases\n*\n* ```tex\n* \\begin{align*}\n* \\operatorname{lgamma}(2+s) &\\approx s (1-\\gamma) & \\mathrm{for\\ tiny\\ s} \\\\\n* \\operatorname{lgamma}(x) &\\approx -\\ln(x) & \\mathrm{for\\ tiny\\ x} \\\\\n* \\operatorname{lgamma}(1) &= 0 & \\\\\n* \\operatorname{lgamma}(2) &= 0 & \\\\\n* \\operatorname{lgamma}(0) &= \\infty & \\\\\n* \\operatorname{lgamma}(\\infty) &= \\infty & \\\\\n* \\operatorname{lgamma}(-\\mathrm{integer}) &= \\pm \\infty\n* \\end{align*}\n* ```\n*\n* @param {number} x - input value\n* @returns {number} function value\n*\n* @example\n* var v = gammaln( 1.0 );\n* // returns 0.0\n*\n* @example\n* var v = gammaln( 2.0 );\n* // returns 0.0\n*\n* @example\n* var v = gammaln( 4.0 );\n* // returns ~1.792\n*\n* @example\n* var v = gammaln( -0.5 );\n* // returns ~1.266\n*\n* @example\n* var v = gammaln( 0.5 );\n* // returns ~0.572\n*\n* @example\n* var v = gammaln( 0.0 );\n* // returns Infinity\n*\n* @example\n* var v = gammaln( NaN );\n* // returns NaN\n*/\nfunction gammaln( x ) {\n\tvar isNegative;\n\tvar nadj;\n\tvar flg;\n\tvar p3;\n\tvar p2;\n\tvar p1;\n\tvar p;\n\tvar q;\n\tvar t;\n\tvar w;\n\tvar y;\n\tvar z;\n\tvar r;\n\n\t// Special cases: NaN, +-infinity\n\tif ( isnan( x ) || isInfinite( x ) ) {\n\t\treturn x;\n\t}\n\t// Special case: 0\n\tif ( x === 0.0 ) {\n\t\treturn PINF;\n\t}\n\tif ( x < 0.0 ) {\n\t\tisNegative = true;\n\t\tx = -x;\n\t} else {\n\t\tisNegative = false;\n\t}\n\t// If |x| < 2**-70, return -ln(|x|)\n\tif ( x < TINY ) {\n\t\treturn -ln( x );\n\t}\n\tif ( isNegative ) {\n\t\t// If |x| >= 2**52, must be -integer\n\t\tif ( x >= TWO52 ) {\n\t\t\treturn PINF;\n\t\t}\n\t\tt = sinpi( x );\n\t\tif ( t === 0.0 ) {\n\t\t\treturn PINF;\n\t\t}\n\t\tnadj = ln( PI / abs( t*x ) );\n\t}\n\t// If x equals 1 or 2, return 0\n\tif ( x === 1.0 || x === 2.0 ) {\n\t\treturn 0.0;\n\t}\n\t// If x < 2, use lgamma(x) = lgamma(x+1) - log(x)\n\tif ( x < 2.0 ) {\n\t\tif ( x <= 0.9 ) {\n\t\t\tr = -ln( x );\n\n\t\t\t// 0.7316 <= x <= 0.9\n\t\t\tif ( x >= ( YMIN - 1.0 + 0.27 ) ) {\n\t\t\t\ty = 1.0 - x;\n\t\t\t\tflg = 0;\n\t\t\t}\n\t\t\t// 0.2316 <= x < 0.7316\n\t\t\telse if ( x >= (YMIN - 1.0 - 0.27) ) {\n\t\t\t\ty = x - (TC - 1.0);\n\t\t\t\tflg = 1;\n\t\t\t}\n\t\t\t// 0 < x < 0.2316\n\t\t\telse {\n\t\t\t\ty = x;\n\t\t\t\tflg = 2;\n\t\t\t}\n\t\t} else {\n\t\t\tr = 0.0;\n\n\t\t\t// 1.7316 <= x < 2\n\t\t\tif ( x >= (YMIN + 0.27) ) {\n\t\t\t\ty = 2.0 - x;\n\t\t\t\tflg = 0;\n\t\t\t}\n\t\t\t// 1.2316 <= x < 1.7316\n\t\t\telse if ( x >= (YMIN - 0.27) ) {\n\t\t\t\ty = x - TC;\n\t\t\t\tflg = 1;\n\t\t\t}\n\t\t\t// 0.9 < x < 1.2316\n\t\t\telse {\n\t\t\t\ty = x - 1.0;\n\t\t\t\tflg = 2;\n\t\t\t}\n\t\t}\n\t\tswitch ( flg ) { // eslint-disable-line default-case\n\t\tcase 0:\n\t\t\tz = y * y;\n\t\t\tp1 = A1C + (z*polyvalA1( z ));\n\t\t\tp2 = z * (A2C + (z*polyvalA2( z )));\n\t\t\tp = (y*p1) + p2;\n\t\t\tr += ( p - (0.5*y) );\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tz = y * y;\n\t\t\tw = z * y;\n\t\t\tp1 = T1C + (w*polyvalT1( w ));\n\t\t\tp2 = T2C + (w*polyvalT2( w ));\n\t\t\tp3 = T3C + (w*polyvalT3( w ));\n\t\t\tp = (z*p1) - (TT - (w*(p2+(y*p3))));\n\t\t\tr += ( TF + p );\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tp1 = y * (UC + (y*polyvalU( y )));\n\t\t\tp2 = VC + (y*polyvalV( y ));\n\t\t\tr += (-0.5*y) + (p1/p2);\n\t\t\tbreak;\n\t\t}\n\t}\n\t// 2 <= x < 8\n\telse if ( x < 8.0 ) {\n\t\tflg = trunc( x );\n\t\ty = x - flg;\n\t\tp = y * (SC + (y*polyvalS( y )));\n\t\tq = RC + (y*polyvalR( y ));\n\t\tr = (0.5*y) + (p/q);\n\t\tz = 1.0; // gammaln(1+s) = ln(s) + gammaln(s)\n\t\tswitch ( flg ) { // eslint-disable-line default-case\n\t\tcase 7:\n\t\t\tz *= y + 6.0;\n\n\t\t\t/* Falls through */\n\t\tcase 6:\n\t\t\tz *= y + 5.0;\n\n\t\t\t/* Falls through */\n\t\tcase 5:\n\t\t\tz *= y + 4.0;\n\n\t\t\t/* Falls through */\n\t\tcase 4:\n\t\t\tz *= y + 3.0;\n\n\t\t\t/* Falls through */\n\t\tcase 3:\n\t\t\tz *= y + 2.0;\n\t\t\tr += ln( z );\n\t\t}\n\t}\n\t// 8 <= x < 2**58\n\telse if ( x < TWO58 ) {\n\t\tt = ln( x );\n\t\tz = 1.0 / x;\n\t\ty = z * z;\n\t\tw = WC + (z*polyvalW( y ));\n\t\tr = ((x-0.5)*(t-1.0)) + w;\n\t}\n\t// 2**58 <= x <= Inf\n\telse {\n\t\tr = x * ( ln(x)-1.0 );\n\t}\n\tif ( isNegative ) {\n\t\tr = nadj - r;\n\t}\n\treturn r;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gammaln;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Evaluate the natural logarithm of the gamma function.\n*\n* @module @stdlib/math-base-special-gammaln\n*\n* @example\n* var gammaln = require( '@stdlib/math-base-special-gammaln' );\n*\n* var v = gammaln( 1.0 );\n* // returns 0.0\n*\n* v = gammaln( 2.0 );\n* // returns 0.0\n*\n* v = gammaln( 4.0 );\n* // returns ~1.792\n*\n* v = gammaln( -0.5 );\n* // returns ~1.266\n*\n* v = gammaln( 0.5 );\n* // returns ~0.572\n*\n* v = gammaln( 0.0 );\n* // returns Infinity\n*\n* v = gammaln( NaN );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAoCA,SAASC,EAAUC,EAAI,CACtB,OAAKA,IAAM,EACH,mBAED,mBAAuBA,GAAK,oBAAwBA,GAAK,qBAAyBA,GAAK,sBAA0BA,EAAI,wBAC7H,CAKAF,EAAO,QAAUC,IC9CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAoCA,SAASC,EAAUC,EAAI,CACtB,OAAKA,IAAM,EACH,oBAED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MACD,IAAK,GACJD,EAAKK,GAAKtB,GAAMsB,EAAEhC,GAAUgC,CAAE,GAC9BN,EAAKf,GAAMqB,EAAE/B,GAAU+B,CAAE,EACzBE,GAAM,IAAKF,EAAML,EAAGD,EACpB,KACD,SAGSL,EAAI,EAOb,OANAG,EAAMnC,GAAOgC,CAAE,EACfW,EAAIX,EAAIG,EACRI,EAAII,GAAK1B,GAAM0B,EAAEpC,GAAUoC,CAAE,GAC7BH,EAAIxB,GAAM2B,EAAErC,GAAUqC,CAAE,EACxBE,EAAK,GAAIF,EAAMJ,EAAEC,EACjBI,EAAI,EACKT,EAAM,CACf,IAAK,GACJS,GAAKD,EAAI,EAGV,IAAK,GACJC,GAAKD,EAAI,EAGV,IAAK,GACJC,GAAKD,EAAI,EAGV,IAAK,GACJC,GAAKD,EAAI,EAGV,IAAK,GACJC,GAAKD,EAAI,EACTE,GAAK9C,EAAI6C,CAAE,CACZ,MAGSZ,EAAIN,IACbe,EAAI1C,EAAIiC,CAAE,EACVY,EAAI,EAAMZ,EACVW,EAAIC,EAAIA,EACRF,EAAInB,GAAMqB,EAAE/B,GAAU8B,CAAE,EACxBE,GAAMb,EAAE,KAAMS,EAAE,GAAQC,GAIxBG,EAAIb,GAAMjC,EAAGiC,CAAC,EAAE,GAEjB,OAAKC,IACJY,EAAIX,EAAOW,GAELA,CACR,CAKAlD,EAAO,QAAUoC,KChWjB,IAAIe,GAAO,IAKX,OAAO,QAAUA", "names": ["require_polyval_a1", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_a2", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_r", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_s", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_t1", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_t2", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_t3", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_u", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_v", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_polyval_w", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_main", "__commonJSMin", "exports", "module", "isnan", "isInfinite", "abs", "ln", "trunc", "sinpi", "PI", "PINF", "polyvalA1", "polyvalA2", "polyvalR", "polyvalS", "polyvalT1", "polyvalT2", "polyvalT3", "polyvalU", "polyvalV", "polyvalW", "A1C", "A2C", "RC", "SC", "T1C", "T2C", "T3C", "UC", "VC", "WC", "YMIN", "TWO52", "TWO58", "TINY", "TC", "TF", "TT", "gammaln", "x", "isNegative", "nadj", "flg", "p3", "p2", "p1", "p", "q", "t", "w", "y", "z", "r", "main"] }