Skip to content
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

chore: use FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL #6363

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

anandkaranubc
Copy link
Contributor

Resolves None

Description

What is the purpose of this pull request?

This pull request:

  • Completes the TODO on replacing the magic number with FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves None

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

---
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: 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Mar 25, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Mar 25, 2025

Coverage Report

Package Statements Branches Functions Lines
math/base/special/factorial2 194 / 194
+ 100.00 %
19 / 19
+ 100.00 %
2 / 2
+ 100.00 %
194 / 194
+ 100.00 %

The above coverage report was generated for the changes in this PR.

Planeshifter
Planeshifter previously approved these changes Mar 25, 2025
Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @anandkaranubc!

@Planeshifter Planeshifter added the Ready To Merge A pull request which is ready to be merged. label Mar 25, 2025
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Mar 25, 2025
@stdlib-bot
Copy link
Contributor

PR Commit Message

chore: use `FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL`

PR-URL: https://github.com/stdlib-js/stdlib/pull/6363

Co-authored-by: Karan Anand <anandkarancompsci@gmail.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>

Please review the above commit message and make any necessary adjustments.

@anandkaranubc
Copy link
Contributor Author

anandkaranubc commented Mar 25, 2025

Thanks, @anandkaranubc!

Thanks for the review, @Planeshifter!

One quick question, I think we need to change the value of FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL from 301 to 300..?

In [18]: base.factorial2(301) <= FLOAT64_MAX
Out[18]: false

In [19]: base.factorial2(300) <= FLOAT64_MAX
Out[19]: true

var FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = 301|0; // eslint-disable-line id-length

Reference: factorial2(301) ≈ 1.13 × 10^309

In [34]: FLOAT64_MAX
Out[34]: 1.7976931348623157e+308

@Planeshifter
Copy link
Member

Planeshifter commented Mar 25, 2025

@anandkaranubc I believe you are correct.

cc @gunjjoshi @kgryte, as this constant was added in https://github.com/stdlib-js/stdlib/pull/2966/files. Maybe the inlined definition of MAX_FACTORIAL2 here was the source of the value of 301, or how was the maximum double factorial safely representable within IEEE-754 double-precision floating-point limits determined?

---
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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@anandkaranubc
Copy link
Contributor Author

The changes have been made according to the discussion in the OH.

cc: @Planeshifter @kgryte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Math Issue or pull request specific to math functionality. Ready To Merge A pull request which is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants