diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h index 514b72add029..c918e2410b2d 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h @@ -144,6 +144,48 @@ }; \ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dii_d_init ) +/** +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number and two signed 64-bit integers and returning a double-precision floating-point number. +* +* @param fcn ternary function +* +* @example +* #include +* +* static double fcn( const int_64 x, const int_64 y, const double z ) { +* // ... +* } +* +* // ... +* +* // Register a Node-API module: +* STDLIB_MATH_BASE_NAPI_MODULE_LLD_D( fcn ); +*/ +#define STDLIB_MATH_BASE_NAPI_MODULE_LLD_D( fcn ) \ + static napi_value stdlib_math_base_napi_lld_d_wrapper( \ + napi_env env, \ + napi_callback_info info \ + ) { \ + return stdlib_math_base_napi_lld_d( env, info, fcn ); \ + }; \ + static napi_value stdlib_math_base_napi_lld_d_init( \ + napi_env env, \ + napi_value exports \ + ) { \ + napi_value fcn; \ + napi_status status = napi_create_function( \ + env, \ + "exports", \ + NAPI_AUTO_LENGTH, \ + stdlib_math_base_napi_lld_d_wrapper, \ + NULL, \ + &fcn \ + ); \ + assert( status == napi_ok ); \ + return fcn; \ + }; \ + NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_lld_d_init ) + /* * If C++, prevent name mangling so that the compiler emits a ternary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -166,6 +208,11 @@ napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, f */ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); +/** +* Invokes a ternary function accepting a double-precision floating-point number and two signed 64-bit integers and returning a double-precision floating-point number. +*/ +napi_value stdlib_math_base_napi_lld_d( napi_env env, napi_callback_info info, double ( *fcn )( int64_t, int64_t, double ) ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c index 92b89ca0999e..77a4f4831145 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c @@ -248,3 +248,79 @@ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, d return v; } + +/** +* Invokes a ternary function accepting a double-precision floating-point number and two signed 64-bit integers and returning a double-precision floating-point number. +* +* ## Notes +* +* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: +* +* - `x`: input value. +* - `y`: input value. +* - `z`: input value. +* +* @param env environment under which the function is invoked +* @param info callback data +* @param fcn ternary function +* @return function return value as a Node-API double-precision floating-point number +*/ +napi_value stdlib_math_base_napi_lld_d( napi_env env, napi_callback_info info, double ( *fcn )( int64_t, int64_t, double ) ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + int64_t x; + status = napi_get_value_int64( env, argv[ 0 ], &x ); + assert( status == napi_ok ); + + int64_t y; + status = napi_get_value_int64( env, argv[ 1 ], &y ); + assert( status == napi_ok ); + + double z; + status = napi_get_value_double( env, argv[ 2 ], &z ); + assert( status == napi_ok ); + + napi_value v; + status = napi_create_double( env, fcn( x, y, z ), &v ); + assert( status == napi_ok ); + + return v; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/cdf/README.md index 44a044f55476..bedb5f0dac06 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/cdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/cdf/README.md @@ -167,6 +167,103 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/binomial/cdf.h" +``` + +#### stdlib_base_dists_binomial_cdf( k, n, p ) + +Evaluates the cumulative distribution function (CDF) for a binomial distribution. + +```c +double out = stdlib_base_dists_binomial_cdf( 5, 10, 0.5 ); +// returns ~0.623 +``` + +The function accepts the following arguments: + +- **k**: `[in] int` input value. +- **n**: `[in] int` number of trials. +- **p**: `[in] double` success probability. + +```c +double stdlib_base_dists_binomial_cdf( const int64_t k, const int64_t n, const double p ); +``` + +
+ + + + +
+ +
+ + + + + +
+### Examples + +```c +#include "stdlib/stats/base/dists/binomial/cdf.h" +#include +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + int64_t k; + int64_t n; + double p; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + k = (int64_t)random_uniform(0.0,10.0); // Random integer between 0 and 10 + n = k+(int64_t)random_uniform(0.0,10.0); // Random integer between k and 20 + p = random_uniform(0.0,1.0); // Random double between 0.0 and 1.0 + y = stdlib_base_dists_binomial_cdf( k, n, p ); + printf( "k: %d, n: %d, p: %lf, F(k;n,p): %lf\n", k, n, p, y ); + } +} +``` + +
+ + + +
+ + +