@stdlib/number-float16-base-significand
v0.1.1
Published
Return an integer corresponding to the significand of a half-precision floating-point number.
Downloads
12
Readme
significand
Return an integer corresponding to the significand of a half-precision floating-point number.
Installation
npm install @stdlib/number-float16-base-significandUsage
var significand = require( '@stdlib/number-float16-base-significand' );significand( x )
Returns an integer corresponding to the significand of a half-precision floating-point number.
var toFloat16 = require( '@stdlib/number-float64-base-to-float16' );
var s = significand( toFloat16( 3.14 ) ); // => 1001001000
// returns 584
s = significand( toFloat16( 3.14e-6 ) ); // => 0000110101
// returns 53
s = significand( toFloat16( -3.14 ) ); // => 1001001000
// returns 584
s = significand( 0.0 ); // => 0000000000
// returns 0
s = significand( NaN ); // => 1000000000
// returns 512Examples
var randu = require( '@stdlib/random-base-randu' );
var round = require( '@stdlib/math-base-special-round' );
var pow = require( '@stdlib/math-base-special-pow' );
var toFloat16 = require( '@stdlib/number-float64-base-to-float16' );
var significand = require( '@stdlib/number-float16-base-significand' );
var frac;
var exp;
var x;
var s;
var i;
// Generate random numbers and extract their significands...
for ( i = 0; i < 100; i++ ) {
frac = randu() * 10.0;
exp = round( randu()*13.0 ) - 7;
x = frac * pow( 10.0, exp );
x = toFloat16( x );
s = significand( x );
console.log( 'x: %d. significand: %d.', x, s );
}C APIs
Usage
#include "stdlib/number/float16/base/significand.h"stdlib_base_float16_significand( x )
Returns an integer corresponding to the significand of a half-precision floating-point number.
#include "stdlib/number/float16/ctor.h"
#include <stdint.h>
stdlib_float16_t x = stdlib_float16_from_bits( 51648 ); // => -11.5
int16_t y = stdlib_base_float16_significand( x );The function accepts the following arguments:
- x:
[in] stdlib_float16_tinput value.
int16_t stdlib_base_float16_significand( const stdlib_float16_t x );Examples
#include "stdlib/number/float16/base/significand.h"
#include "stdlib/number/float16/ctor.h"
#include "stdlib/number/float32/base/to_float16.h"
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
int main( void ) {
const float x[] = { 4.0f, 0.0f, -0.0f, 1.0f, -1.0f, 3.14f, -3.14f, 1.0e38f, -1.0e38f, 1.0f/0.0f, -1.0f/0.0f, 0.0f/0.0f };
stdlib_float16_t v;
int16_t out;
int i;
for ( i = 0; i < 12; i++ ) {
v = stdlib_base_float32_to_float16( x[ i ] );
out = stdlib_base_float16_significand( v );
printf( "%f => %" PRId16 "\n", x[ i ], out );
}
}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.
