Skip to content

test: migrate constants/float16/pi-squared to ULP-based assertions - #16170

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-constants-float16-pi-squared
Oct 15, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-constants-float16-pi-squared

Conversation

@kgryte

@kgryte kgryte commented Oct 15, 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/float16/pi-squared from a relative tolerance assertion to a ULP difference assertion.

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

tape( 'export equals π²', function test( t ) {
	var v = float64ToFloat16( pow( PI, 2 ) );
	t.strictEqual( isAlmostSameValue( v, FLOAT16_PI_SQUARED, 0 ), true, 'returns expected value' );
	t.end();
});

Final ULP constant: 0.

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

Notes on how the bound was measured:

  • The bound was tightened empirically, starting high and lowering. ulpDifference( v, FLOAT16_PI_SQUARED ) is exactly 0: the computed value float64ToFloat16( pow( PI, 2 ) ) and the exported constant are both 9.8671875, i.e., bit-identical in half-precision. 0 is therefore the measured minimum and no smaller bound exists.
  • Note that, per the implementation, maxULP === 0 short-circuits to isSameValue, so the final assertion is an exact (same-value) comparison. This matches the already-converted constants/float16/ln-ten, which likewise settled on 0.
  • The half-precision variant of the assertion is used here so that the ULP gap is measured in half-precision units, consistent with the other converted constants/float16/* packages (ln-ten, half-ln-two).
  • 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.8671875 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 structure of the change intentionally mirrors the already-merged constants/float32/pi-squared conversion (#16088), which has a near-identical test file in the single-precision family.

The bound is reproducible across architectures: the comparison is between two compile-time-fixed half-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. All other pre-commit checks (JavaScript test lint, license headers, filenames, commit message) ran and passed, as did make test for this package.

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 families (notably constants/float32/pi-squared and constants/float16/ln-ten) 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_01Mpjxv2Udzx2apcT86dshJY


Generated by Claude Code

Replace the relative tolerance assertion in the `export equals π²` test
with a ULP difference assertion via
`@stdlib/number/float16/base/assert/is-almost-same-value`. The measured
minimum ULP bound is `0`, as the computed value and the exported
constant are bit-identical in half-precision.

Ref: #11352

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

---
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: 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: na
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Oct 15, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

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

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

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Oct 15, 2026
@kgryte
kgryte marked this pull request as ready for review October 15, 2026 11:51
@kgryte
kgryte requested a review from a team October 15, 2026 11:51
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 15, 2026
@kgryte
kgryte merged commit 71017b3 into develop Oct 15, 2026
66 checks passed
@kgryte
kgryte deleted the kgryte/ulp-constants-float16-pi-squared branch October 15, 2026 11:51
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Oct 15, 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.

2 participants