Skip to content

feat: add C implementation for math/base/special/heaviside #6972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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 @@ -214,6 +214,8 @@ The `continuity` parameter may be one of the following values:
- `STDLIB_BASE_HEAVISIDE_CONTINUITY_RIGHT_CONTINUOUS`: if `x == 0`, the function returns `1.0`.
- `STDLIB_BASE_HEAVISIDE_CONTINUITY_DISCONTINUOUS`: if `x == 0`, the function returns `NaN`.

If not provided a valid `continuity` parameter, the function returns `NaN` for `x == 0`, behaving like the discontinuous case.

```c
double stdlib_base_heaviside( const double x, const STDLIB_BASE_HEAVISIDE_CONTINUITY continuity );
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var ENUM = enumeration();
*/
function str2enum( ctype ) {
var v = ENUM[ ctype ];
return ( typeof v === 'number' ) ? v : null; // note: we include this guard to prevent walking the prototype chain
return ( typeof v === 'number' ) ? v : -1; // note: we include this guard to prevent walking the prototype chain
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ tape( 'if the `continuity` option is `right-continuous`, the function returns `1
t.end();
});

tape( 'if the `continuity` option is not valid, the function returns `NaN` if provided `+-0`', opts, function test( t ) {
var v;

v = heaviside( -0.0, 'foo' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = heaviside( +0.0, 'bar' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
var v = heaviside( NaN, 'left-continuous' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
Expand Down