@stdlib/complex-base-assert-is-almost-same-value
v0.1.1
Published
Test whether two complex numbers are approximately the same value within a specified number of ULPs (units in the last place).
Readme
isAlmostSameValue
Test whether two complex numbers are approximately the same value within a specified number of ULPs (units in the last place).
Installation
npm install @stdlib/complex-base-assert-is-almost-same-valueUsage
var isAlmostSameValue = require( '@stdlib/complex-base-assert-is-almost-same-value' );isAlmostSameValue( z1, z2, maxULP )
Tests whether two complex numbers are approximately the same value 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 = isAlmostSameValue( z1, z2, 0 );
// returns false
out = isAlmostSameValue( z1, z2, 1 );
// returns trueIn 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 Complex64 = require( '@stdlib/complex-float32-ctor' );
var z1 = new Complex64( NaN, 3.0 );
var z2 = new Complex64( 1.0, 3.0 );
var out = isAlmostSameValue( z1, z2, 1 );
// returns false
out = isAlmostSameValue( z2, z1, 1 );
// returns false
z1 = new Complex64( NaN, NaN );
z2 = new Complex64( NaN, NaN );
out = isAlmostSameValue( z1, z2, 1 );
// returns true
z1 = new Complex128( 0.0, 0.0 );
z2 = new Complex64( -0.0, -0.0 );
out = isAlmostSameValue( z1, z2, 0 );
// returns falseNotes
- The function implements the SameValue Algorithm as specified in ECMAScript 5.
Examples
var EPS = require( '@stdlib/constants-float64-eps' );
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var isAlmostSameValue = require( '@stdlib/complex-base-assert-is-almost-same-value' );
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
z1 = new Complex128( 1.0, 3.0+EPS );
z2 = new Complex128( 1.0+EPS+EPS, 3.0 );
console.log( isAlmostSameValue( z1, z2, 1 ) );
// => false
z1 = new Complex128( 0.0, 0.0 );
z2 = new Complex128( -0.0, 0.0 );
console.log( isAlmostSameValue( z1, z2, 0 ) );
// => false
z1 = new Complex128( NaN, 0.0 );
z2 = new Complex128( 1.0, 0.0 );
console.log( isAlmostSameValue( 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.
