Skip to content

Comments

feat: add constants/float16/inv-pi#8931

Open
Amansingh0807 wants to merge 2 commits intostdlib-js:developfrom
Amansingh0807:feat-float16-inv-pi-clean
Open

feat: add constants/float16/inv-pi#8931
Amansingh0807 wants to merge 2 commits intostdlib-js:developfrom
Amansingh0807:feat-float16-inv-pi-clean

Conversation

@Amansingh0807
Copy link
Contributor

@Amansingh0807 Amansingh0807 commented Dec 10, 2025

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: passed
task: lint_javascript_src status: passed
task: lint_javascript_cli status: na
task: lint_javascript_examples status: passed
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: passed
task: lint_typescript_tests status: passed
task: lint_license_headers status: passed ---

Resolves #{{TODO: add issue number}}.

Description

What is the purpose of this pull request?

This pull request:

  • add constants/float16/inv-pi

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • #{{TODO: add related issue number}}

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.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".


@stdlib-js/reviewers

Add half-precision floating-point constant for 1/π (inverse of pi).

The constant value 0.31835937 is the closest half-precision
floating-point representation of the mathematical constant 1/π.

This addresses the missing float16 inverse constants noted in
issue stdlib-js#8920 and complements the recently added
float16 pi constant from PR stdlib-js#8919.

Implementation follows stdlib conventions:
- Package structure matches existing float16 constants
- Includes comprehensive documentation and examples
- Provides TypeScript definitions
- Includes test suite for validation
- Adds REPL documentation
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 10, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 10, 2025

Coverage Report

Package Statements Branches Functions Lines
constants/float16/inv-pi $\color{green}48/48$
$\color{green}+100.00%$
$\color{green}1/1$
$\color{green}+100.00%$
$\color{green}0/0$
$\color{green}+100.00%$
$\color{green}48/48$
$\color{green}+100.00%$

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

@Amansingh0807
Copy link
Contributor Author

Amansingh0807 commented Dec 12, 2025

Hi @Neerajpathak07,
While working on inv-two-pi across all precisions, I also noticed that inv-pi currently exists only in my open PR for float16.
If you think it makes sense, I can add the float32 and float64 versions as well once the float16 PR is merged or get review.
Just wanted to check before proceeding.

@Neerajpathak07
Copy link
Member

It's better to hold those for a while till we can get the PR's on inv-two-pi in.

@Neerajpathak07
Copy link
Member

One thing that's on top of my mind is that whether this package is necessary and if so which packages would we be needing this constant for.

@Amansingh0807
Copy link
Contributor Author

Amansingh0807 commented Dec 12, 2025

Thanks for the clarification, @Neerajpathak07!

Regarding the usefulness of inv-pi:

1/π appears quite frequently in numerical code, especially in :

  • probability distributions (e.g., Cauchy pdf: 1/(π * (1 + x²))),
  • Fourier/signal-processing normalizations, and
  • several special-function kernels where π or factors appear in denominators.

Having a dedicated constant avoids repeated divisions, ensures consistent rounding across precisions, and keeps the API parallel to existing constants like two-pi, and half-pi.

But yes, I am happy to wait until the inv-two-pi PRs land before proceeding further.

@kgryte kgryte added Feature Issue or pull request for adding a new feature. Needs Discussion Needs further discussion. labels Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. Needs Discussion Needs further discussion. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants