Skip to content

Commit 42ef0dd

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 83bec65 commit 42ef0dd

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/node_modules/@stdlib/math/base/special/factorial2f/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-evenf",
4141
"@stdlib/constants/float32/pinf",
4242
"@stdlib/constants/float32/max-nth-double-factorial",
43-
"@stdlib/math/base/assert/is-nonnegative-integerf"
43+
"@stdlib/math/base/assert/is-nonnegative-integerf",
44+
"@stdlib/math/base/assert/is-nanf"
4445
]
4546
},
4647
{
@@ -57,7 +58,8 @@
5758
"@stdlib/math/base/assert/is-evenf",
5859
"@stdlib/constants/float32/pinf",
5960
"@stdlib/constants/float32/max-nth-double-factorial",
60-
"@stdlib/math/base/assert/is-nonnegative-integerf"
61+
"@stdlib/math/base/assert/is-nonnegative-integerf",
62+
"@stdlib/math/base/assert/is-nanf"
6163
]
6264
},
6365
{
@@ -74,7 +76,8 @@
7476
"@stdlib/math/base/assert/is-evenf",
7577
"@stdlib/constants/float32/pinf",
7678
"@stdlib/constants/float32/max-nth-double-factorial",
77-
"@stdlib/math/base/assert/is-nonnegative-integerf"
79+
"@stdlib/math/base/assert/is-nonnegative-integerf",
80+
"@stdlib/math/base/assert/is-nanf"
7881
]
7982
}
8083
]

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

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

1919
#include "stdlib/math/base/special/factorial2f.h"
2020
#include "stdlib/math/base/assert/is_evenf.h"
21+
#include "stdlib/math/base/assert/is_nanf.h"
2122
#include "stdlib/constants/float32/pinf.h"
2223
#include "stdlib/constants/float32/max_nth_double_factorial.h"
2324
#include "stdlib/math/base/assert/is_nonnegative_integerf.h"
@@ -37,7 +38,7 @@ float stdlib_base_factorial2f( const float n ) {
3738
float out;
3839
float i;
3940

40-
if ( !stdlib_base_is_nonnegative_integerf( n ) ) {
41+
if ( stdlib_base_is_nanf( n ) || !stdlib_base_is_nonnegative_integerf( n ) ) {
4142
return 0.0f / 0.0f; // NaN
4243
}
4344
if ( n > STDLIB_CONSTANT_FLOAT32_MAX_NTH_DOUBLE_FACTORIAL ) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var absf = require( '@stdlib/math/base/special/absf' );
2727
var incrspace = require( '@stdlib/array/base/incrspace' );
2828
var PINF = require( '@stdlib/constants/float32/pinf' );
29+
var NINF = require( '@stdlib/constants/float32/ninf' );
2930
var EPS = require( '@stdlib/constants/float32/eps' );
3031
var tryRequire = require( '@stdlib/utils/try-require' );
3132

@@ -64,6 +65,24 @@ tape( 'if provided a negative integer, the function returns `NaN`', opts, functi
6465
t.end();
6566
});
6667

68+
tape( 'if provided negative infinity, the function returns `NaN`', opts, function test( t ) {
69+
var v = factorial2f( NINF );
70+
t.strictEqual( isnanf( v ), true, 'returns expected value' );
71+
t.end();
72+
});
73+
74+
tape( 'if provided positive infinity, the function returns `+infinity`', opts, function test( t ) {
75+
var v = factorial2f( PINF );
76+
t.strictEqual( v, PINF, 'returns expected value' );
77+
t.end();
78+
});
79+
80+
tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
81+
var v = factorial2f( NaN );
82+
t.strictEqual( isnanf( v ), true, 'returns expected value' );
83+
t.end();
84+
});
85+
6786
tape( 'the function evaluates the double factorial', opts, function test( t ) {
6887
var expected;
6988
var delta;

0 commit comments

Comments
 (0)