From 458697cf4aae5b6bcd2e0d9e19181d2ac3b70fe1 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Thu, 8 Aug 2024 05:14:40 +0530 Subject: [PATCH] feat: add C implementation for `math/base/special/gamma1pm1` PR-URL: #2741 Ref: #649 --------- Signed-off-by: Gunj Joshi Reviewed-by: Philipp Burckhardt --- .../math/base/special/gamma1pm1/README.md | 85 +++++ .../gamma1pm1/benchmark/benchmark.native.js | 60 ++++ .../gamma1pm1/benchmark/c/native/Makefile | 146 +++++++++ .../gamma1pm1/benchmark/c/native/benchmark.c | 133 ++++++++ .../math/base/special/gamma1pm1/binding.gyp | 170 ++++++++++ .../special/gamma1pm1/docs/types/index.d.ts | 14 +- .../base/special/gamma1pm1/docs/types/test.ts | 22 +- .../special/gamma1pm1/examples/c/Makefile | 146 +++++++++ .../special/gamma1pm1/examples/c/example.c | 31 ++ .../base/special/gamma1pm1/examples/index.js | 4 +- .../math/base/special/gamma1pm1/include.gypi | 53 +++ .../stdlib/math/base/special/gamma1pm1.h | 38 +++ .../special/gamma1pm1/lib/lgamma_small_imp.js | 2 +- .../math/base/special/gamma1pm1/lib/main.js | 16 +- .../math/base/special/gamma1pm1/lib/native.js | 62 ++++ .../special/gamma1pm1/lib/rational_p1q1.js | 4 +- .../special/gamma1pm1/lib/rational_p2q2.js | 4 +- .../special/gamma1pm1/lib/rational_p3q3.js | 4 +- .../math/base/special/gamma1pm1/manifest.json | 87 +++++ .../special/gamma1pm1/scripts/evalrational.js | 56 ++++ .../math/base/special/gamma1pm1/src/Makefile | 70 ++++ .../math/base/special/gamma1pm1/src/addon.c | 23 ++ .../math/base/special/gamma1pm1/src/main.c | 303 ++++++++++++++++++ .../special/gamma1pm1/test/test.native.js | 132 ++++++++ 24 files changed, 1630 insertions(+), 35 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/include/stdlib/math/base/special/gamma1pm1.h create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma1pm1/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/gamma1pm1/README.md b/lib/node_modules/@stdlib/math/base/special/gamma1pm1/README.md index ccf18b2874af..108770906da2 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma1pm1/README.md +++ b/lib/node_modules/@stdlib/math/base/special/gamma1pm1/README.md @@ -75,6 +75,91 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/gamma1pm1.h" +``` + +#### stdlib_base_gamma1pm1( x ) + +Computes `gamma(x+1) - 1` without cancellation errors for small `x` and where `gamma(x)` is the [gamma function][@stdlib/math/base/special/gamma]. + +```c +double out = stdlib_base_gamma1pm1( 0.2 ); +// returns ~-0.082 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +double stdlib_base_gamma1pm1( const double x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/gamma1pm1.h" +#include + +int main( void ) { + const double x[] = { 4.0, -1.5, -0.5, 0.5 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_gamma1pm1( x[ i ] ); + printf( "gamma1pm1(%lf) = %lf\n", x[ i ], y ); + } +} +``` + +
+ + + +
+ + +