diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cabs/lib/main.js index 79503c4e63a2..70e4872deb88 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs/lib/main.js @@ -40,7 +40,6 @@ var imag = require( '@stdlib/complex/float64/imag' ); * // returns ~5.83 */ function cabs( z ) { - // TODO: consider whether to use C99 rules for special cases involving infinities and nans (see https://github.com/python/cpython/blob/f4c03484da59049eb62a9bf7777b963e2267d187/Objects/complexobject.c#L191) return hypot( real( z ), imag( z ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js index 801b6e32937f..6f21f97be530 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js @@ -23,6 +23,8 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); var abs = require( '@stdlib/math/base/special/abs' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var cabs = require( './../lib' ); @@ -67,17 +69,59 @@ tape( 'the function computes the absolute value of a complex number', function t t.end(); }); -tape( 'if either the real or imaginary component is `NaN`, the function returns `NaN`', function test( t ) { +tape( 'if either the real or imaginary component is `+infinity`, the function returns `+infinity`', function test( t ) { + var v; + + v = cabs( new Complex128( PINF, 3.0 ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( 5.0, PINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( PINF, PINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NaN, PINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( PINF, NaN ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either the real or imaginary component is `-infinity`, the function returns `+infinity`', function test( t ) { + var v; + + v = cabs( new Complex128( NINF, 3.0 ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( 5.0, NINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NINF, NINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NaN, NINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NINF, NaN ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either the real or imaginary component is `NaN` but not `+-infinity`, the function returns `NaN`', function test( t ) { var v; v = cabs( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js index 4000a697045d..959ba9d3a207 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js @@ -24,6 +24,8 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); var abs = require( '@stdlib/math/base/special/abs' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -76,17 +78,59 @@ tape( 'the function computes the absolute value of a complex number', opts, func t.end(); }); -tape( 'if either the real or imaginary component is `NaN`, the function returns `NaN`', opts, function test( t ) { +tape( 'if either the real or imaginary component is `+infinity`, the function returns `+infinity`', opts, function test( t ) { + var v; + + v = cabs( new Complex128( PINF, 3.0 ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( 5.0, PINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( PINF, PINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NaN, PINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( PINF, NaN ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either the real or imaginary component is `-infinity`, the function returns `+infinity`', opts, function test( t ) { + var v; + + v = cabs( new Complex128( NINF, 3.0 ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( 5.0, NINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NINF, NINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NaN, NINF ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + v = cabs( new Complex128( NINF, NaN ) ); + t.strictEqual( v, PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either the real or imaginary component is `NaN` but not `+-infinity`, the function returns `NaN`', opts, function test( t ) { var v; v = cabs( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); });