feat: add C implementation for math/base/special/heaviside#6823
feat: add C implementation for math/base/special/heaviside#6823sahil20021008 wants to merge 5 commits intostdlib-js:developfrom
math/base/special/heaviside#6823Conversation
---
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: passed
- 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: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
---
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: na
- 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: passed
- 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
---
---
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: na
- 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
---
math/base/special/heaviside
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2018 The Stdlib Authors. | ||
| Copyright (c) 2025 The Stdlib Authors. |
There was a problem hiding this comment.
| Copyright (c) 2025 The Stdlib Authors. | |
| Copyright (c) 2018 The Stdlib Authors. |
There was a problem hiding this comment.
We can avoid updating copyright years for pre-existing files.
| # @license Apache-2.0 | ||
| # | ||
| # Copyright (c) 2018 The Stdlib Authors. | ||
| # Copyright (c) 2025 The Stdlib Authors. |
There was a problem hiding this comment.
| # Copyright (c) 2025 The Stdlib Authors. | |
| # Copyright (c) 2018 The Stdlib Authors. |
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2018 The Stdlib Authors. | ||
| * Copyright (c) 2025 The Stdlib Authors. |
There was a problem hiding this comment.
| * Copyright (c) 2025 The Stdlib Authors. | |
| * Copyright (c) 2018 The Stdlib Authors. |
| // The function returns a number... | ||
| { | ||
| heaviside( 3.141592653589793 ); // $ExpectType number | ||
| heaviside( 3.141592653589793, 'half-maximum' ); // $ExpectType number |
There was a problem hiding this comment.
I don't think this is necessary, @sahil20021008. We want to demonstrate the default case here, without the second argument, such as the function is discontinuous at 0.
| * @param x input value | ||
| * @param continuity continuity option | ||
| * @return function value |
|
|
||
| #### stdlib_base_heaviside( x ) | ||
|
|
||
| Evaluate the [Heaviside function][heaviside-function]. |
There was a problem hiding this comment.
| Evaluate the [Heaviside function][heaviside-function]. | |
| Evaluates the [Heaviside function][heaviside-function]. |
| #include "stdlib/math/base/special/heaviside.h" | ||
| ``` | ||
|
|
||
| #### stdlib_base_heaviside( x ) |
There was a problem hiding this comment.
| #### stdlib_base_heaviside( x ) | |
| #### stdlib_base_heaviside( x, continuity ) |
| if ( stdlib_base_is_nan( x )) { | ||
| return 0.0/0.0; | ||
| } | ||
| if ( x > 0.0 ) { | ||
| return 1.0; | ||
| } | ||
| if ( x == 0.0 ) { | ||
| if ( continuity == 0 ) { | ||
| return 0.0; | ||
| }else if ( continuity == 1 ) { | ||
| return 1.0; | ||
| }else if ( continuity == 2 ) { | ||
| return 0.5; | ||
| } | ||
| // Default behaviour is discontinuity | ||
| return 0.0/0.0; |
There was a problem hiding this comment.
Spacing is off at certain places here, will need to be fixed.
There was a problem hiding this comment.
Not exactly sure where the placing has to be improved
For now, I have fixed placing at line 58, but please lmk if changes required anywhere else also.
Thanks
---
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: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- 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: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
sahil20021008
left a comment
There was a problem hiding this comment.
Hi @gunjjoshi
I have addressed your review comments.
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2018 The Stdlib Authors. | ||
| Copyright (c) 2025 The Stdlib Authors. |
| #include "stdlib/math/base/special/heaviside.h" | ||
| ``` | ||
|
|
||
| #### stdlib_base_heaviside( x ) |
|
|
||
| #### stdlib_base_heaviside( x ) | ||
|
|
||
| Evaluate the [Heaviside function][heaviside-function]. |
| # @license Apache-2.0 | ||
| # | ||
| # Copyright (c) 2018 The Stdlib Authors. | ||
| # Copyright (c) 2025 The Stdlib Authors. |
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2018 The Stdlib Authors. | ||
| * Copyright (c) 2025 The Stdlib Authors. |
| // The function returns a number... | ||
| { | ||
| heaviside( 3.141592653589793 ); // $ExpectType number | ||
| heaviside( 3.141592653589793, 'half-maximum' ); // $ExpectType number |
| * @param x input value | ||
| * @param continuity continuity option | ||
| * @return function value |
| if ( stdlib_base_is_nan( x )) { | ||
| return 0.0/0.0; | ||
| } | ||
| if ( x > 0.0 ) { | ||
| return 1.0; | ||
| } | ||
| if ( x == 0.0 ) { | ||
| if ( continuity == 0 ) { | ||
| return 0.0; | ||
| }else if ( continuity == 1 ) { | ||
| return 1.0; | ||
| }else if ( continuity == 2 ) { | ||
| return 0.5; | ||
| } | ||
| // Default behaviour is discontinuity | ||
| return 0.0/0.0; |
There was a problem hiding this comment.
Not exactly sure where the placing has to be improved
For now, I have fixed placing at line 58, but please lmk if changes required anywhere else also.
Thanks
|
Receiving the following error while using have used |
---
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: na
- 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
---
|
Ref: #10196 |
|
Thank you for working on this pull request. However, we cannot accept your contribution as the issue this pull request seeks to resolve has already been addressed in a different pull request or commit. Thank you again for your interest in stdlib, and we look forward to reviewing your future contributions. |
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves #1891 .
Description
This pull request:
stdlib/math/base/special/heaviside. This includes benchmarks, examples, tests, README files, etc.Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers