From 82eb01cc21a3351bc3876c9e5a30f11909d2eb72 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 18 Jul 2024 02:44:55 +0530 Subject: [PATCH] feat: add C implementation for math/base/special/floorb --- .../math/base/special/floorb/README.md | 74 ++++ .../floorb/benchmark/benchmark.native.js | 60 ++++ .../floorb/benchmark/c/native/Makefile | 146 ++++++++ .../floorb/benchmark/c/native/benchmark.c | 136 ++++++++ .../math/base/special/floorb/binding.gyp | 170 +++++++++ .../base/special/floorb/examples/c/Makefile | 146 ++++++++ .../base/special/floorb/examples/c/example.c | 34 ++ .../math/base/special/floorb/include.gypi | 53 +++ .../include/stdlib/math/base/special/floorb.h | 40 +++ .../math/base/special/floorb/lib/native.js | 59 ++++ .../math/base/special/floorb/manifest.json | 84 +++++ .../math/base/special/floorb/src/Makefile | 70 ++++ .../math/base/special/floorb/src/addon.c | 23 ++ .../math/base/special/floorb/src/main.c | 68 ++++ .../base/special/floorb/test/test.native.js | 326 ++++++++++++++++++ 15 files changed, 1489 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/include/stdlib/math/base/special/floorb.h create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/floorb/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/floorb/README.md b/lib/node_modules/@stdlib/math/base/special/floorb/README.md index ea7bea08c8b3..919cdb3da497 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorb/README.md +++ b/lib/node_modules/@stdlib/math/base/special/floorb/README.md @@ -102,6 +102,80 @@ for ( i = 0; i < 100; i++ ) { + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/floorb.h" +``` + +#### stdlib_base_floorb( x, n, b ) + +Rounds a `numeric` value to the nearest multiple of `b^n` toward negative infinity. + +```c +double out = stdlib_base_floorb( 3.141592653589793, -4, 10 ); +// returns 3.1415 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **n**: `[in] int32_t` power. +- **b**: `[in] int32_t` base. + +```c +double stdlib_base_floorb( const double x, const int32_t n, const int32_t b ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/floorb.h" +#include +#include + +int main( void ) { + const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 }; + const int32_t n[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 }; + const int32_t b[] = { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 }; + + double v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_floorb( x[ i ], n[ i ], b[ i ] ); + printf( "floorb(%lf, %d, %d) = %lf\n", x[ i ], n[ i ], b[ i ], v ); + } +} +``` + +
+ + + + + + +