Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var imag = require( '@stdlib/complex/float32/imag' );
* // returns ~5.83
*/
function cabsf( 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 hypotf( real( z ), imag( z ) );
}

Expand Down
46 changes: 45 additions & 1 deletion lib/node_modules/@stdlib/math/base/special/cabsf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
var tape = require( 'tape' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var absf = require( '@stdlib/math/base/special/absf' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var cabsf = require( './../lib' );
Expand Down Expand Up @@ -67,7 +69,49 @@ 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 = cabsf( new Complex64( PINF, 3.0 ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 5.0, PINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( PINF, PINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( NaN, PINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 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 = cabsf( new Complex64( NINF, 3.0 ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 5.0, NINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( NINF, NINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( NaN, NINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 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 = cabsf( new Complex64( NaN, 3.0 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var absf = require( '@stdlib/math/base/special/absf' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var tryRequire = require( '@stdlib/utils/try-require' );
Expand Down Expand Up @@ -76,7 +78,49 @@ 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 = cabsf( new Complex64( PINF, 3.0 ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 5.0, PINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( PINF, PINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( NaN, PINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 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 = cabsf( new Complex64( NINF, 3.0 ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 5.0, NINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( NINF, NINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( NaN, NINF ) );
t.strictEqual( v, PINF, 'returns expected value' );

v = cabsf( new Complex64( 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 = cabsf( new Complex64( NaN, 3.0 ) );
Expand Down