Multiply two half-precision floating-point numbers.
var mul = require( '@stdlib/number/float16/base/mul' );Multiplies two half-precision floating-point numbers.
var v = mul( -1.0, 5.0 );
// returns -5.0
v = mul( 2.0, 5.0 );
// returns 10.0
v = mul( 0.0, 5.0 );
// returns 0.0
v = mul( -0.0, 0.0 );
// returns -0.0
v = mul( 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 mul = require( '@stdlib/number/float16/base/mul' );
// Create arrays of random half-precision floating-point numbers:
var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
// Perform multiplication on half-precision floating-point numbers:
logEachMap( 'x: %f, y: %f => %f', x, y, mul );#include "stdlib/number/float16/base/mul.h"Multiplies 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_mul( 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_mul( const stdlib_float16_t x, const stdlib_float16_t y );#include "stdlib/number/float16/base/mul.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 a;
stdlib_float16_t b;
stdlib_float16_t z;
int i;
for ( i = 0; i < 4; i++ ) {
a = stdlib_base_float32_to_float16( x[ i ] );
b = stdlib_base_float32_to_float16( y[ i ] );
z = stdlib_base_float16_mul( a, b );
printf( "%f x %f = %f\n", stdlib_base_float16_to_float32( a ), stdlib_base_float16_to_float32( b ), stdlib_base_float16_to_float32( z ) );
}
}