Skip to content

Conversation

@Amansingh0807
Copy link
Contributor

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 none

Description

What is the purpose of this pull request?

This pull request:

  • add constants/float64/inv-two-pi

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • 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.

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

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 12, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 12, 2025

Coverage Report

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

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

@Amansingh0807
Copy link
Contributor Author

Hi @Neerajpathak07!
Just wanted to let you know that I have added the single precision and double precision versions of inv-two-pi as discussed.
Everything is pushed and the PRs are ready.
Let me know if you'd like anything adjusted.

* @default 0.15915494309189535
* @see [Wikipedia]{@link https://en.wikipedia.org/wiki/Pi}
*/
var FLOAT64_INV_TWO_PI = 0.15915494309189533576888376337251436203445964574045644874766734405889679763422653509534861042142103174415371554; // eslint-disable-line max-len
Copy link
Member

@Neerajpathak07 Neerajpathak07 Dec 12, 2025

Choose a reason for hiding this comment

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

Why is the value exceeding the precision limit. The return value should be the same as the set default value.

* @default 0.15915494309189535
* @see [Wikipedia]{@link https://en.wikipedia.org/wiki/Pi}
*/
var FLOAT64_INV_TWO_PI = 0.15915494309189533576888376337251436203445964574045644874766734405889679763422653509534861042142103174415371554; // eslint-disable-line max-len
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var FLOAT64_INV_TWO_PI = 0.15915494309189533576888376337251436203445964574045644874766734405889679763422653509534861042142103174415371554; // eslint-disable-line max-len
var FLOAT64_INV_TWO_PI = 0.15915494309189535;

/**
* Macro for the inverse of 2π (1/(2π)).
*/
#define STDLIB_CONSTANT_FLOAT64_INV_TWO_PI 0.15915494309189533577
Copy link
Member

Choose a reason for hiding this comment

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

Why is the C header file giving out different return value.

Copy link
Member

@Neerajpathak07 Neerajpathak07 Dec 12, 2025

Choose a reason for hiding this comment

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

I'm interested in knowing where this value is coming from did you take any reference you would like to share?

@Amansingh0807
Copy link
Contributor Author

Thanks for the review @Neerajpathak07!

Regarding the long value: It is actually the arbitrary-precision decimal expansion of 1 / (2π). It wasn't calculated using the standard Math.PI, but generated using a high-precision tool (mpmath) to ensure the literal is the exact mathematical "source of truth".

The value in the C header (...3577) appears to be the same value but rounded to 20 decimal places (since the next digit in the expansion is 8, it rounded up ...76 to ...77).

However, I agree with you for practical float64 representation in JS, the truncated version avoids confusion. I have updated the value to match the standard 15-17 digit precision as suggested.

</section>

<!-- /.related -->

Copy link
Member

Choose a reason for hiding this comment

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

Since you have added an C header file you'll have to add the documentation for C usage as well. To address the macro version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants