From 89cb5e40a7ee959895266d2a7a5795460a3380da Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 29 Aug 2026 01:07:17 -0500 Subject: [PATCH] feat: add C implementation for `stats/base/dists/studentized-range/quantile` - Add src/main.c with the quantile algorithm ported from JS: apnorminv (inverse normal), qtrngo (initial estimate), and secant-method root-finding iterating the CDF - Link to the CDF C library instead of inlining the CDF code - Add public header, native addon, build configuration - Add manifest.json with CDF dependency - Add native benchmark, native test, C benchmark, C example - Add README C API documentation section - Update package.json with gypfile and native directories - Update lib/index.js with tryRequire pattern for native addon Co-Authored-By: Claude Fable 5 --- .../studentized-range/quantile/README.md | 98 +++++++ .../quantile/benchmark/benchmark.native.js | 70 +++++ .../quantile/benchmark/c/Makefile | 146 +++++++++++ .../quantile/benchmark/c/benchmark.c | 141 ++++++++++ .../studentized-range/quantile/binding.gyp | 170 ++++++++++++ .../quantile/examples/c/Makefile | 146 +++++++++++ .../quantile/examples/c/example.c | 42 +++ .../studentized-range/quantile/include.gypi | 53 ++++ .../base/dists/studentized-range/quantile.h | 38 +++ .../studentized-range/quantile/lib/native.js | 68 +++++ .../studentized-range/quantile/manifest.json | 88 +++++++ .../studentized-range/quantile/package.json | 3 + .../studentized-range/quantile/src/Makefile | 70 +++++ .../studentized-range/quantile/src/addon.c | 22 ++ .../studentized-range/quantile/src/main.c | 241 ++++++++++++++++++ .../quantile/test/test.native.js | 140 ++++++++++ 16 files changed, 1536 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/include/stdlib/stats/base/dists/studentized-range/quantile.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/README.md b/lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/README.md index 3824c4525895..4e0eea4f9bb4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/README.md @@ -124,6 +124,104 @@ logEachMap( 'p: %0.4f, r: %0.4f, v: %0.4f, Q(p;r,v): %0.4f', p, r, v, quantile ) + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/studentized-range/quantile.h" +``` + +#### stdlib_base_dists_studentized_range_quantile( p, r, v ) + +Evaluates the quantile function for a studentized range distribution. + +```c +double out = stdlib_base_dists_studentized_range_quantile( 0.5, 3.0, 2.0 ); +// returns ~1.908 +``` + +The function accepts the following arguments: + +- **p**: `[in] double` input probability. +- **r**: `[in] double` sample size for range (same for each group). +- **v**: `[in] double` degrees of freedom. + +```c +double stdlib_base_dists_studentized_range_quantile( const double p, const double r, const double v ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/studentized-range/quantile.h" +#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 ) { + double p; + double r; + double v; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + p = random_uniform( 0.0, 1.0 ); + r = random_uniform( 2.0, 20.0 ); + v = random_uniform( 2.0, 10.0 ); + y = stdlib_base_dists_studentized_range_quantile( p, r, v ); + printf( "p: %lf, r: %lf, v: %lf, Q(p;r,v): %lf\n", p, r, v, y ); + } +} +``` + +
+ + + +
+ + +