@stdlib/number-float16-base-from-word
v0.2.1
Published
Create a half-precision floating-point number from an unsigned integer corresponding to an IEEE 754 binary representation.
Readme
fromWord
Create a half-precision floating-point number from an unsigned integer corresponding to an IEEE 754 binary representation.
Installation
npm install @stdlib/number-float16-base-from-wordUsage
var fromWord = require( '@stdlib/number-float16-base-from-word' );fromWord( word )
Creates a half-precision floating-point number from an unsigned integer corresponding to an IEEE 754 binary representation.
var word = 15411; // => 0 01111 0000110011
var f16 = fromWord( word ); // when printed, implicitly promoted to float64
// returns 1.0498046875Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var pickArguments = require( '@stdlib/utils-pick-arguments' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var MAX_UINT16 = require( '@stdlib/constants-uint16-max' );
var fromWord = require( '@stdlib/number-float16-base-from-word' );
// Generate an array of random numbers:
var word = discreteUniform( 1000, 0.0, MAX_UINT16 );
// Create half-precision floating-point numbers from unsigned integers...
logEachMap( 'word: %d => float16: %f', word, pickArguments( fromWord, [ 0 ] ) );C APIs
Usage
#include "stdlib/number/float16/base/from_word.h"stdlib_base_float16_from_word( word, *x )
Creates a half-precision floating-point number from an unsigned 16-bit integer corresponding to an IEEE 754 binary representation.
#include "stdlib/number/float16/ctor.h"
#include <stdint.h>
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_tinput word. - x:
[out] stdlib_float16_t*destination for a half-precision floating-point number.
void stdlib_base_float16_from_word( const uint16_t word, stdlib_float16_t *x );Examples
#include "stdlib/number/float16/base/from_word.h"
#include "stdlib/number/float16/ctor.h"
#include "stdlib/number/float32/base/to_float16.h"
#include <stdint.h>
#include <stdio.h>
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 ) );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
