Skip to content

Commit 83bec65

Browse files
committed
refactor: add explicit NaN check
--- 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: na - 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 9f18e41 commit 83bec65

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"@stdlib/math/base/assert/is-even",
4141
"@stdlib/constants/float64/pinf",
4242
"@stdlib/constants/float64/max-nth-double-factorial",
43-
"@stdlib/math/base/assert/is-nonnegative-integer"
43+
"@stdlib/math/base/assert/is-nonnegative-integer",
44+
"@stdlib/math/base/assert/is-nan"
4445
]
4546
},
4647
{
@@ -57,7 +58,8 @@
5758
"@stdlib/math/base/assert/is-even",
5859
"@stdlib/constants/float64/pinf",
5960
"@stdlib/constants/float64/max-nth-double-factorial",
60-
"@stdlib/math/base/assert/is-nonnegative-integer"
61+
"@stdlib/math/base/assert/is-nonnegative-integer",
62+
"@stdlib/math/base/assert/is-nan"
6163
]
6264
},
6365
{
@@ -74,7 +76,8 @@
7476
"@stdlib/math/base/assert/is-even",
7577
"@stdlib/constants/float64/pinf",
7678
"@stdlib/constants/float64/max-nth-double-factorial",
77-
"@stdlib/math/base/assert/is-nonnegative-integer"
79+
"@stdlib/math/base/assert/is-nonnegative-integer",
80+
"@stdlib/math/base/assert/is-nan"
7881
]
7982
}
8083
]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "stdlib/math/base/special/factorial2.h"
2020
#include "stdlib/math/base/assert/is_even.h"
21+
#include "stdlib/math/base/assert/is_nan.h"
2122
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
2223
#include "stdlib/constants/float64/pinf.h"
2324
#include "stdlib/constants/float64/max_nth_double_factorial.h"
@@ -37,7 +38,8 @@ double stdlib_base_factorial2( const double n ) {
3738
double out;
3839
double v;
3940
double i;
40-
if ( !stdlib_base_is_nonnegative_integer( n ) ) {
41+
42+
if ( stdlib_base_is_nan( n ) || !stdlib_base_is_nonnegative_integer( n ) ) {
4143
return 0.0 / 0.0; // NaN
4244
}
4345
if ( n > STDLIB_CONSTANT_FLOAT64_MAX_NTH_DOUBLE_FACTORIAL ) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var incrspace = require( '@stdlib/array/base/incrspace' );
2727
var PINF = require( '@stdlib/constants/float64/pinf' );
28+
var NINF = require( '@stdlib/constants/float64/ninf' );
2829
var tryRequire = require( '@stdlib/utils/try-require' );
2930

3031

@@ -62,6 +63,24 @@ tape( 'if provided a negative integer, the function returns `NaN`', opts, functi
6263
t.end();
6364
});
6465

66+
tape( 'if provided negative infinity, the function returns `NaN`', opts, function test( t ) {
67+
var v = factorial2( NINF );
68+
t.strictEqual( isnan( v ), true, 'returns expected value' );
69+
t.end();
70+
});
71+
72+
tape( 'if provided positive infinity, the function returns `+infinity`', opts, function test( t ) {
73+
var v = factorial2( PINF );
74+
t.strictEqual( v, PINF, 'returns expected value' );
75+
t.end();
76+
});
77+
78+
tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
79+
var v = factorial2( NaN );
80+
t.strictEqual( isnan( v ), true, 'returns expected value' );
81+
t.end();
82+
});
83+
6584
tape( 'the function evaluates the double factorial', opts, function test( t ) {
6685
var expected;
6786
var x;

0 commit comments

Comments
 (0)