Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

hasAlmostSameValues

Test if two arrays have respective elements which are approximately the same value within a specified number of ULPs (units in the last place).

Usage

var hasAlmostSameValues = require( '@stdlib/array/base/assert/has-almost-same-values' );

hasAlmostSameValues( x, y, maxULP )

Tests if two arrays have respective elements which are approximately the same value within a specified number of ULPs (units in the last place).

var x = [ 0, 0, 1, 0 ];
var y = [ 0, 0, 1, 0 ];

var bool = hasAlmostSameValues( x, y, 1 );
// returns true

Notes

  • In contrast to the strict equality operator ===, the function distinguishes between +0 and -0 and treats NaNs as the same value.
  • If provided arrays of unequal length, the function returns false.
  • The function does not skip undefined elements and is thus not optimized for sparse arrays.

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var Complex128Array = require( '@stdlib/array/complex128' );
var hasAlmostSameValues = require( '@stdlib/array/base/assert/has-almost-same-values' );

var buf = uniform( 10, 0, 10 );
// returns <Float64Array>

var x = new Complex128Array( buf );
// returns <Complex128Array>

var y = new Complex128Array( buf );
// returns <Complex128Array>

var out = hasAlmostSameValues( x, y, 1 );
// returns true