Skip to content

Commit c8a3c52

Browse files
committed
refactor: change fallback return value from null to -1 in str2enum
--- 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: passed - 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: na - 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 98f0d2b commit c8a3c52

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/node_modules/@stdlib/math/base/special/heaviside/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ The `continuity` parameter may be one of the following values:
214214
- `STDLIB_BASE_HEAVISIDE_CONTINUITY_RIGHT_CONTINUOUS`: if `x == 0`, the function returns `1.0`.
215215
- `STDLIB_BASE_HEAVISIDE_CONTINUITY_DISCONTINUOUS`: if `x == 0`, the function returns `NaN`.
216216

217+
If not provided a valid `continuity` parameter, the function returns `NaN` for `x == 0`, behaving like the discontinuous case.
218+
217219
```c
218220
double stdlib_base_heaviside( const double x, const STDLIB_BASE_HEAVISIDE_CONTINUITY continuity );
219221
```

lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var ENUM = enumeration();
4343
*/
4444
function str2enum( ctype ) {
4545
var v = ENUM[ ctype ];
46-
return ( typeof v === 'number' ) ? v : null; // note: we include this guard to prevent walking the prototype chain
46+
return ( typeof v === 'number' ) ? v : -1; // note: we include this guard to prevent walking the prototype chain
4747
}
4848

4949

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

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ tape( 'if the `continuity` option is `right-continuous`, the function returns `1
121121
t.end();
122122
});
123123

124+
tape( 'if the `continuity` option is not valid, the function returns `NaN` if provided `+-0`', opts, function test( t ) {
125+
var v;
126+
127+
v = heaviside( -0.0, 'foo' );
128+
t.strictEqual( isnan( v ), true, 'returns expected value' );
129+
130+
v = heaviside( +0.0, 'bar' );
131+
t.strictEqual( isnan( v ), true, 'returns expected value' );
132+
133+
t.end();
134+
});
135+
124136
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
125137
var v = heaviside( NaN, 'left-continuous' );
126138
t.strictEqual( isnan( v ), true, 'returns expected value' );

0 commit comments

Comments
 (0)