From fe08d682fdbbc153c943a10924c19a6b43b12183 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 23 Dec 2025 16:30:30 +0530 Subject: [PATCH 1/5] feat: add C implementation for number/float16/base/from-word --- .../number/float16/base/from-word/README.md | 94 ++++++ .../from-word/benchmark/benchmark.native.js | 62 ++++ .../base/from-word/benchmark/c/Makefile | 146 +++++++++ .../base/from-word/benchmark/c/benchmark.c | 133 ++++++++ .../number/float16/base/from-word/binding.gyp | 170 ++++++++++ .../base/from-word/examples/c/Makefile | 146 +++++++++ .../base/from-word/examples/c/example.c | 34 ++ .../float16/base/from-word/include.gypi | 53 +++ .../stdlib/number/float16/base/from_word.h | 41 +++ .../float16/base/from-word/lib/native.js | 47 +++ .../float16/base/from-word/manifest.json | 42 +++ .../float16/base/from-word/package.json | 3 + .../float16/base/from-word/src/Makefile | 70 ++++ .../number/float16/base/from-word/src/addon.c | 92 ++++++ .../float16/base/from-word/src/from_word.c | 40 +++ .../base/from-word/test/test.native.js | 302 ++++++++++++++++++ 16 files changed, 1475 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/binding.gyp create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/include.gypi create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/include/stdlib/number/float16/base/from_word.h create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/lib/native.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/manifest.json create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/src/Makefile create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/src/addon.c create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/src/from_word.c create mode 100644 lib/node_modules/@stdlib/number/float16/base/from-word/test/test.native.js diff --git a/lib/node_modules/@stdlib/number/float16/base/from-word/README.md b/lib/node_modules/@stdlib/number/float16/base/from-word/README.md index 19a217d40eb6..cf3111893068 100644 --- a/lib/node_modules/@stdlib/number/float16/base/from-word/README.md +++ b/lib/node_modules/@stdlib/number/float16/base/from-word/README.md @@ -75,6 +75,100 @@ logEachMap( 'word: %d => float16: %f', word, pickArguments( fromWord, [ 0 ] ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/number/float16/base/from_word.h" +``` + +#### stdlib_base_float16_from_word( word, \*x ) + +Creates a [half-precision floating-point number][ieee754] from an unsigned 16-bit integer corresponding to an [IEEE 754][ieee754] binary representation. + +```c +#include "stdlib/number/float16/ctor.h" +#include + +uint16_t word = 51648; // => -11.5 + +stdlib_float16_t x; +stdlib_base_float16_from_word( word, &x ); +``` + +The function accepts the following arguments: + +- **word**: `[in] uint16_t` input word. +- **x**: `[out] stdlib_float16_t*` destination for a half-precision floating-point number. + +```c +void stdlib_base_float16_from_word( const uint16_t word, stdlib_float16_t *x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/number/float16/base/from_word.h" +#include "stdlib/number/float16/ctor.h" +#include "stdlib/number/float32/base/to_float16.h" +#include +#include + +int main( void ) { + uint16_t word = 51648; + + stdlib_float16_t x; + int i; + for ( i = 0; i < 10; i++ ) { + stdlib_base_float16_from_word( word+(uint16_t)(i*10), &x ); + printf( "word: %u => %f\n", word, stdlib_base_float32_to_float16( x ) ); + } +} +``` + +
+ + + +
+ + +