From 80b977fe16ae974b4cceed4acd915420485785db Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sun, 23 Jun 2024 02:10:41 +0530 Subject: [PATCH 1/2] feat: add C implementation for math/base/special/trunc2 --- .../math/base/special/trunc2/README.md | 85 +++++++++ .../trunc2/benchmark/benchmark.native.js | 60 ++++++ .../trunc2/benchmark/c/native/Makefile | 146 +++++++++++++++ .../trunc2/benchmark/c/native/benchmark.c | 136 ++++++++++++++ .../math/base/special/trunc2/binding.gyp | 170 +++++++++++++++++ .../base/special/trunc2/examples/c/Makefile | 146 +++++++++++++++ .../base/special/trunc2/examples/c/example.c | 31 ++++ .../math/base/special/trunc2/include.gypi | 53 ++++++ .../include/stdlib/math/base/special/trunc2.h | 41 ++++ .../math/base/special/trunc2/lib/native.js | 54 ++++++ .../math/base/special/trunc2/manifest.json | 84 +++++++++ .../math/base/special/trunc2/src/Makefile | 70 +++++++ .../math/base/special/trunc2/src/addon.c | 22 +++ .../math/base/special/trunc2/src/main.c | 51 +++++ .../base/special/trunc2/test/test.native.js | 175 ++++++++++++++++++ 15 files changed, 1324 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/include/stdlib/math/base/special/trunc2.h create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/trunc2/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/trunc2/README.md b/lib/node_modules/@stdlib/math/base/special/trunc2/README.md index 47bb1740b1c4..ba5376b762a2 100644 --- a/lib/node_modules/@stdlib/math/base/special/trunc2/README.md +++ b/lib/node_modules/@stdlib/math/base/special/trunc2/README.md @@ -101,6 +101,91 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/trunc2.h" +``` + +#### stdlib_base_trunc2( x ) + +Rounds a `numeric` value to the nearest power of two toward zero. + +```c +double y = stdlib_base_trunc2( -4.2 ); +// returns -4.0 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +double stdlib_base_trunc2( const double x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/trunc2.h" +#include + +int main( void ) { + const double x[] = { 3.14, -3.14, 0.0, 0.0 / 0.0 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_trunc2( x[ i ] ); + printf( "trunc2(%lf) = %lf\n", x[ i ], y ); + } +} +``` + +
+ + + +
+ + +