Return a boolean indicating if the sign bit for a half-precision floating-point number is on (true) or off (false).
var signbit = require( '@stdlib/number/float16/base/signbit' );Returns a boolean indicating if the sign bit for a half-precision floating-point number is on (true) or off (false).
var toFloat16 = require( '@stdlib/number/float64/base/to-float16' );
var bool = signbit( toFloat16( 4.0 ) );
// returns false
bool = signbit( toFloat16( -5.960464477539063e-8 ) );
// returns true
bool = signbit( 0.0 );
// returns false
bool = signbit( -0.0 );
// returns truevar toFloat16 = require( '@stdlib/number/float64/base/to-float16' );
var uniform = require( '@stdlib/random/array/uniform' );
var map = require( '@stdlib/array/base/map' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var signbit = require( '@stdlib/number/float16/base/signbit' );
// Create an array of random half-precision floating-point numbers:
var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
// Determine whether the sign bit is on or off for each number:
logEachMap( 'x: %0.4f => %s', x, signbit );#include "stdlib/number/float16/base/signbit.h"Returns an integer indicating whether the sign bit for a half-precision floating-point number is on (1) or off (0).
#include "stdlib/number/float16/ctor.h"
#include <stdint.h>
stdlib_float16_t x = stdlib_float16_from_bits( 51648 ); // => -11.5
int8_t out = stdlib_base_float16_signbit( x );The function accepts the following arguments:
- x:
[in] stdlib_float16_tinput value.
int8_t stdlib_base_float16_signbit( const stdlib_float16_t x );#include "stdlib/number/float16/base/signbit.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[] = { 3.14f, -3.14f, 0.0f, -0.0f, 4.0f, 1.0f, -1.0f, 1.0e38f, -1.0e38f };
stdlib_float16_t v;
int8_t out;
int i;
for ( i = 0; i < 9; i++ ) {
v = stdlib_base_float32_to_float16( x[ i ] );
out = stdlib_base_float16_signbit( v );
printf( "%f => signbit: %" PRId8 "\n", x[ i ], out );
}
}