1.1.1 • Published 10 years ago
allclose v1.1.1
allclose
Compare numbers, arrays, or nested arrays for equality up to some tolerance. Checks both shapes and values. Uses almost-equal and generalizes array-almost-equal. Useful when working with lists of coordinates and other numerical data.
install
use npm
npm install allcloseusage
allclose(a, b, [atol], [rtol])
requires two numbers or arrays or nested arrays a and b, and optionally an absolute tolerance atol and a relative tolerance rtol. returns true if a and b have the same shape and value, and false otherwise.
examples
you can test numbers
allclose(1, 1)
> true
allclose(1, 2)
> falseor arrays
allclose([1, 2], [1, 2])
> true
allclose([1, 2], [1, 2, 3])
> false
allclose([1, 2], [1, 3])
> falseor nested arrays
allclose([[1, 2], [3, 4]], [[1, 2], [3, 4]])
> true
allclose([[1, 2], [3, 4]], [[1, 2], [3, 4], [5, 6]])
> false
allclose([[1, 2], [3, 4]], [[1, 2], [3, 5]])
> falseand you can optionally specify a tolerance
allclose([1, 2], [1, 2.1])
> false
allclose([1, 2], [1, 2.1], 0.2)
> true