Test if two arguments are approximately the same value within a specified number of ULPs (units in the last place).
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );Tests if two arguments are approximately the same value within a specified number of ULPs (units in the last place).
var EPS = require( '@stdlib/constants/float64/eps' );
var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 );
// returns true
bool = isAlmostSameValue( '', '', 0 );
// returns true
bool = isAlmostSameValue( {}, {}, 1 );
// returns falseIn contrast to the strict equality operator ===, the function distinguishes between +0 and -0 and treats NaNs as the same value.
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var bool = isAlmostSameValue( NaN, 1.0, 1 );
// returns false
bool = isAlmostSameValue( NaN, NaN, 1 );
// returns true
var z1 = new Complex128( NaN, 3.0 );
var z2 = new Complex128( 1.0, 3.0 );
bool = isAlmostSameValue( z1, z2, 1 );
// returns false
z1 = new Complex128( NaN, NaN );
z2 = new Complex128( NaN, NaN );
bool = isAlmostSameValue( z1, z2, 1 );
// returns true
bool = isAlmostSameValue( 0.0, -0.0, 0 );
// returns false
z1 = new Complex128( 0.0, 0.0 );
z2 = new Complex128( -0.0, -0.0 );
bool = isAlmostSameValue( z1, z2, 0 );
// returns false- The function implements the SameValue Algorithm as specified in ECMAScript 5.
var EPS = require( '@stdlib/constants/float64/eps' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
console.log( isAlmostSameValue( true, true, 0 ) );
// => true
console.log( isAlmostSameValue( true, false, 1 ) );
// => false
console.log( isAlmostSameValue( 'beep', 'beep', 1 ) );
// => true
console.log( isAlmostSameValue( 1.0, 1.0+EPS, 1 ) );
// => true
console.log( isAlmostSameValue( null, null, 0 ) );
// => true
console.log( isAlmostSameValue( 0.0, -0.0, 0 ) );
// => false
console.log( isAlmostSameValue( NaN, NaN, 1 ) );
// => true
var z1 = new Complex128( 1.0, 3.0+EPS );
var z2 = new Complex128( 1.0+EPS, 3.0 );
console.log( isAlmostSameValue( z1, z2, 1 ) );
// => true
console.log( isAlmostSameValue( {}, {}, 1 ) );
// => false
console.log( isAlmostSameValue( [], [], 1 ) );
// => false
console.log( isAlmostSameValue( isAlmostSameValue, isAlmostSameValue, 0 ) );
// => true