Skip to content

test: migrate constants/float32/pi-squared to ULP-based assertions - #16088

Merged
kgryte merged 2 commits into
developfrom
kgryte/ulp-constants-float32-pi-squared
Oct 13, 2026
Merged

kgryte merged 2 commits into
developfrom
kgryte/ulp-constants-float32-pi-squared

Conversation

@kgryte

@kgryte kgryte commented Oct 12, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

  • migrates the test suite for constants/float32/pi-squared from a relative tolerance assertion to a ULP difference assertion.

The export equals π² test previously computed delta = absf( FLOAT32_PI_SQUARED - v ) and tol = EPS * v and asserted with t.ok( delta <= tol, ... ). It now delegates to @stdlib/number/float32/base/assert/is-almost-same-value:

tape( 'export equals π²', function test( t ) {
	var v;

	v = float64ToFloat32( pow( PI, 2 ) );

	t.strictEqual( isAlmostSameValue( v, FLOAT32_PI_SQUARED, 1 ), true, 'returns expected value' );

	t.end();
});

Final ULP constant: 1.

File Call sites ULP bound
test/test.js 1 1

Notes on how the bound was measured:

  • The bound was tightened empirically by probing isAlmostSameValue( v, FLOAT32_PI_SQUARED, n ) for n = 0..8. n = 0 fails and n = 1 is the smallest value which passes, so 1 is the measured minimum.
  • The computed value is float64ToFloat32( pow( PI, 2 ) ) = 9.86960506439209, while the exported constant is 9.869604110717773, i.e., the two differ by exactly one single-precision ULP. The single-precision variant of the assertion is used here (matching the already-converted constants/float32/ln-two-pi, constants/float32/ln-ten, and constants/float32/half-ln-two) so that the ULP gap is measured in single-precision units.
  • The suite was run twice at the final bound to confirm determinism; all 4 assertions pass both times.
  • This package has no test.native.js, so there is no JS/C divergence to account for.
  • The two pre-existing exact assertions (typeof and the exact 9.869604110717773 value check) are intentionally left unchanged, as exact comparisons remain correct there.
  • Only the one test file is modified; no source, documentation, or fixture changes.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

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.

The bound is reproducible across architectures: the comparison is between two compile-time-fixed single-precision values and is not subject to FMA-contraction differences.

Note that the local make pre-commit EditorConfig check could not run in this environment (the editorconfig-checker binary download is network-blocked), so the changed file was verified manually for tabs-only indentation, no trailing whitespace, LF endings, and a final newline. make eslint-tests and make test for this package both pass.

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

This PR was authored by Claude Code. It studied the already-converted packages in the same family (notably constants/float32/ln-two-pi and constants/float64/ln-two-pi) to match the established idiom, then measured the minimum ULP bound empirically and verified determinism as described above.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01RWwXztzfFcS6UC8AYLZenG


Generated by Claude Code

Replace the relative tolerance assertion in the test suite with a ULP
difference assertion via
`@stdlib/number/float32/base/assert/is-almost-same-value`.

The measured minimum ULP bound is `1`.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RWwXztzfFcS6UC8AYLZenG

---
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: skipped
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - 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
---
@stdlib-bot

stdlib-bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
constants/float32/pi-squared $\\color{green}52/52$
$\\color{green}+0.00\\%$
$\\color{green}1/1$
$\\color{green}+0.00\\%$
$\\color{green}0/0$
$\\color{green}+0.00\\%$
$\\color{green}52/52$
$\\color{green}+0.00\\%$

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

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Oct 12, 2026
@kgryte kgryte added the Tests Pull requests specifically adding tests. label Oct 13, 2026
@kgryte
kgryte marked this pull request as ready for review October 13, 2026 10:45
@kgryte
kgryte requested a review from a team October 13, 2026 10:45
Signed-off-by: Athan <kgryte@gmail.com>
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 13, 2026
@kgryte
kgryte merged commit 5e18080 into develop Oct 13, 2026
28 checks passed
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue. Tests Pull requests specifically adding tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants