@stdlib/math-base-special-binomcoefln 0.2.2 → 0.3.1

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/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -94,7 +94,7 @@ var binomcoefln = require( '@stdlib/math-base-special-binomcoefln' );
94
94
 
95
95
  #### binomcoefln( n, k )
96
96
 
97
- Evaluates the [binomial coefficient][binomial-coefficient] of two integers `n` and `k`.
97
+ Evaluates the natural logarithm of the [binomial coefficient][binomial-coefficient] of two integers `n` and `k`.
98
98
 
99
99
  ```javascript
100
100
  var v = binomcoefln( 8, 2 );
@@ -150,18 +150,99 @@ v = binomcoefln( 5.5, 2 );
150
150
  <!-- eslint no-undef: "error" -->
151
151
 
152
152
  ```javascript
153
- var randu = require( '@stdlib/random-base-randu' );
154
- var round = require( '@stdlib/math-base-special-round' );
153
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
154
+ var logEachMap = require( '@stdlib/console-log-each-map' );
155
155
  var binomcoefln = require( '@stdlib/math-base-special-binomcoefln' );
156
156
 
157
- var n;
158
- var k;
159
- var i;
157
+ var opts = {
158
+ 'dtype': 'float64'
159
+ };
160
+ var n = discreteUniform( 100, -10, 30, opts );
161
+ var k = discreteUniform( 100, 0, 20, opts );
160
162
 
161
- for ( i = 0; i < 100; i++ ) {
162
- n = round( (randu()*40.0) - 10.0 );
163
- k = round( randu()*20.0 );
164
- console.log( 'ln( %d choose %d ) = %d', n, k, binomcoefln( n, k ) );
163
+ logEachMap( 'ln( %d choose %d ) = %0.4f', n, k, binomcoefln );
164
+ ```
165
+
166
+ </section>
167
+
168
+ <!-- /.examples -->
169
+
170
+ <!-- C interface documentation. -->
171
+
172
+ * * *
173
+
174
+ <section class="c">
175
+
176
+ ## C APIs
177
+
178
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
179
+
180
+ <section class="intro">
181
+
182
+ </section>
183
+
184
+ <!-- /.intro -->
185
+
186
+ <!-- C usage documentation. -->
187
+
188
+ <section class="usage">
189
+
190
+ ### Usage
191
+
192
+ ```c
193
+ #include "stdlib/math/base/special/binomcoefln.h"
194
+ ```
195
+
196
+ #### stdlib_base_binomcoefln( n, k )
197
+
198
+ Evaluates the natural logarithm of the [binomial coefficient][binomial-coefficient] of two integers `n` and `k`.
199
+
200
+ ```c
201
+ double v = stdlib_base_binomcoefln( 8.0, 2.0 );
202
+ // returns ~3.332
203
+ ```
204
+
205
+ The function accepts the following arguments:
206
+
207
+ - **n**: `[in] double` input value.
208
+ - **k**: `[in] double` input value.
209
+
210
+ ```c
211
+ double stdlib_base_binomcoefln( const double n, const double k );
212
+ ```
213
+
214
+ </section>
215
+
216
+ <!-- /.usage -->
217
+
218
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
219
+
220
+ <section class="notes">
221
+
222
+ </section>
223
+
224
+ <!-- /.notes -->
225
+
226
+ <!-- C API usage examples. -->
227
+
228
+ <section class="examples">
229
+
230
+ ### Examples
231
+
232
+ ```c
233
+ #include "stdlib/math/base/special/binomcoefln.h"
234
+ #include <stdio.h>
235
+
236
+ int main( void ) {
237
+ const double a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 };
238
+ const double b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 };
239
+
240
+ double out;
241
+ int i;
242
+ for ( i = 0; i < 5; i++ ) {
243
+ out = stdlib_base_binomcoefln( a[ i ], b[ i ] );
244
+ printf( "binomcoefln(%lf, %lf) = %lf\n", a[ i ], b[ i ], out );
245
+ }
165
246
  }
166
247
  ```
167
248
 
@@ -169,6 +250,10 @@ for ( i = 0; i < 100; i++ ) {
169
250
 
170
251
  <!-- /.examples -->
171
252
 
253
+ </section>
254
+
255
+ <!-- /.c -->
256
+
172
257
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
173
258
 
174
259
  <section class="related">
@@ -203,7 +288,7 @@ See [LICENSE][stdlib-license].
203
288
 
204
289
  ## Copyright
205
290
 
206
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
291
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
207
292
 
208
293
  </section>
209
294
 
@@ -216,8 +301,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
216
301
  [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-binomcoefln.svg
217
302
  [npm-url]: https://npmjs.org/package/@stdlib/math-base-special-binomcoefln
218
303
 
219
- [test-image]: https://github.com/stdlib-js/math-base-special-binomcoefln/actions/workflows/test.yml/badge.svg?branch=v0.2.2
220
- [test-url]: https://github.com/stdlib-js/math-base-special-binomcoefln/actions/workflows/test.yml?query=branch:v0.2.2
304
+ [test-image]: https://github.com/stdlib-js/math-base-special-binomcoefln/actions/workflows/test.yml/badge.svg?branch=v0.3.1
305
+ [test-url]: https://github.com/stdlib-js/math-base-special-binomcoefln/actions/workflows/test.yml?query=branch:v0.3.1
221
306
 
222
307
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-binomcoefln/main.svg
223
308
  [coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-binomcoefln?branch=main
@@ -229,8 +314,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
229
314
 
230
315
  -->
231
316
 
232
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
233
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
317
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
318
+ [chat-url]: https://stdlib.zulipchat.com
234
319
 
235
320
  [stdlib]: https://github.com/stdlib-js/stdlib
236
321
 
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../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'use strict';\n\n// MODULES //\n\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar betaln = require( '@stdlib/math-base-special-betaln' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Computes the natural logarithm of the binomial coefficient of two integers.\n*\n* @param {integer} n - input value\n* @param {integer} k - second input value\n* @returns {number} function value\n*\n* @example\n* var v = binomcoefln( 8, 2 );\n* // returns ~3.332\n*\n* @example\n* var v = binomcoefln( 0, 0 );\n* // returns 0.0\n*\n* @example\n* var v = binomcoefln( -4, 2 );\n* // returns ~2.303\n*\n* @example\n* var v = binomcoefln( 88, 3 );\n* // returns ~11.606\n*\n* @example\n* var v = binomcoefln( NaN, 3 );\n* // returns NaN\n*\n* @example\n* var v = binomcoefln( 5, NaN );\n* // returns NaN\n*\n* @example\n* var v = binomcoefln( NaN, NaN );\n* // returns NaN\n*/\nfunction binomcoefln( n, k ) {\n\tif ( isnan( n ) || isnan( k ) ) {\n\t\treturn NaN;\n\t}\n\tif ( !isInteger( n ) || !isInteger( k ) ) {\n\t\treturn NaN;\n\t}\n\tif ( n < 0.0 ) {\n\t\treturn binomcoefln( -n + k - 1, k );\n\t}\n\tif ( k < 0 ) {\n\t\treturn NINF;\n\t}\n\tif ( k === 0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( k === 1 ) {\n\t\treturn ln( abs( n ) );\n\t}\n\tif ( n < k ) {\n\t\treturn NINF;\n\t}\n\tif ( n - k < 2 ) {\n\t\treturn binomcoefln( n, n - k );\n\t}\n\t// Case: n - k >= 2\n\treturn -ln( n + 1 ) - betaln( n - k + 1, k + 1 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = binomcoefln;\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* Compute the natural logarithm of the binomial coefficient.\n*\n* @module @stdlib/math-base-special-binomcoefln\n*\n* @example\n* var binomcoefln = require( '@stdlib/math-base-special-binomcoefln' );\n*\n* var v = binomcoefln( 8, 2 );\n* // returns ~3.332\n*\n* v = binomcoefln( 0, 0 );\n* // returns 0.0\n*\n* v = binomcoefln( -4, 2 );\n* // returns ~2.302\n*\n* v = binomcoefln( 88, 3 );\n* // returns ~11.606\n*\n* v = binomcoefln( NaN, 3 );\n* // returns NaN\n*\n* v = binomcoefln( 5, NaN );\n* // returns NaN\n*\n* v = binomcoefln( NaN, NaN );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
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'use strict';\n\n// MODULES //\n\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar betaln = require( '@stdlib/math-base-special-betaln' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Computes the natural logarithm of the binomial coefficient of two integers.\n*\n* @param {integer} n - input value\n* @param {integer} k - second input value\n* @returns {number} function value\n*\n* @example\n* var v = binomcoefln( 8, 2 );\n* // returns ~3.332\n*\n* @example\n* var v = binomcoefln( 0, 0 );\n* // returns 0.0\n*\n* @example\n* var v = binomcoefln( -4, 2 );\n* // returns ~2.303\n*\n* @example\n* var v = binomcoefln( 88, 3 );\n* // returns ~11.606\n*\n* @example\n* var v = binomcoefln( NaN, 3 );\n* // returns NaN\n*\n* @example\n* var v = binomcoefln( 5, NaN );\n* // returns NaN\n*\n* @example\n* var v = binomcoefln( NaN, NaN );\n* // returns NaN\n*/\nfunction binomcoefln( n, k ) {\n\tif ( isnan( n ) || isnan( k ) ) {\n\t\treturn NaN;\n\t}\n\tif ( !isInteger( n ) || !isInteger( k ) ) {\n\t\treturn NaN;\n\t}\n\tif ( n < 0.0 ) {\n\t\treturn binomcoefln( -n + k - 1, k );\n\t}\n\tif ( k < 0 ) {\n\t\treturn NINF;\n\t}\n\tif ( k === 0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( k === 1 ) {\n\t\treturn ln( abs( n ) );\n\t}\n\tif ( n < k ) {\n\t\treturn NINF;\n\t}\n\tif ( n - k < 2 ) {\n\t\treturn binomcoefln( n, n - k );\n\t}\n\t// Case: n - k >= 2\n\treturn -ln( n + 1 ) - betaln( n - k + 1, k + 1 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = binomcoefln;\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* Compute the natural logarithm of the binomial coefficient.\n*\n* @module @stdlib/math-base-special-binomcoefln\n*\n* @example\n* var binomcoefln = require( '@stdlib/math-base-special-binomcoefln' );\n*\n* var v = binomcoefln( 8, 2 );\n* // returns ~3.332\n*\n* v = binomcoefln( 0, 0 );\n* // returns 0.0\n*\n* v = binomcoefln( -4, 2 );\n* // returns ~2.303\n*\n* v = binomcoefln( 88, 3 );\n* // returns ~11.606\n*\n* v = binomcoefln( NaN, 3 );\n* // returns NaN\n*\n* v = binomcoefln( 5, NaN );\n* // returns NaN\n*\n* v = binomcoefln( NaN, NaN );\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,cAsBA,IAAIC,EAAY,QAAS,qCAAsC,EAC3DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAS,QAAS,kCAAmC,EACrDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EAwCrD,SAASC,EAAaC,EAAGC,EAAI,CAC5B,OAAKP,EAAOM,CAAE,GAAKN,EAAOO,CAAE,EACpB,IAEH,CAACR,EAAWO,CAAE,GAAK,CAACP,EAAWQ,CAAE,EAC9B,IAEHD,EAAI,EACDD,EAAa,CAACC,EAAIC,EAAI,EAAGA,CAAE,EAE9BA,EAAI,EACDH,EAEHG,IAAM,EACH,EAEHA,IAAM,EACHJ,EAAID,EAAKI,CAAE,CAAE,EAEhBA,EAAIC,EACDH,EAEHE,EAAIC,EAAI,EACLF,EAAaC,EAAGA,EAAIC,CAAE,EAGvB,CAACJ,EAAIG,EAAI,CAAE,EAAIL,EAAQK,EAAIC,EAAI,EAAGA,EAAI,CAAE,CAChD,CAKAT,EAAO,QAAUO,IC/CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_main", "__commonJSMin", "exports", "module", "isInteger", "isnan", "betaln", "abs", "ln", "NINF", "binomcoefln", "n", "k", "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_BINOMCOEFLN_H
20
+ #define STDLIB_MATH_BASE_SPECIAL_BINOMCOEFLN_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
+ * Computes the natural logarithm of the binomial coefficient of two integers.
31
+ */
32
+ double stdlib_base_binomcoefln( const double n, const double k );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_MATH_BASE_SPECIAL_BINOMCOEFLN_H
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@
33
33
  * // returns 0.0
34
34
  *
35
35
  * v = binomcoefln( -4, 2 );
36
- * // returns ~2.302
36
+ * // returns ~2.303
37
37
  *
38
38
  * v = binomcoefln( 88, 3 );
39
39
  * // returns ~11.606
package/lib/native.js ADDED
@@ -0,0 +1,59 @@
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
+ * Computes the natural logarithm of the binomial coefficient of two integers.
30
+ *
31
+ * @private
32
+ * @param {integer} n - input value
33
+ * @param {integer} k - second input value
34
+ * @returns {number} function value
35
+ *
36
+ * @example
37
+ * var v = binomcoefln( 8, 2 );
38
+ * // returns ~3.332
39
+ *
40
+ * @example
41
+ * var v = binomcoefln( 0, 0 );
42
+ * // returns 0.0
43
+ *
44
+ * @example
45
+ * var v = binomcoefln( -4, 2 );
46
+ * // returns ~2.303
47
+ *
48
+ * @example
49
+ * var v = binomcoefln( 88, 3 );
50
+ * // returns ~11.606
51
+ */
52
+ function binomcoefln( n, k ) {
53
+ return addon( n, k );
54
+ }
55
+
56
+
57
+ // EXPORTS //
58
+
59
+ module.exports = binomcoefln;
package/manifest.json ADDED
@@ -0,0 +1,90 @@
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
+ "-lm"
38
+ ],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/math-base-napi-binary",
42
+ "@stdlib/math-base-special-betaln",
43
+ "@stdlib/math-base-special-abs",
44
+ "@stdlib/math-base-special-ln",
45
+ "@stdlib/constants-float64-ninf",
46
+ "@stdlib/math-base-assert-is-integer"
47
+ ]
48
+ },
49
+ {
50
+ "task": "benchmark",
51
+ "src": [
52
+ "./src/main.c"
53
+ ],
54
+ "include": [
55
+ "./include"
56
+ ],
57
+ "libraries": [
58
+ "-lm"
59
+ ],
60
+ "libpath": [],
61
+ "dependencies": [
62
+ "@stdlib/math-base-special-betaln",
63
+ "@stdlib/math-base-special-abs",
64
+ "@stdlib/math-base-special-ln",
65
+ "@stdlib/constants-float64-ninf",
66
+ "@stdlib/math-base-assert-is-integer"
67
+ ]
68
+ },
69
+ {
70
+ "task": "examples",
71
+ "src": [
72
+ "./src/main.c"
73
+ ],
74
+ "include": [
75
+ "./include"
76
+ ],
77
+ "libraries": [
78
+ "-lm"
79
+ ],
80
+ "libpath": [],
81
+ "dependencies": [
82
+ "@stdlib/math-base-special-betaln",
83
+ "@stdlib/math-base-special-abs",
84
+ "@stdlib/math-base-special-ln",
85
+ "@stdlib/constants-float64-ninf",
86
+ "@stdlib/math-base-assert-is-integer"
87
+ ]
88
+ }
89
+ ]
90
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-special-binomcoefln",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Compute the natural logarithm of the binomial coefficient.",
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",
@@ -30,12 +33,14 @@
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
35
  "dependencies": {
33
- "@stdlib/constants-float64-ninf": "^0.2.2",
34
- "@stdlib/math-base-assert-is-integer": "^0.2.5",
35
- "@stdlib/math-base-assert-is-nan": "^0.2.2",
36
- "@stdlib/math-base-special-abs": "^0.2.2",
37
- "@stdlib/math-base-special-betaln": "^0.2.1",
38
- "@stdlib/math-base-special-ln": "^0.2.4"
36
+ "@stdlib/constants-float64-ninf": "^0.2.3",
37
+ "@stdlib/math-base-assert-is-integer": "^0.2.7",
38
+ "@stdlib/math-base-assert-is-nan": "^0.2.3",
39
+ "@stdlib/math-base-napi-binary": "^0.3.3",
40
+ "@stdlib/math-base-special-abs": "^0.2.3",
41
+ "@stdlib/math-base-special-betaln": "^0.3.0",
42
+ "@stdlib/math-base-special-ln": "^0.2.5",
43
+ "@stdlib/utils-library-manifest": "^0.2.4"
39
44
  },
40
45
  "devDependencies": {},
41
46
  "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/binomcoefln.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_binomcoefln )
package/src/main.c ADDED
@@ -0,0 +1,62 @@
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/binomcoefln.h"
20
+ #include "stdlib/math/base/assert/is_integer.h"
21
+ #include "stdlib/math/base/special/betaln.h"
22
+ #include "stdlib/math/base/special/abs.h"
23
+ #include "stdlib/math/base/special/ln.h"
24
+ #include "stdlib/constants/float64/ninf.h"
25
+
26
+ /**
27
+ * Computes the natural logarithm of the binomial coefficient of two integers.
28
+ *
29
+ * @param n input value
30
+ * @param k second input value
31
+ * @return function value
32
+ *
33
+ * @example
34
+ * double out = stdlib_base_binomcoefln( 8.0, 2.0 );
35
+ * // returns ~3.332
36
+ */
37
+ double stdlib_base_binomcoefln( const double n, const double k ) {
38
+ if ( !stdlib_base_is_integer( n ) || !stdlib_base_is_integer( k ) ) {
39
+ return 0.0 / 0.0; // NaN
40
+ }
41
+ if ( n < 0 ) {
42
+ return stdlib_base_binomcoefln( -n + k - 1, k );
43
+ }
44
+ if ( k < 0 ) {
45
+ return STDLIB_CONSTANT_FLOAT64_NINF;
46
+ }
47
+ if ( k == 0 ) {
48
+ return 0.0;
49
+ }
50
+ if ( k == 1 ) {
51
+ return stdlib_base_ln( stdlib_base_abs( n ) );
52
+ }
53
+ if ( n < k ) {
54
+ return STDLIB_CONSTANT_FLOAT64_NINF;
55
+ }
56
+ if ( n - k < 2 ) {
57
+ return stdlib_base_binomcoefln( n, n - k );
58
+ }
59
+
60
+ // Case: n - k >= 2
61
+ return -stdlib_base_ln( ( n + 1 ) ) - stdlib_base_betaln( ( n - k + 1 ), ( k + 1 ) );
62
+ }