Skip to content

Latest commit

 

History

History
125 lines (76 loc) · 2.83 KB

File metadata and controls

125 lines (76 loc) · 2.83 KB

isSameValue

Test if two half-precision floating-point numbers are the same value.

Usage

var isSameValue = require( '@stdlib/number/float16/base/assert/is-same-value' );

isSameValue( a, b )

Tests if two half-precision floating-point numbers a and b are the same value.

var toFloat16 = require( '@stdlib/number/float64/base/to-float16' );

var bool = isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) );
// returns true

bool = isSameValue( toFloat16( 5.0 ), toFloat16( 3.0 ) );
// returns false

In contrast to the strict equality operator ===, the function distinguishes between +0 and -0 and treats NaNs as the same value.

var bool = ( 0.0 === -0.0 );
// returns true

bool = isSameValue( 0.0, -0.0 );
// returns false

bool = isSameValue( -0.0, -0.0 );
// returns true

bool = ( NaN === NaN );
// returns false

bool = isSameValue( NaN, NaN );
// returns true

Notes

Examples

var toFloat16 = require( '@stdlib/number/float64/base/to-float16' );
var isSameValue = require( '@stdlib/number/float16/base/assert/is-same-value' );

var bool = isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) );
// returns true

bool = isSameValue( toFloat16( 0.0 ), toFloat16( 0.0 ) );
// returns true

bool = isSameValue( toFloat16( -0.0 ), toFloat16( 0.0 ) );
// returns false

bool = isSameValue( toFloat16( NaN ), toFloat16( NaN ) );
// returns true