Skip to content

Commit ae3c95d

Browse files
committed
fix: update implementation to follow the C99 standard
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0f68b5c commit ae3c95d

File tree

5 files changed

+61
-64
lines changed

5 files changed

+61
-64
lines changed

lib/node_modules/@stdlib/math/base/special/cabs/lib/main.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
// MODULES //
2222

2323
var hypot = require( '@stdlib/math/base/special/hypot' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var isInfinite = require( '@stdlib/math/base/assert/is-infinite' );
26-
var PINF = require( '@stdlib/constants/float64/pinf' );
2724
var real = require( '@stdlib/complex/float64/real' );
2825
var imag = require( '@stdlib/complex/float64/imag' );
2926

@@ -43,12 +40,6 @@ var imag = require( '@stdlib/complex/float64/imag' );
4340
* // returns ~5.83
4441
*/
4542
function cabs( z ) {
46-
if ( isnan( real( z ) ) || isnan( imag( z ) ) ) {
47-
return NaN;
48-
}
49-
if ( isInfinite( real( z ) ) || isInfinite( imag( z ) ) ) {
50-
return PINF;
51-
}
5243
return hypot( real( z ), imag( z ) );
5344
}
5445

lib/node_modules/@stdlib/math/base/special/cabs/manifest.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
"@stdlib/math/base/napi/unary",
4040
"@stdlib/complex/float64/ctor",
4141
"@stdlib/complex/float64/reim",
42-
"@stdlib/math/base/special/hypot",
43-
"@stdlib/math/base/assert/is-nan",
44-
"@stdlib/math/base/assert/is-infinite",
45-
"@stdlib/constants/float64/pinf"
42+
"@stdlib/math/base/special/hypot"
4643
]
4744
},
4845
{
@@ -58,10 +55,7 @@
5855
"dependencies": [
5956
"@stdlib/complex/float64/ctor",
6057
"@stdlib/complex/float64/reim",
61-
"@stdlib/math/base/special/hypot",
62-
"@stdlib/math/base/assert/is-nan",
63-
"@stdlib/math/base/assert/is-infinite",
64-
"@stdlib/constants/float64/pinf"
58+
"@stdlib/math/base/special/hypot"
6559
]
6660
},
6761
{
@@ -77,10 +71,7 @@
7771
"dependencies": [
7872
"@stdlib/complex/float64/ctor",
7973
"@stdlib/complex/float64/reim",
80-
"@stdlib/math/base/special/hypot",
81-
"@stdlib/math/base/assert/is-nan",
82-
"@stdlib/math/base/assert/is-infinite",
83-
"@stdlib/constants/float64/pinf"
74+
"@stdlib/math/base/special/hypot"
8475
]
8576
}
8677
]

lib/node_modules/@stdlib/math/base/special/cabs/src/main.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
#include "stdlib/math/base/special/cabs.h"
2020
#include "stdlib/math/base/special/hypot.h"
21-
#include "stdlib/math/base/assert/is_nan.h"
22-
#include "stdlib/math/base/assert/is_infinite.h"
23-
#include "stdlib/constants/float64/pinf.h"
2421
#include "stdlib/complex/float64/ctor.h"
2522
#include "stdlib/complex/float64/reim.h"
2623

@@ -43,11 +40,5 @@ double stdlib_base_cabs( const stdlib_complex128_t z ) {
4340
double im;
4441
stdlib_complex128_reim( z, &re, &im );
4542

46-
if ( stdlib_base_is_nan( re ) || stdlib_base_is_nan( im ) ) {
47-
return 0.0 / 0.0; // NaN
48-
}
49-
if ( stdlib_base_is_infinite( re ) || stdlib_base_is_infinite( im ) ) {
50-
return STDLIB_CONSTANT_FLOAT64_PINF;
51-
}
5243
return stdlib_base_hypot( re, im );
5344
}

lib/node_modules/@stdlib/math/base/special/cabs/test/test.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,7 @@ tape( 'the function computes the absolute value of a complex number', function t
6969
t.end();
7070
});
7171

72-
tape( 'if either the real or imaginary component is `NaN`, the function returns `NaN`', function test( t ) {
73-
var v;
74-
75-
v = cabs( new Complex128( NaN, 3.0 ) );
76-
t.strictEqual( isnan( v ), true, 'returns expected value' );
77-
78-
v = cabs( new Complex128( 5.0, NaN ) );
79-
t.strictEqual( isnan( v ), true, 'returns expected value' );
80-
81-
v = cabs( new Complex128( NaN, NaN ) );
82-
t.strictEqual( isnan( v ), true, 'returns expected value' );
83-
84-
t.end();
85-
});
86-
87-
tape( 'if either the real or imaginary component is `+Infinity`, the function returns `+Infinity`', function test( t ) {
72+
tape( 'if either the real or imaginary component is `+infinity`, the function returns `+infinity`', function test( t ) {
8873
var v;
8974

9075
v = cabs( new Complex128( PINF, 3.0 ) );
@@ -96,10 +81,16 @@ tape( 'if either the real or imaginary component is `+Infinity`, the function re
9681
v = cabs( new Complex128( PINF, PINF ) );
9782
t.strictEqual( v, PINF, 'returns expected value' );
9883

84+
v = cabs( new Complex128( NaN, PINF ) );
85+
t.strictEqual( v, PINF, 'returns expected value' );
86+
87+
v = cabs( new Complex128( PINF, NaN ) );
88+
t.strictEqual( v, PINF, 'returns expected value' );
89+
9990
t.end();
10091
});
10192

102-
tape( 'if either the real or imaginary component is `-Infinity`, the function returns `+Infinity`', function test( t ) {
93+
tape( 'if either the real or imaginary component is `-infinity`, the function returns `+infinity`', function test( t ) {
10394
var v;
10495

10596
v = cabs( new Complex128( NINF, 3.0 ) );
@@ -111,5 +102,26 @@ tape( 'if either the real or imaginary component is `-Infinity`, the function re
111102
v = cabs( new Complex128( NINF, NINF ) );
112103
t.strictEqual( v, PINF, 'returns expected value' );
113104

105+
v = cabs( new Complex128( NaN, NINF ) );
106+
t.strictEqual( v, PINF, 'returns expected value' );
107+
108+
v = cabs( new Complex128( NINF, NaN ) );
109+
t.strictEqual( v, PINF, 'returns expected value' );
110+
111+
t.end();
112+
});
113+
114+
tape( 'if either the real or imaginary component is `NaN` but not `+-infinity`, the function returns `NaN`', function test( t ) {
115+
var v;
116+
117+
v = cabs( new Complex128( NaN, 3.0 ) );
118+
t.strictEqual( isnan( v ), true, 'returns expected value' );
119+
120+
v = cabs( new Complex128( 5.0, NaN ) );
121+
t.strictEqual( isnan( v ), true, 'returns expected value' );
122+
123+
v = cabs( new Complex128( NaN, NaN ) );
124+
t.strictEqual( isnan( v ), true, 'returns expected value' );
125+
114126
t.end();
115127
});

lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,7 @@ tape( 'the function computes the absolute value of a complex number', opts, func
7878
t.end();
7979
});
8080

81-
tape( 'if either the real or imaginary component is `NaN`, the function returns `NaN`', opts, function test( t ) {
82-
var v;
83-
84-
v = cabs( new Complex128( NaN, 3.0 ) );
85-
t.strictEqual( isnan( v ), true, 'returns expected value' );
86-
87-
v = cabs( new Complex128( 5.0, NaN ) );
88-
t.strictEqual( isnan( v ), true, 'returns expected value' );
89-
90-
v = cabs( new Complex128( NaN, NaN ) );
91-
t.strictEqual( isnan( v ), true, 'returns expected value' );
92-
93-
t.end();
94-
});
95-
96-
tape( 'if either the real or imaginary component is `+Infinity`, the function returns `+Infinity`', opts, function test( t ) {
81+
tape( 'if either the real or imaginary component is `+infinity`, the function returns `+infinity`', opts, function test( t ) {
9782
var v;
9883

9984
v = cabs( new Complex128( PINF, 3.0 ) );
@@ -105,10 +90,16 @@ tape( 'if either the real or imaginary component is `+Infinity`, the function re
10590
v = cabs( new Complex128( PINF, PINF ) );
10691
t.strictEqual( v, PINF, 'returns expected value' );
10792

93+
v = cabs( new Complex128( NaN, PINF ) );
94+
t.strictEqual( v, PINF, 'returns expected value' );
95+
96+
v = cabs( new Complex128( PINF, NaN ) );
97+
t.strictEqual( v, PINF, 'returns expected value' );
98+
10899
t.end();
109100
});
110101

111-
tape( 'if either the real or imaginary component is `-Infinity`, the function returns `+Infinity`', opts, function test( t ) {
102+
tape( 'if either the real or imaginary component is `-infinity`, the function returns `+infinity`', opts, function test( t ) {
112103
var v;
113104

114105
v = cabs( new Complex128( NINF, 3.0 ) );
@@ -120,5 +111,26 @@ tape( 'if either the real or imaginary component is `-Infinity`, the function re
120111
v = cabs( new Complex128( NINF, NINF ) );
121112
t.strictEqual( v, PINF, 'returns expected value' );
122113

114+
v = cabs( new Complex128( NaN, NINF ) );
115+
t.strictEqual( v, PINF, 'returns expected value' );
116+
117+
v = cabs( new Complex128( NINF, NaN ) );
118+
t.strictEqual( v, PINF, 'returns expected value' );
119+
120+
t.end();
121+
});
122+
123+
tape( 'if either the real or imaginary component is `NaN` but not `+-infinity`, the function returns `NaN`', opts, function test( t ) {
124+
var v;
125+
126+
v = cabs( new Complex128( NaN, 3.0 ) );
127+
t.strictEqual( isnan( v ), true, 'returns expected value' );
128+
129+
v = cabs( new Complex128( 5.0, NaN ) );
130+
t.strictEqual( isnan( v ), true, 'returns expected value' );
131+
132+
v = cabs( new Complex128( NaN, NaN ) );
133+
t.strictEqual( isnan( v ), true, 'returns expected value' );
134+
123135
t.end();
124136
});

0 commit comments

Comments
 (0)