@stdlib/math-base-special-betaln 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/NOTICE +1 -1
- package/README.md +93 -6
- package/dist/index.js.map +1 -1
- package/include/stdlib/math/base/special/betaln.h +38 -0
- package/lib/dceval.js +2 -2
- package/lib/gamma_correction.js +2 -2
- package/lib/main.js +2 -2
- package/lib/native.js +67 -0
- package/manifest.json +99 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +160 -0
package/LICENSE
CHANGED
|
@@ -182,6 +182,6 @@ The library links against the following external libraries or contains
|
|
|
182
182
|
implementations from the following external libraries, which have their own
|
|
183
183
|
licenses:
|
|
184
184
|
|
|
185
|
-
* SLATEC Common Mathematical Library <
|
|
185
|
+
* SLATEC Common Mathematical Library <https://netlib.org/slatec/>
|
|
186
186
|
|
|
187
187
|
Public domain.
|
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ var betaln = require( '@stdlib/math-base-special-betaln' );
|
|
|
83
83
|
|
|
84
84
|
#### betaln( x, y )
|
|
85
85
|
|
|
86
|
-
Evaluates the
|
|
86
|
+
Evaluates the [natural logarithm][natural-logarithm] of the [beta function][beta-function].
|
|
87
87
|
|
|
88
88
|
```javascript
|
|
89
89
|
var val = betaln( 0.0, 0.0 );
|
|
@@ -128,6 +128,93 @@ for ( x = 0; x < 10; x++ ) {
|
|
|
128
128
|
|
|
129
129
|
<!-- /.examples -->
|
|
130
130
|
|
|
131
|
+
<!-- C interface documentation. -->
|
|
132
|
+
|
|
133
|
+
* * *
|
|
134
|
+
|
|
135
|
+
<section class="c">
|
|
136
|
+
|
|
137
|
+
## C APIs
|
|
138
|
+
|
|
139
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
140
|
+
|
|
141
|
+
<section class="intro">
|
|
142
|
+
|
|
143
|
+
</section>
|
|
144
|
+
|
|
145
|
+
<!-- /.intro -->
|
|
146
|
+
|
|
147
|
+
<!-- C usage documentation. -->
|
|
148
|
+
|
|
149
|
+
<section class="usage">
|
|
150
|
+
|
|
151
|
+
### Usage
|
|
152
|
+
|
|
153
|
+
```c
|
|
154
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### stdlib_base_betaln( x, y )
|
|
158
|
+
|
|
159
|
+
Evaluates the [natural logarithm][natural-logarithm] of the [beta function][beta-function].
|
|
160
|
+
|
|
161
|
+
```c
|
|
162
|
+
double v = stdlib_base_betaln( 5.0, 0.2 );
|
|
163
|
+
// returns ~1.218
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The function accepts the following arguments:
|
|
167
|
+
|
|
168
|
+
- **x**: `[in] double` input value.
|
|
169
|
+
- **y**: `[in] double` input value.
|
|
170
|
+
|
|
171
|
+
```c
|
|
172
|
+
double stdlib_base_betaln( const double x, const double y );
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
</section>
|
|
176
|
+
|
|
177
|
+
<!-- /.usage -->
|
|
178
|
+
|
|
179
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
180
|
+
|
|
181
|
+
<section class="notes">
|
|
182
|
+
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<!-- /.notes -->
|
|
186
|
+
|
|
187
|
+
<!-- C API usage examples. -->
|
|
188
|
+
|
|
189
|
+
<section class="examples">
|
|
190
|
+
|
|
191
|
+
### Examples
|
|
192
|
+
|
|
193
|
+
```c
|
|
194
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
195
|
+
#include <stdio.h>
|
|
196
|
+
|
|
197
|
+
int main( void ) {
|
|
198
|
+
const double x[] = { 24.0, 32.0, 48.0, 116.0, 33.0 };
|
|
199
|
+
const double y[] = { 12.0, 6.0, 15.0, 52.0, 22.0 };
|
|
200
|
+
|
|
201
|
+
double out;
|
|
202
|
+
int i;
|
|
203
|
+
for ( i = 0; i < 5; i++ ) {
|
|
204
|
+
out = stdlib_base_betaln( x[ i ], y[ i ] );
|
|
205
|
+
printf( "betaln(%lf, %lf) = %lf\n", x[ i ], y[ i ], out );
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
</section>
|
|
211
|
+
|
|
212
|
+
<!-- /.examples -->
|
|
213
|
+
|
|
214
|
+
</section>
|
|
215
|
+
|
|
216
|
+
<!-- /.c -->
|
|
217
|
+
|
|
131
218
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
132
219
|
|
|
133
220
|
<section class="related">
|
|
@@ -165,7 +252,7 @@ For more information on the project, filing bug reports and feature requests, an
|
|
|
165
252
|
|
|
166
253
|
## Copyright
|
|
167
254
|
|
|
168
|
-
Copyright © 2016-
|
|
255
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
169
256
|
|
|
170
257
|
</section>
|
|
171
258
|
|
|
@@ -178,8 +265,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
178
265
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-betaln.svg
|
|
179
266
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-betaln
|
|
180
267
|
|
|
181
|
-
[test-image]: https://github.com/stdlib-js/math-base-special-betaln/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
182
|
-
[test-url]: https://github.com/stdlib-js/math-base-special-betaln/actions/workflows/test.yml?query=branch:v0.
|
|
268
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-betaln/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
269
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-betaln/actions/workflows/test.yml?query=branch:v0.3.0
|
|
183
270
|
|
|
184
271
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-betaln/main.svg
|
|
185
272
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-betaln?branch=main
|
|
@@ -191,8 +278,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
191
278
|
|
|
192
279
|
-->
|
|
193
280
|
|
|
194
|
-
[chat-image]: https://img.shields.io/
|
|
195
|
-
[chat-url]: https://
|
|
281
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
282
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
196
283
|
|
|
197
284
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
198
285
|
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/dceval.js", "../lib/gamma_correction.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\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 code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link
|
|
4
|
+
"sourcesContent": ["/**\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 code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://netlib.org/slatec/fnlib/dcsevl.f}.\n*\n* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar ALGMCS = [\n\t+0.1276642195630062933333333333333e-30,\n\t-0.3401102254316748799999999999999e-29,\n\t+0.1025680058010470912000000000000e-27,\n\t-0.3547598158101070547199999999999e-26,\n\t+0.1429227355942498147573333333333e-24,\n\t-0.6831888753985766870111999999999e-23,\n\t+0.3962837061046434803679306666666e-21,\n\t-0.2868042435334643284144622399999e-19,\n\t+0.2683181998482698748957538846666e-17,\n\t-0.3399615005417721944303330599666e-15,\n\t+0.6221098041892605227126015543416e-13,\n\t-0.1809129475572494194263306266719e-10,\n\t+0.9810825646924729426157171547487e-8,\n\t-0.1384948176067563840732986059135e-4,\n\t+0.1666389480451863247205729650822e+0\n];\nvar LEN = ALGMCS.length;\n\n\n// MAIN //\n\n/**\n* Evaluates the n-term Chebyshev series at `x`.\n*\n* ## References\n*\n* - Broucke, Roger. 1973. \"Algorithm: Ten Subroutines for the Manipulation of Chebyshev Series.\" _Communications of the ACM_ 16 (4). New York, NY, USA: ACM: 254\u201356. doi:[10.1145/362003.362037](https://doi.org/10.1145/362003.362037).\n* - Fox, Leslie, and Ian Bax Parker. 1968. _Chebyshev polynomials in numerical analysis_. Oxford Mathematical Handbooks. London, United Kingdom: Oxford University Press. <https://books.google.com/books?id=F8NzsEtJCD0C>.\n*\n* @private\n* @param {number} x - value at which the series is to be evaluated\n* @returns {number} series value\n*/\nfunction dcseval( x ) {\n\tvar twox;\n\tvar b2;\n\tvar b1;\n\tvar b0;\n\tvar i;\n\n\tif ( x < -1.1 || x > 1.1 ) {\n\t\treturn NaN;\n\t}\n\tb1 = 0.0;\n\tb0 = 0.0;\n\ttwox = 2.0 * x;\n\tfor ( i = 0; i < LEN; i++ ) {\n\t\tb2 = b1;\n\t\tb1 = b0;\n\t\tb0 = (twox*b1) - b2 + ALGMCS[ i ];\n\t}\n\treturn ( b0-b2 ) * 0.5;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dcseval;\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 code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://netlib.org/fn/d9lgmc.f}.\n*\n* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar dceval = require( './dceval.js' );\n\n\n// VARIABLES //\n\nvar XBIG = 94906265.62425156;\nvar XMAX = 3.745194030963158e306;\n\n\n// MAIN //\n\n/**\n* Computes the log gamma correction factor for `x >= 10`.\n*\n* ```tex\n* \\log(\\gamma(x)) = \\log(\\sqrt{2*\\Pi}) + (x-0.5) \\cdot \\log(x) - x \\operatorname{R9LGMC}(x).\n* ```\n*\n* @private\n* @param {number} x - input value\n* @returns {number} correction value\n*/\nfunction gammaCorrection( x ) {\n\tif ( x < 10.0 ) {\n\t\treturn NaN;\n\t}\n\t// Check for underflow...\n\tif ( x >= XMAX ) {\n\t\treturn 0.0;\n\t}\n\tif ( x < XBIG ) {\n\t\treturn dceval( (2.0*pow( 10.0/x, 2.0 )) - 1.0 ) / x;\n\t}\n\treturn 1.0 / (x * 12.0);\n}\n\n\n// EXPORTS //\n\nmodule.exports = gammaCorrection;\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 code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://www.netlib.org/slatec/fnlib/albeta.f}.\n*\n* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar gammaln = require( '@stdlib/math-base-special-gammaln' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar gamma = require( '@stdlib/math-base-special-gamma' );\nvar max = require( '@stdlib/math-base-special-max' );\nvar min = require( '@stdlib/math-base-special-min' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LN_SQRT_TWO_PI = require( '@stdlib/constants-float64-ln-sqrt-two-pi' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar correction = require( './gamma_correction.js' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the beta function.\n*\n* @param {NonNegativeNumber} a - first input value\n* @param {NonNegativeNumber} b - second input value\n* @returns {number} natural logarithm of beta function\n*\n* @example\n* var v = betaln( 0.0, 0.0 );\n* // returns Infinity\n*\n* @example\n* var v = betaln( 1.0, 1.0 );\n* // returns 0.0\n*\n* @example\n* var v = betaln( -1.0, 2.0 );\n* // returns NaN\n*\n* @example\n* var v = betaln( 5.0, 0.2 );\n* // returns ~1.218\n*\n* @example\n* var v = betaln( 4.0, 1.0 );\n* // returns ~-1.386\n*\n* @example\n* var v = betaln( NaN, 2.0 );\n* // returns NaN\n*/\nfunction betaln( a, b ) {\n\tvar corr;\n\tvar p;\n\tvar q;\n\n\tp = min( a, b );\n\tq = max( a, b );\n\n\tif ( p < 0.0 ) {\n\t\treturn NaN;\n\t}\n\tif ( p === 0.0 ) {\n\t\treturn PINF;\n\t}\n\tif ( q === PINF ) {\n\t\treturn NINF;\n\t}\n\t// Case: p and q are big\n\tif ( p >= 10.0 ) {\n\t\tcorr = correction( p ) + correction( q ) - correction( p+q );\n\t\treturn ( -0.5*ln( q ) ) + LN_SQRT_TWO_PI + corr + ( (p-0.5) * ln( p/(p+q) ) ) + ( q*log1p( -p/(p+q) ) ); // eslint-disable-line max-len\n\t}\n\t// Case: p is small, but q is big\n\tif ( q >= 10.0 ) {\n\t\tcorr = correction( q ) - correction( p+q );\n\t\treturn gammaln( p ) + corr + p - (p*ln( p+q )) + ( (q-0.5)*log1p( -p/(p+q) ) ); // eslint-disable-line max-len\n\t}\n\t// Case: p and q are small\n\treturn ln( gamma( p ) * ( gamma( q ) / gamma( p+q ) ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = betaln;\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 beta function.\n*\n* @module @stdlib/math-base-special-betaln\n*\n* @example\n* var betaln = require( '@stdlib/math-base-special-betaln' );\n*\n* var v = betaln( 0.0, 0.0 );\n* // returns Infinity\n*\n* v = betaln( 1.0, 1.0 );\n* // returns 0.0\n*\n* v = betaln( -1.0, 2.0 );\n* // returns NaN\n*\n* v = betaln( 5.0, 0.2 );\n* // returns ~1.218\n*\n* v = betaln( 4.0, 1.0 );\n* // returns ~-1.386\n*\n* v = betaln( NaN, 2.0 );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
5
|
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6BA,IAAIC,EAAS,CACZ,qBACA,sBACA,qBACA,uBACA,sBACA,sBACA,sBACA,sBACA,qBACA,sBACA,qBACA,sBACA,oBACA,sBACA,kBACD,EACIC,EAAMD,EAAO,OAiBjB,SAASE,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKL,EAAI,MAAQA,EAAI,IACpB,MAAO,KAKR,IAHAG,EAAK,EACLC,EAAK,EACLH,EAAO,EAAMD,EACPK,EAAI,EAAGA,EAAIP,EAAKO,IACrBH,EAAKC,EACLA,EAAKC,EACLA,EAAMH,EAAKE,EAAMD,EAAKL,EAAQQ,CAAE,EAEjC,OAASD,EAAGF,GAAO,EACpB,CAKAN,EAAO,QAAUG,ICvFjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6BA,IAAIC,EAAM,QAAS,+BAAgC,EAC/CC,EAAS,IAKTC,EAAO,oBACPC,EAAO,qBAgBX,SAASC,EAAiBC,EAAI,CAC7B,OAAKA,EAAI,GACD,IAGHA,GAAKF,EACF,EAEHE,EAAIH,EACDD,EAAS,EAAID,EAAK,GAAKK,EAAG,CAAI,EAAK,CAAI,EAAIA,EAE5C,GAAOA,EAAI,GACnB,CAKAN,EAAO,QAAUK,ICrEjB,IAAAE,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6BA,IAAIC,EAAU,QAAS,mCAAoC,EACvDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAiB,QAAS,0CAA2C,EACrEC,EAAO,QAAS,gCAAiC,EACjDC,EAAO,QAAS,gCAAiC,EACjDC,EAAa,IAoCjB,SAASC,EAAQ,EAAGC,EAAI,CACvB,IAAIC,EACAC,EACAC,EAKJ,OAHAD,EAAIT,EAAK,EAAGO,CAAE,EACdG,EAAIX,EAAK,EAAGQ,CAAE,EAETE,EAAI,EACD,IAEHA,IAAM,EACHL,EAEHM,IAAMN,EACHD,EAGHM,GAAK,IACTD,EAAOH,EAAYI,CAAE,EAAIJ,EAAYK,CAAE,EAAIL,EAAYI,EAAEC,CAAE,EAClD,IAAKT,EAAIS,CAAE,EAAMR,EAAiBM,GAAUC,EAAE,IAAOR,EAAIQ,GAAGA,EAAEC,EAAG,EAAQA,EAAEb,EAAO,CAACY,GAAGA,EAAEC,EAAG,GAGhGA,GAAK,IACTF,EAAOH,EAAYK,CAAE,EAAIL,EAAYI,EAAEC,CAAE,EAClCd,EAASa,CAAE,EAAID,EAAOC,EAAKA,EAAER,EAAIQ,EAAEC,CAAE,GAAQA,EAAE,IAAKb,EAAO,CAACY,GAAGA,EAAEC,EAAG,GAGrET,EAAIH,EAAOW,CAAE,GAAMX,EAAOY,CAAE,EAAIZ,EAAOW,EAAEC,CAAE,EAAI,CACvD,CAKAf,EAAO,QAAUW,IC3DjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
|
|
6
6
|
"names": ["require_dceval", "__commonJSMin", "exports", "module", "ALGMCS", "LEN", "dcseval", "x", "twox", "b2", "b1", "b0", "i", "require_gamma_correction", "__commonJSMin", "exports", "module", "pow", "dceval", "XBIG", "XMAX", "gammaCorrection", "x", "require_main", "__commonJSMin", "exports", "module", "gammaln", "log1p", "gamma", "max", "min", "ln", "LN_SQRT_TWO_PI", "NINF", "PINF", "correction", "betaln", "b", "corr", "p", "q", "main"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef STDLIB_MATH_BASE_SPECIAL_BETALN_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_BETALN_H
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
24
|
+
*/
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Evaluates the natural logarithm of the beta function.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_betaln( const double a, const double b );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_BETALN_H
|
package/lib/dceval.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* ## Notice
|
|
20
20
|
*
|
|
21
|
-
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link
|
|
21
|
+
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://netlib.org/slatec/fnlib/dcsevl.f}.
|
|
22
22
|
*
|
|
23
23
|
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.
|
|
24
24
|
*/
|
|
@@ -50,7 +50,7 @@ var LEN = ALGMCS.length;
|
|
|
50
50
|
// MAIN //
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Evaluates the n-term Chebyshev series at `x`.
|
|
54
54
|
*
|
|
55
55
|
* ## References
|
|
56
56
|
*
|
package/lib/gamma_correction.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* ## Notice
|
|
20
20
|
*
|
|
21
|
-
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link
|
|
21
|
+
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://netlib.org/fn/d9lgmc.f}.
|
|
22
22
|
*
|
|
23
23
|
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.
|
|
24
24
|
*/
|
|
@@ -40,7 +40,7 @@ var XMAX = 3.745194030963158e306;
|
|
|
40
40
|
// MAIN //
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Computes the log gamma correction factor for `x >= 10`.
|
|
44
44
|
*
|
|
45
45
|
* ```tex
|
|
46
46
|
* \log(\gamma(x)) = \log(\sqrt{2*\Pi}) + (x-0.5) \cdot \log(x) - x \operatorname{R9LGMC}(x).
|
package/lib/main.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* ## Notice
|
|
20
20
|
*
|
|
21
|
-
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link
|
|
21
|
+
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://www.netlib.org/slatec/fnlib/albeta.f}.
|
|
22
22
|
*
|
|
23
23
|
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.
|
|
24
24
|
*/
|
|
@@ -42,7 +42,7 @@ var correction = require( './gamma_correction.js' );
|
|
|
42
42
|
// MAIN //
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Evaluates the natural logarithm of the beta function.
|
|
46
46
|
*
|
|
47
47
|
* @param {NonNegativeNumber} a - first input value
|
|
48
48
|
* @param {NonNegativeNumber} b - second input value
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates the natural logarithm of the beta function.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {NonNegativeNumber} a - first input value
|
|
33
|
+
* @param {NonNegativeNumber} b - second input value
|
|
34
|
+
* @returns {number} natural logarithm of beta function
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var v = betaln( 0.0, 0.0 );
|
|
38
|
+
* // returns Infinity
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var v = betaln( 1.0, 1.0 );
|
|
42
|
+
* // returns 0.0
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var v = betaln( -1.0, 2.0 );
|
|
46
|
+
* // returns NaN
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var v = betaln( 5.0, 0.2 );
|
|
50
|
+
* // returns ~1.218
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var v = betaln( 4.0, 1.0 );
|
|
54
|
+
* // returns ~-1.386
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* var v = betaln( NaN, 2.0 );
|
|
58
|
+
* // returns NaN
|
|
59
|
+
*/
|
|
60
|
+
function betaln( a, b ) {
|
|
61
|
+
return addon( a, b );
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// EXPORTS //
|
|
66
|
+
|
|
67
|
+
module.exports = betaln;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build"
|
|
4
|
+
},
|
|
5
|
+
"fields": [
|
|
6
|
+
{
|
|
7
|
+
"field": "src",
|
|
8
|
+
"resolve": true,
|
|
9
|
+
"relative": true
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"field": "include",
|
|
13
|
+
"resolve": true,
|
|
14
|
+
"relative": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"field": "libraries",
|
|
18
|
+
"resolve": false,
|
|
19
|
+
"relative": false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"field": "libpath",
|
|
23
|
+
"resolve": true,
|
|
24
|
+
"relative": false
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"confs": [
|
|
28
|
+
{
|
|
29
|
+
"task": "build",
|
|
30
|
+
"src": [
|
|
31
|
+
"./src/main.c"
|
|
32
|
+
],
|
|
33
|
+
"include": [
|
|
34
|
+
"./include"
|
|
35
|
+
],
|
|
36
|
+
"libraries": [],
|
|
37
|
+
"libpath": [],
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"@stdlib/math-base-napi-binary",
|
|
40
|
+
"@stdlib/math-base-special-gammaln",
|
|
41
|
+
"@stdlib/math-base-special-log1p",
|
|
42
|
+
"@stdlib/math-base-special-gamma",
|
|
43
|
+
"@stdlib/math-base-special-max",
|
|
44
|
+
"@stdlib/math-base-special-min",
|
|
45
|
+
"@stdlib/math-base-special-pow",
|
|
46
|
+
"@stdlib/math-base-special-ln",
|
|
47
|
+
"@stdlib/constants-float64-ln-sqrt-two-pi",
|
|
48
|
+
"@stdlib/constants-float64-pinf",
|
|
49
|
+
"@stdlib/constants-float64-ninf"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"task": "benchmark",
|
|
54
|
+
"src": [
|
|
55
|
+
"./src/main.c"
|
|
56
|
+
],
|
|
57
|
+
"include": [
|
|
58
|
+
"./include"
|
|
59
|
+
],
|
|
60
|
+
"libraries": [],
|
|
61
|
+
"libpath": [],
|
|
62
|
+
"dependencies": [
|
|
63
|
+
"@stdlib/math-base-special-gammaln",
|
|
64
|
+
"@stdlib/math-base-special-log1p",
|
|
65
|
+
"@stdlib/math-base-special-gamma",
|
|
66
|
+
"@stdlib/math-base-special-max",
|
|
67
|
+
"@stdlib/math-base-special-min",
|
|
68
|
+
"@stdlib/math-base-special-pow",
|
|
69
|
+
"@stdlib/math-base-special-ln",
|
|
70
|
+
"@stdlib/constants-float64-ln-sqrt-two-pi",
|
|
71
|
+
"@stdlib/constants-float64-pinf",
|
|
72
|
+
"@stdlib/constants-float64-ninf"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"task": "examples",
|
|
77
|
+
"src": [
|
|
78
|
+
"./src/main.c"
|
|
79
|
+
],
|
|
80
|
+
"include": [
|
|
81
|
+
"./include"
|
|
82
|
+
],
|
|
83
|
+
"libraries": [],
|
|
84
|
+
"libpath": [],
|
|
85
|
+
"dependencies": [
|
|
86
|
+
"@stdlib/math-base-special-gammaln",
|
|
87
|
+
"@stdlib/math-base-special-log1p",
|
|
88
|
+
"@stdlib/math-base-special-gamma",
|
|
89
|
+
"@stdlib/math-base-special-max",
|
|
90
|
+
"@stdlib/math-base-special-min",
|
|
91
|
+
"@stdlib/math-base-special-pow",
|
|
92
|
+
"@stdlib/math-base-special-ln",
|
|
93
|
+
"@stdlib/constants-float64-ln-sqrt-two-pi",
|
|
94
|
+
"@stdlib/constants-float64-pinf",
|
|
95
|
+
"@stdlib/constants-float64-ninf"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-special-betaln",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Natural logarithm of the beta function.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
17
18
|
"directories": {
|
|
18
19
|
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
19
21
|
"lib": "./lib",
|
|
22
|
+
"src": "./src",
|
|
20
23
|
"dist": "./dist"
|
|
21
24
|
},
|
|
22
25
|
"types": "./docs/types",
|
|
@@ -33,13 +36,15 @@
|
|
|
33
36
|
"@stdlib/constants-float64-ln-sqrt-two-pi": "^0.2.2",
|
|
34
37
|
"@stdlib/constants-float64-ninf": "^0.2.2",
|
|
35
38
|
"@stdlib/constants-float64-pinf": "^0.2.2",
|
|
39
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
36
40
|
"@stdlib/math-base-special-gamma": "^0.3.0",
|
|
37
|
-
"@stdlib/math-base-special-gammaln": "^0.
|
|
41
|
+
"@stdlib/math-base-special-gammaln": "^0.3.0",
|
|
38
42
|
"@stdlib/math-base-special-ln": "^0.2.4",
|
|
39
43
|
"@stdlib/math-base-special-log1p": "^0.2.3",
|
|
40
44
|
"@stdlib/math-base-special-max": "^0.3.0",
|
|
41
45
|
"@stdlib/math-base-special-min": "^0.2.3",
|
|
42
|
-
"@stdlib/math-base-special-pow": "^0.3.0"
|
|
46
|
+
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
47
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {},
|
|
45
50
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_betaln )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* ## Notice
|
|
20
|
+
*
|
|
21
|
+
* The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link https://www.netlib.org/slatec/fnlib/albeta.f}.
|
|
22
|
+
*
|
|
23
|
+
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
27
|
+
#include "stdlib/math/base/special/gammaln.h"
|
|
28
|
+
#include "stdlib/math/base/special/log1p.h"
|
|
29
|
+
#include "stdlib/math/base/special/gamma.h"
|
|
30
|
+
#include "stdlib/math/base/special/max.h"
|
|
31
|
+
#include "stdlib/math/base/special/min.h"
|
|
32
|
+
#include "stdlib/math/base/special/pow.h"
|
|
33
|
+
#include "stdlib/math/base/special/ln.h"
|
|
34
|
+
#include "stdlib/constants/float64/ln_sqrt_two_pi.h"
|
|
35
|
+
#include "stdlib/constants/float64/pinf.h"
|
|
36
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
37
|
+
#include <stdint.h>
|
|
38
|
+
|
|
39
|
+
static const double ALGMCS[ 15 ] = {
|
|
40
|
+
+0.1276642195630062933333333333333e-30,
|
|
41
|
+
-0.3401102254316748799999999999999e-29,
|
|
42
|
+
+0.1025680058010470912000000000000e-27,
|
|
43
|
+
-0.3547598158101070547199999999999e-26,
|
|
44
|
+
+0.1429227355942498147573333333333e-24,
|
|
45
|
+
-0.6831888753985766870111999999999e-23,
|
|
46
|
+
+0.3962837061046434803679306666666e-21,
|
|
47
|
+
-0.2868042435334643284144622399999e-19,
|
|
48
|
+
+0.2683181998482698748957538846666e-17,
|
|
49
|
+
-0.3399615005417721944303330599666e-15,
|
|
50
|
+
+0.6221098041892605227126015543416e-13,
|
|
51
|
+
-0.1809129475572494194263306266719e-10,
|
|
52
|
+
+0.9810825646924729426157171547487e-8,
|
|
53
|
+
-0.1384948176067563840732986059135e-4,
|
|
54
|
+
+0.1666389480451863247205729650822e+0
|
|
55
|
+
};
|
|
56
|
+
static const int32_t LEN = 15;
|
|
57
|
+
static const double XBIG = 94906265.62425156;
|
|
58
|
+
static const double XMAX = 3.745194030963158e306;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Evaluates the n-term Chebyshev series at `x`.
|
|
62
|
+
*
|
|
63
|
+
* ## References
|
|
64
|
+
*
|
|
65
|
+
* - Broucke, Roger. 1973. "Algorithm: Ten Subroutines for the Manipulation of Chebyshev Series." _Communications of the ACM_ 16 (4). New York, NY, USA: ACM: 254–56. doi:[10.1145/362003.362037](https://doi.org/10.1145/362003.362037).
|
|
66
|
+
* - Fox, Leslie, and Ian Bax Parker. 1968. _Chebyshev polynomials in numerical analysis_. Oxford Mathematical Handbooks. London, United Kingdom: Oxford University Press. <https://books.google.com/books?id=F8NzsEtJCD0C>.
|
|
67
|
+
*
|
|
68
|
+
* @param x value at which the series is to be evaluated
|
|
69
|
+
* @return series value
|
|
70
|
+
*/
|
|
71
|
+
static double dceval( const double x ) {
|
|
72
|
+
double twox;
|
|
73
|
+
double b2;
|
|
74
|
+
double b1;
|
|
75
|
+
double b0;
|
|
76
|
+
int32_t i;
|
|
77
|
+
|
|
78
|
+
if ( x < -1.1 || x > 1.1 ) {
|
|
79
|
+
return 0.0 / 0.0; // NaN
|
|
80
|
+
}
|
|
81
|
+
b1 = 0.0;
|
|
82
|
+
b0 = 0.0;
|
|
83
|
+
twox = 2.0 * x;
|
|
84
|
+
for ( i = 0; i < LEN; i++ ) {
|
|
85
|
+
b2 = b1;
|
|
86
|
+
b1 = b0;
|
|
87
|
+
b0 = ( twox * b1 ) - b2 + ALGMCS[ i ];
|
|
88
|
+
}
|
|
89
|
+
return ( b0 - b2 ) * 0.5;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Computes the log gamma correction factor for `x >= 10`.
|
|
94
|
+
*
|
|
95
|
+
* ```tex
|
|
96
|
+
* \log(\gamma(x)) = \log(\sqrt{2*\Pi}) + (x-0.5) \cdot \log(x) - x \operatorname{R9LGMC}(x).
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @param x input value
|
|
100
|
+
* @return correction value
|
|
101
|
+
*/
|
|
102
|
+
static double gammaCorrection( const double x ) {
|
|
103
|
+
if ( x < 10.0 ) {
|
|
104
|
+
return 0.0 / 0.0; // NaN
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Check for underflow...
|
|
108
|
+
if ( x >= XMAX ) {
|
|
109
|
+
return 0.0;
|
|
110
|
+
}
|
|
111
|
+
if ( x < XBIG ) {
|
|
112
|
+
return dceval( ( 2.0 * stdlib_base_pow( 10.0 / x, 2.0 ) ) - 1.0 ) / x;
|
|
113
|
+
}
|
|
114
|
+
return 1.0 / ( x * 12.0 );
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Evaluates the natural logarithm of the beta function.
|
|
119
|
+
*
|
|
120
|
+
* @param a first input value
|
|
121
|
+
* @param b second input value
|
|
122
|
+
* @return natural logarithm of beta function
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* double out = stdlib_base_betaln( 5.0, 0.2 );
|
|
126
|
+
* // returns ~1.218
|
|
127
|
+
*/
|
|
128
|
+
double stdlib_base_betaln( const double a, const double b ) {
|
|
129
|
+
double corr;
|
|
130
|
+
double p;
|
|
131
|
+
double q;
|
|
132
|
+
|
|
133
|
+
p = stdlib_base_min( a, b );
|
|
134
|
+
q = stdlib_base_max( a, b );
|
|
135
|
+
|
|
136
|
+
if ( p < 0.0 ) {
|
|
137
|
+
return 0.0 / 0.0; // NaN
|
|
138
|
+
}
|
|
139
|
+
if ( p == 0.0 ) {
|
|
140
|
+
return STDLIB_CONSTANT_FLOAT64_PINF;
|
|
141
|
+
}
|
|
142
|
+
if ( q == STDLIB_CONSTANT_FLOAT64_PINF ) {
|
|
143
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Case: p and q are big
|
|
147
|
+
if ( p >= 10.0 ) {
|
|
148
|
+
corr = gammaCorrection( p ) + gammaCorrection( q ) - gammaCorrection( p + q );
|
|
149
|
+
return ( -0.5 * stdlib_base_ln( q ) ) + STDLIB_CONSTANT_FLOAT64_LN_SQRT_TWO_PI + corr + ( ( p - 0.5 ) * stdlib_base_ln( p / ( p + q ) ) ) + ( q * stdlib_base_log1p( -p / ( p + q ) ) );
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Case: p is small, but q is big
|
|
153
|
+
if ( q >= 10.0 ) {
|
|
154
|
+
corr = gammaCorrection( q ) - gammaCorrection( p + q );
|
|
155
|
+
return stdlib_base_gammaln( p ) + corr + p - ( p * stdlib_base_ln( p + q ) ) + ( ( q - 0.5 ) * stdlib_base_log1p( -p / ( p + q ) ) );
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Case: p and q are small
|
|
159
|
+
return stdlib_base_ln( stdlib_base_gamma( p ) * ( stdlib_base_gamma( q ) / stdlib_base_gamma( p + q ) ) );
|
|
160
|
+
}
|