From 372a566ee898e4b76dec8017969bccbd3aba9f28 Mon Sep 17 00:00:00 2001 From: Rutam Kathale Date: Thu, 14 Mar 2024 18:22:11 +0530 Subject: [PATCH 1/3] feat: `add C implementation for math/base/assert/uint32-is-pow2` This commit if applied adds the C implementation to @stdlib/math/base/assert/uint32-is-pow2 package --- .../math/base/assert/uint32-is-pow2/README.md | 92 ++++++++++ .../benchmark/benchmark.native.js | 62 +++++++ .../benchmark/c/native/Makefile | 146 +++++++++++++++ .../benchmark/c/native/benchmark.c | 138 ++++++++++++++ .../base/assert/uint32-is-pow2/binding.gyp | 170 ++++++++++++++++++ .../assert/uint32-is-pow2/examples/c/Makefile | 146 +++++++++++++++ .../uint32-is-pow2/examples/c/example.c | 33 ++++ .../base/assert/uint32-is-pow2/include.gypi | 53 ++++++ .../stdlib/math/base/assert/uint32_is_pow2.h | 41 +++++ .../base/assert/uint32-is-pow2/lib/native.js | 55 ++++++ .../base/assert/uint32-is-pow2/manifest.json | 38 ++++ .../base/assert/uint32-is-pow2/src/Makefile | 70 ++++++++ .../base/assert/uint32-is-pow2/src/addon.c | 90 ++++++++++ .../base/assert/uint32-is-pow2/src/main.c | 36 ++++ .../assert/uint32-is-pow2/test/test.native.js | 63 +++++++ 15 files changed, 1233 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/include/stdlib/math/base/assert/uint32_is_pow2.h create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/README.md b/lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/README.md index 1fe10a660ab..00bcfec2ca8 100644 --- a/lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/README.md +++ b/lib/node_modules/@stdlib/math/base/assert/uint32-is-pow2/README.md @@ -72,6 +72,98 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/assert/uint32_is_pow2.h" +``` + +#### stdlib_base_uint32_is_pow2( x ) + +Test whether an unsigned integer is a power of 2 + +```c +#include + +bool out = stdlib_base_uint32_is_pow2( 5 ); +// returns false + +out = stdlib_base_uint32_is_pow2( 2 ); +// returns true +``` + +The function accepts the following arguments: + +- **x**: `[in] uint32_t` input value. + +```c +bool stdlib_base_uint32_is_pow2( const uint32_t x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/assert/uint32_is_pow2.h" +#include +#include +#include + +int main( void ) { + const uint32_t x[] = { 0, 1, 2, 3, 4, 5, 8, 10, 16, 1024 }; + bool b; + int i; + + for ( i = 0; i < 9; i++ ) { + b = stdlib_base_uint32_is_pow2( x[ i ] ); + printf( "Value: %d. is a power of 2? %s.\n", x[ i ], ( b ) ? "True" : "False" ); + } +} +``` + +
s + + + +
+ + +