From 88f5b96779774b462886bb7953df9c3b2ecdbab6 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 26 Aug 2026 11:48:00 -0500 Subject: [PATCH] feat: add C implementation for `stats/base/dists/erlang/quantile` Co-Authored-By: Claude Opus 5 (1M context) --- .../base/dists/erlang/quantile/README.md | 83 +++++++ .../quantile/benchmark/benchmark.native.js | 74 +++++++ .../erlang/quantile/benchmark/c/Makefile | 146 ++++++++++++ .../erlang/quantile/benchmark/c/benchmark.c | 142 ++++++++++++ .../base/dists/erlang/quantile/binding.gyp | 170 ++++++++++++++ .../dists/erlang/quantile/examples/c/Makefile | 146 ++++++++++++ .../erlang/quantile/examples/c/example.c | 42 ++++ .../base/dists/erlang/quantile/include.gypi | 53 +++++ .../stdlib/stats/base/dists/erlang/quantile.h | 38 ++++ .../base/dists/erlang/quantile/lib/native.js | 64 ++++++ .../base/dists/erlang/quantile/manifest.json | 79 +++++++ .../base/dists/erlang/quantile/package.json | 3 + .../base/dists/erlang/quantile/src/Makefile | 70 ++++++ .../base/dists/erlang/quantile/src/addon.c | 22 ++ .../base/dists/erlang/quantile/src/main.c | 40 ++++ .../dists/erlang/quantile/test/test.native.js | 207 ++++++++++++++++++ 16 files changed, 1379 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/include/stdlib/stats/base/dists/erlang/quantile.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/README.md index d4c7c4321708..bf11d6fba232 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/quantile/README.md @@ -158,6 +158,89 @@ logEachMap( 'p: %0.4f, k: %d, λ: %0.4f, Q(p;k,λ): %0.4f', p, k, lambda, quanti + + +
+ +
+ +
+ + + + +
+ +## C APIs + +### Usage + +```c +#include "stdlib/stats/base/dists/erlang/quantile.h" +``` + +#### stdlib_base_dists_erlang_quantile( p, k, lambda ) + +Evaluates the [quantile function][quantile-function] for an [Erlang][erlang-distribution] distribution with shape parameter `k` and rate parameter `lambda`. + +```c +double out = stdlib_base_dists_erlang_quantile( 0.8, 2.0, 1.0 ); +// returns ~2.994 +``` + +The function accepts the following arguments: + +- **p**: `[in] double` input probability. +- **k**: `[in] double` shape parameter. +- **lambda**: `[in] double` rate parameter. + +```c +double stdlib_base_dists_erlang_quantile( const double p, const double k, const double lambda ); +``` + +
+ + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/erlang/quantile.h" +#include +#include + +static double random_uniform( double min, double max ) { + double scale = rand() / (double) RAND_MAX; + return min + ( scale * ( max - min ) ); +} + +int main( void ) { + double lambda; + double p; + double y; + int k; + int i; + + for ( i = 0; i < 25; i++ ) { + p = random_uniform( 0.0, 1.0 ); + k = (int)random_uniform( 1.0, 10.0 ); + lambda = random_uniform( 0.1, 5.0 ); + y = stdlib_base_dists_erlang_quantile( p, (double)k, lambda ); + printf( "p: %lf, k: %d, λ: %lf, Q(p;k,λ): %lf\n", p, k, lambda, y ); + } +} +``` + +
+ + + +
+ + +