-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add math/base/special/atanhf
#9514
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
base: develop
Are you sure you want to change the base?
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
Signed-off-by: Harsh <[email protected]>
|
/stdlib lint-autofix |
@hrshya, the slash command failed to complete. Please check the workflow logs for details. |
Signed-off-by: Harsh <[email protected]>
Signed-off-by: Harsh <[email protected]>
Signed-off-by: Harsh <[email protected]>
| */ | ||
| static double benchmark( void ) { | ||
| double elapsed; | ||
| double x; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables x and y declared as double instead of float here.
| // VARIABLES // | ||
|
|
||
| var opts = { | ||
| 'skip': ( typeof Math.atanhf !== 'function' ) // eslint-disable-line stdlib/no-builtin-math |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.atanhf does not exist. Can only compare to Math.atanh.
| #include "stdlib/constants/float32/ninf.h" | ||
| #include <stdint.h> | ||
|
|
||
| static const float NEAR_ZERO = 1.0 / (1 << 28); // 2**-28 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static const float NEAR_ZERO = 1.0 / (1 << 28); // 2**-28 | |
| static const float NEAR_ZERO = 1.0f / (1 << 28); // 2**-28 |
| int i; | ||
| for ( i = 0; i < 10; i++ ) { | ||
| v = stdlib_base_atanhf( x[ i ] ); | ||
| printf( "atanhf(%lf) = %lf\n", x[ i ], v ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use %f instead of %lf.
| t.strictEqual( y, e, 'x: '+x[i]+'. E: '+e ); | ||
| } else { | ||
| delta = abs( y - e ); | ||
| tol = 1.3 * EPS * abs( e ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there are reason why the "small negative" test case uses 1.3 * EPS here but 1.0 * EPS in test.js line 123?
| NaN | ||
|
|
||
| See Also | ||
| -------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line after the See Also separator.
---
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: passed
- 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: passed
- 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: passed
- 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: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- 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: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
| /** | ||
| * Generates a random number on the interval [0,1). | ||
| * | ||
| * @return random number | ||
| */ | ||
| static float rand_float( void ) { | ||
| int r = rand(); | ||
| return (float)r / ( (float)RAND_MAX + 1.0f ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this to use random_uniform instead? You can refer to tanf for this
| x = ( 2.0f * rand_float() ) - 1.0f; | ||
| y = stdlib_base_atanhf( x ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done outside the loop. tanf is a good example to refer to.
| * | ||
| * @return random number | ||
| */ | ||
| static float rand_float( void ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment applies here and below, for random number generation.
| if ( y === e ) { | ||
| t.strictEqual( y, e, 'x: '+x[i]+'. E: '+e ); | ||
| } else { | ||
| delta = abs( y - e ); | ||
| tol = 1.3 * EPS * abs( e ); | ||
| t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. tol: '+tol+'.' ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor this to use assert/is-almost-same-value instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment applies below and for test.native.js
---
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: passed
- 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: passed
- 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: passed
- 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: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
| if ( y === e ) { | ||
| t.strictEqual( y, e, 'x: '+x[i]+'. E: '+e ); | ||
| } else { | ||
| delta = abs( y - e ); | ||
| tol = 1.3 * EPS * abs( e ); | ||
| t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. tol: '+tol+'.' ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment applies below and for test.native.js
Resolves none .
Description
This pull request:
math/base/special/atanhf.Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers