assert/is-almost-same-array at main · stdlib-js/assert · GitHub
Skip to content

Latest commit

 

History

History

Folders and files

README.md

isAlmostSameArray

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

Usage

var isAlmostSameArray = require( '@stdlib/assert/is-almost-same-array' );

isAlmostSameArray( v1, v2, maxULP )

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

var EPS = require( '@stdlib/constants/float64/eps' );

var x = [ 1.0, 2.0 ];
var y = [ 1.0+EPS, 2.0 ];

var bool = isAlmostSameArray( x, y, 0 );
// returns false

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

bool = isAlmostSameArray( x, [ -1.0, 2.0 ], 1 );
// returns false

Examples

var isAlmostSameArray = require( '@stdlib/assert/is-almost-same-array' );

var x = [ 1.0, 2.0, 3.0 ];
var y = [ 1.0, 2.0, 3.0 ];
var out = isAlmostSameArray( x, y, 0 );
// returns true

x = [ -0.0, 0.0, -0.0 ];
y = [ 0.0, -0.0, 0.0 ];
out = isAlmostSameArray( x, y, 0 );
// returns false

x = [ NaN, NaN, NaN ];
y = [ NaN, NaN, NaN ];
out = isAlmostSameArray( x, y, 0 );
// returns true