diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/README.md b/lib/node_modules/@stdlib/math/base/special/binomcoef/README.md index c10e23b11d6f..56b16b76ff21 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/README.md +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/README.md @@ -172,17 +172,17 @@ logEachMap( '%d choose %d = %d', n, k, binomcoef ); Evaluates the [binomial coefficient][binomial-coefficient] of two integers `n` and `k`. ```c -double v = stdlib_base_binomcoef( 8, 2 ); +double v = stdlib_base_binomcoef( 8.0, 2.0 ); // returns 28.0 ``` The function accepts the following arguments: -- **n**: `[in] int64_t` input value. -- **k**: `[in] int64_t` input value. +- **n**: `[in] double` input value. +- **k**: `[in] double` input value. ```c -double stdlib_base_binomcoef( const int64_t n, const int64_t k ); +double stdlib_base_binomcoef( const double n, const double k ); ``` @@ -206,18 +206,16 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ); ```c #include "stdlib/math/base/special/binomcoef.h" #include -#include -#include int main( void ) { - const int64_t a[] = { 24, 32, 48, 116, 33 }; - const int64_t b[] = { 12, 6, 15, 52, 22 }; + const double a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; + const double b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; double out; int i; for ( i = 0; i < 5; i++ ) { out = stdlib_base_binomcoef( a[ i ], b[ i ] ); - printf( "binomcoef(%" PRId64 ", %" PRId64 ") = %lf\n", a[ i ], b[ i ], out ); + printf( "binomcoef(%lf, %lf) = %lf\n", a[ i ], b[ i ], out ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/binomcoef/benchmark/c/native/benchmark.c index 549dea957044..d3ebce1b1d2a 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/benchmark/c/native/benchmark.c @@ -90,16 +90,16 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { - int64_t n[ 100 ]; - int64_t k[ 100 ]; + double n[ 100 ]; + double k[ 100 ]; double elapsed; double y; double t; int i; for ( i = 0; i < 100; i++ ) { - n[ i ] = (int64_t)round( 500.0 * rand_double() ); - k[ i ] = (int64_t)round( 500.0 * rand_double() ); + n[ i ] = round( 500.0 * rand_double() ); + k[ i ] = round( 500.0 * rand_double() ); } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/binomcoef/examples/c/example.c index fb6bc1e451f2..da996596403d 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/examples/c/example.c @@ -18,17 +18,15 @@ #include "stdlib/math/base/special/binomcoef.h" #include -#include -#include int main( void ) { - const int64_t a[] = { 24, 32, 48, 116, 33 }; - const int64_t b[] = { 12, 6, 15, 52, 22 }; + const double a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; + const double b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; double out; int i; for ( i = 0; i < 5; i++ ) { out = stdlib_base_binomcoef( a[ i ], b[ i ] ); - printf( "binomcoef(%" PRId64 ", %" PRId64 ") = %lf\n", a[ i ], b[ i ], out ); + printf( "binomcoef(%lf, %lf) = %lf\n", a[ i ], b[ i ], out ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/include/stdlib/math/base/special/binomcoef.h b/lib/node_modules/@stdlib/math/base/special/binomcoef/include/stdlib/math/base/special/binomcoef.h index f9e2ae42fbaa..a0274d3395af 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/include/stdlib/math/base/special/binomcoef.h +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/include/stdlib/math/base/special/binomcoef.h @@ -19,8 +19,6 @@ #ifndef STDLIB_MATH_BASE_SPECIAL_BINOMCOEF_H #define STDLIB_MATH_BASE_SPECIAL_BINOMCOEF_H -#include - /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -31,7 +29,7 @@ extern "C" { /** * Computes the binomial coefficient of two integers. */ -double stdlib_base_binomcoef( const int64_t n, const int64_t k ); +double stdlib_base_binomcoef( const double n, const double k ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/manifest.json b/lib/node_modules/@stdlib/math/base/special/binomcoef/manifest.json index cb16c422f117..7b8ffed68392 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/manifest.json @@ -42,7 +42,9 @@ "@stdlib/math/base/special/floor", "@stdlib/math/base/special/gcd", "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/max-safe-integer" + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/math/base/assert/is-integer", + "@stdlib/math/base/assert/is-odd" ] }, { @@ -61,7 +63,9 @@ "@stdlib/math/base/special/floor", "@stdlib/math/base/special/gcd", "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/max-safe-integer" + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/math/base/assert/is-integer", + "@stdlib/math/base/assert/is-odd" ] }, { @@ -80,7 +84,9 @@ "@stdlib/math/base/special/floor", "@stdlib/math/base/special/gcd", "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/max-safe-integer" + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/math/base/assert/is-integer", + "@stdlib/math/base/assert/is-odd" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/src/addon.c b/lib/node_modules/@stdlib/math/base/special/binomcoef/src/addon.c index a513c406c10e..4f1016b113e0 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/src/addon.c @@ -19,4 +19,4 @@ #include "stdlib/math/base/special/binomcoef.h" #include "stdlib/math/base/napi/binary.h" -STDLIB_MATH_BASE_NAPI_MODULE_LL_D( stdlib_base_binomcoef ) +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_binomcoef ) diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoef/src/main.c b/lib/node_modules/@stdlib/math/base/special/binomcoef/src/main.c index f988aa6d2348..fd33fc6f8b0d 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoef/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoef/src/main.c @@ -17,11 +17,12 @@ */ #include "stdlib/math/base/special/binomcoef.h" +#include "stdlib/math/base/assert/is_integer.h" +#include "stdlib/math/base/assert/is_odd.h" #include "stdlib/math/base/special/floor.h" #include "stdlib/math/base/special/gcd.h" #include "stdlib/constants/float64/pinf.h" #include "stdlib/constants/float64/max_safe_integer.h" -#include /** * Computes the binomial coefficient of two integers. @@ -31,20 +32,24 @@ * @return function value * * @example -* double out = stdlib_base_binomcoef( 8, 2 ); +* double out = stdlib_base_binomcoef( 8.0, 2.0 ); * // returns 28.0 */ -double stdlib_base_binomcoef( const int64_t n, const int64_t k ) { +double stdlib_base_binomcoef( const double n, const double k ) { double res; double sgn; - int64_t nc; - int64_t kc; - int64_t d; + double nc; + double kc; + double d; double b; double c; double g; double s; + if ( !stdlib_base_is_integer( n ) || !stdlib_base_is_integer( k ) ) { + return 0.0 / 0.0; // NaN + } + if ( k < 0 ) { return 0.0; } @@ -52,7 +57,7 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) { nc = n; if ( nc < 0 ) { nc = -nc + k - 1; - if ( k & 1 ) { + if ( stdlib_base_is_odd( k ) ) { sgn *= -1.0; } } @@ -63,7 +68,7 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) { return sgn; } if ( k == 1 || k == nc - 1 ) { - return sgn * (double)nc; + return sgn * nc; } // Minimize the number of computed terms by leveraging symmetry: @@ -71,11 +76,11 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) { if ( nc - kc < kc ) { kc = nc - kc; } - s = stdlib_base_floor( (double)STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER / (double)nc ); + s = stdlib_base_floor( (double)STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER / nc ); // Use a standard algorithm for computing the binomial coefficient res = 1.0; - for ( d = 1; d <= kc; d++ ) { + for ( d = 1.0; d <= kc; d++ ) { // Check for potential overflow... if ( res > s ) { break;