diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md b/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md index 75c7849c6ae8..9211a32326b0 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md @@ -162,17 +162,17 @@ logEachMap( 'binomcoeff(%d,%d) = %0.4f', n, k, binomcoeff ); Evaluates the [binomial coefficient][binomial-coefficient] of two integers `n` and `k` as a single-precision floating-point number. ```c -float v = stdlib_base_binomcoeff( 8, 2 ); +float v = stdlib_base_binomcoeff( 8.0f, 2.0f ); // returns 28.0f ``` The function accepts the following arguments: -- **n**: `[in] int32_t` input value. -- **k**: `[in] int32_t` input value. +- **n**: `[in] float` input value. +- **k**: `[in] float` input value. ```c -float stdlib_base_binomcoeff( const int32_t n, const int32_t k ); +float stdlib_base_binomcoeff( const float n, const float k ); ``` @@ -196,17 +196,16 @@ float stdlib_base_binomcoeff( const int32_t n, const int32_t k ); ```c #include "stdlib/math/base/special/binomcoeff.h" #include -#include int main( void ) { - const int32_t a[] = { 24, 32, 48, 116, 33 }; - const int32_t b[] = { 12, 6, 15, 52, 22 }; + const float a[] = { 24.0f, 32.0f, 48.0f, 116.0f, 33.0f }; + const float b[] = { 12.0f, 6.0f, 15.0f, 52.0f, 22.0f }; float out; int i; for ( i = 0; i < 5; i++ ) { out = stdlib_base_binomcoeff( a[ i ], b[ i ] ); - printf( "binomcoeff(%d, %d) = %f\n", a[ i ], b[ i ], out ); + printf( "binomcoeff(%f, %f) = %f\n", a[ i ], b[ i ], out ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c index 05b52c909835..4bf89c4614bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c @@ -90,16 +90,16 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { - int32_t n[ 100 ]; - int32_t k[ 100 ]; + float n[ 100 ]; + float k[ 100 ]; double elapsed; double t; float y; int i; for ( i = 0; i < 100; i++ ) { - n[ i ] = (int32_t)round( 100.0 * rand_float() ); - k[ i ] = (int32_t)round( 100.0 * rand_float() ); + n[ i ] = roundf( 100.0f * rand_float() ); + k[ i ] = roundf( 100.0f * rand_float() ); } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c index 9e866aa64bc7..94dfe08085d1 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c @@ -18,16 +18,15 @@ #include "stdlib/math/base/special/binomcoeff.h" #include -#include int main( void ) { - const int32_t a[] = { 24, 32, 48, 116, 33 }; - const int32_t b[] = { 12, 6, 15, 52, 22 }; + const float a[] = { 24.0f, 32.0f, 48.0f, 116.0f, 33.0f }; + const float b[] = { 12.0f, 6.0f, 15.0f, 52.0f, 22.0f }; float out; int i; for ( i = 0; i < 5; i++ ) { out = stdlib_base_binomcoeff( a[ i ], b[ i ] ); - printf( "binomcoeff(%d, %d) = %f\n", a[ i ], b[ i ], out ); + printf( "binomcoeff(%f, %f) = %f\n", a[ i ], b[ i ], out ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/include/stdlib/math/base/special/binomcoeff.h b/lib/node_modules/@stdlib/math/base/special/binomcoeff/include/stdlib/math/base/special/binomcoeff.h index 19888e0894f2..56e7c327de1a 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/include/stdlib/math/base/special/binomcoeff.h +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/include/stdlib/math/base/special/binomcoeff.h @@ -19,8 +19,6 @@ #ifndef STDLIB_MATH_BASE_SPECIAL_BINOMCOEFF_H #define STDLIB_MATH_BASE_SPECIAL_BINOMCOEFF_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 as a single-precision floating-point number. */ -float stdlib_base_binomcoeff( const int32_t n, const int32_t k ); +float stdlib_base_binomcoeff( const float n, const float k ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json b/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json index 3bc22b3e354a..27fba1e53e41 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json @@ -42,7 +42,9 @@ "@stdlib/math/base/special/floorf", "@stdlib/math/base/special/gcdf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/max-safe-integer" + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/math/base/assert/is-integerf", + "@stdlib/math/base/assert/is-oddf" ] }, { @@ -61,7 +63,9 @@ "@stdlib/math/base/special/floorf", "@stdlib/math/base/special/gcdf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/max-safe-integer" + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/math/base/assert/is-integerf", + "@stdlib/math/base/assert/is-oddf" ] }, { @@ -80,7 +84,9 @@ "@stdlib/math/base/special/floorf", "@stdlib/math/base/special/gcdf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/max-safe-integer" + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/math/base/assert/is-integerf", + "@stdlib/math/base/assert/is-oddf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/addon.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/addon.c index c00c46f7ddbc..6e6c8aaea883 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/addon.c @@ -19,4 +19,4 @@ #include "stdlib/math/base/special/binomcoeff.h" #include "stdlib/math/base/napi/binary.h" -STDLIB_MATH_BASE_NAPI_MODULE_II_F( stdlib_base_binomcoeff ) +STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_binomcoeff ) diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c index 755e115e1698..bb064932be8d 100644 --- a/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c @@ -17,11 +17,12 @@ */ #include "stdlib/math/base/special/binomcoeff.h" +#include "stdlib/math/base/assert/is_integerf.h" +#include "stdlib/math/base/assert/is_oddf.h" #include "stdlib/math/base/special/floorf.h" #include "stdlib/math/base/special/gcdf.h" #include "stdlib/constants/float32/pinf.h" #include "stdlib/constants/float32/max_safe_integer.h" -#include /** * Computes the binomial coefficient of two integers as a single-precision floating-point number. @@ -31,20 +32,23 @@ * @return function value * * @example -* float out = stdlib_base_binomcoeff( 8, 2 ); +* float out = stdlib_base_binomcoeff( 8.0f, 2.0f ); * // returns 28.0f */ -float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { - int32_t nc; - int32_t kc; - int32_t d; +float stdlib_base_binomcoeff( const float n, const float k ) { float res; float sgn; + float nc; + float kc; + float d; float b; float c; float g; float s; + if ( !stdlib_base_is_integerf( n ) || !stdlib_base_is_integerf( k ) ) { + return 0.0f / 0.0f; // NaN + } if ( k < 0 ) { return 0.0f; } @@ -52,7 +56,7 @@ float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { nc = n; if ( nc < 0 ) { nc = -nc + k - 1; - if ( k & 1 ) { + if ( stdlib_base_is_oddf( k ) ) { sgn *= -1.0f; } } @@ -63,7 +67,7 @@ float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { return sgn; } if ( k == 1 || k == nc - 1 ) { - return sgn * (float)nc; + return sgn * nc; } // Minimize the number of computed terms by leveraging symmetry: @@ -71,17 +75,17 @@ float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { if ( nc - kc < kc ) { kc = nc - kc; } - s = stdlib_base_floorf( (float)STDLIB_CONSTANT_FLOAT32_MAX_SAFE_INTEGER / (float)nc ); + s = stdlib_base_floorf( (float)STDLIB_CONSTANT_FLOAT32_MAX_SAFE_INTEGER / nc ); // Use a standard algorithm for computing the binomial coefficient res = 1.0f; - for ( d = 1; d <= kc; d++ ) { + for ( d = 1.0f; d <= kc; d++ ) { // Check for potential overflow... if ( res > s ) { break; } - res *= (float)nc; - res /= (float)d; + res *= nc; + res /= d; nc -= 1; } @@ -110,7 +114,7 @@ float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { if ( b == STDLIB_CONSTANT_FLOAT32_PINF ) { return sgn * b; } - c = stdlib_base_binomcoeff( kc, kc-d+1 ) ; + c = stdlib_base_binomcoeff( kc, kc-d+1 ); /* * At this point, the result should be `res*b/c`.