@stdlib/complex-float64-base-assert-is-almost-equal
v0.0.1
Published
Test whether two double-precision complex floating-point numbers are approximately equal within a specified number of ULPs (units in the last place).
Readme
isAlmostEqual
Test whether two double-precision complex floating-point numbers are approximately equal within a specified number of ULPs (units in the last place).
Installation
npm install @stdlib/complex-float64-base-assert-is-almost-equalUsage
var isAlmostEqual = require( '@stdlib/complex-float64-base-assert-is-almost-equal' );isAlmostEqual( z1, z2, maxULP )
Tests whether two double-precision complex floating-point numbers are approximately equal within a specified number of ULPs (units in the last place).
var EPS = require( '@stdlib/constants-float64-eps' );
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var z1 = new Complex128( 1.0, 3.0 );
var z2 = new Complex128( 1.0+EPS, 3.0 );
var out = isAlmostEqual( z1, z2, 0 );
// returns false
out = isAlmostEqual( z1, z2, 1 );
// returns trueThe function returns false if either input value has a NaN real or imaginary component.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var z1 = new Complex128( NaN, 3.0 );
var z2 = new Complex128( 1.0, 3.0 );
var out = isAlmostEqual( z1, z2, 1 );
// returns false
out = isAlmostEqual( z2, z1, 1 );
// returns false
z1 = new Complex128( NaN, NaN );
z2 = new Complex128( NaN, NaN );
out = isAlmostEqual( z1, z2, 1 );
// returns falseThe function does not distinguish between -0 and +0, treating them as equal.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var z1 = new Complex128( 0.0, 0.0 );
var z2 = new Complex128( -0.0, -0.0 );
var out = isAlmostEqual( z1, z2, 0 );
// returns trueExamples
var EPS = require( '@stdlib/constants-float64-eps' );
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var isAlmostEqual = require( '@stdlib/complex-float64-base-assert-is-almost-equal' );
var z1 = new Complex128( 1.0, 3.0+EPS );
var z2 = new Complex128( 1.0+EPS, 3.0 );
console.log( isAlmostEqual( z1, z2, 1 ) );
// => true
z1 = new Complex128( 1.0, 3.0+EPS );
z2 = new Complex128( 1.0+EPS+EPS, 3.0 );
console.log( isAlmostEqual( z1, z2, 1 ) );
// => false
z1 = new Complex128( 0.0, 0.0 );
z2 = new Complex128( -0.0, 0.0 );
console.log( isAlmostEqual( z1, z2, 0 ) );
// => true
z1 = new Complex128( NaN, 0.0 );
z2 = new Complex128( 1.0, 0.0 );
console.log( isAlmostEqual( z1, z2, 1 ) );
// => falseNotice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
