Subtract two half-precision floating-point numbers.
var sub = require( '@stdlib/number/float16/base/sub' );Subtracts two half-precision floating-point numbers.
var v = sub( -1.0, 5.0 );
// returns -6.0
v = sub( 2.0, 5.0 );
// returns -3.0
v = sub( 0.0, 5.0 );
// returns -5.0
v = sub( -0.0, 0.0 );
// returns -0.0
v = sub( NaN, NaN );
// returns NaNvar 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 sub = require( '@stdlib/number/float16/base/sub' );
var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
logEachMap( 'x: %f, y: %f => %f', x, y, sub );#include "stdlib/number/float16/base/sub.h"Subtract two half-precision floating-point numbers.
#include "stdlib/number/float16/ctor.h"
stdlib_float16_t x = stdlib_float16_from_bits( 17664 ); // => 5.0
stdlib_float16_t y = stdlib_float16_from_bits( 16384 ); // => 2.0
stdlib_float16_t v = stdlib_base_float16_sub( x, y );The function accepts the following arguments:
- x:
[in] stdlib_float16_tfirst input value. - y:
[in] stdlib_float16_tsecond input value.
stdlib_float16_t stdlib_base_float16_sub( const stdlib_float16_t x, const stdlib_float16_t y );#include "stdlib/number/float16/base/sub.h"
#include "stdlib/number/float16/ctor.h"
#include "stdlib/number/float32/base/to_float16.h"
#include "stdlib/number/float16/base/to_float32.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 3.14f, -3.14f, 0.0f, 0.0f/0.0f };
const float y[] = { 3.14f, -3.14f, -0.0f, 0.0f/0.0f };
stdlib_float16_t v;
stdlib_float16_t w;
stdlib_float16_t z;
int i;
for ( i = 0; i < 4; i++ ) {
v = stdlib_base_float32_to_float16( x[ i ]);
w = stdlib_base_float32_to_float16( y[ i ]);
z = stdlib_base_float16_sub( v, w );
printf( "%f - %f = %f\n", stdlib_base_float16_to_float32( v ), stdlib_base_float16_to_float32( w ), stdlib_base_float16_to_float32( z ) );
}
}