Skip to content

test: migrate constants/float64/pi-squared to ULP-based assertions - #16253

Draft
kgryte wants to merge 1 commit into
developfrom
claude/great-brahmagupta-l6nfld
Draft

kgryte wants to merge 1 commit into
developfrom
claude/great-brahmagupta-l6nfld

Conversation

@kgryte

@kgryte kgryte commented Oct 19, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

test/test.js contains a single relative tolerance assertion, in the 'export equals π²' test, which compared the exported constant against pow( PI, 2 ) using a computed delta/tol pair. It is replaced with one isAlmostSameValue( v, PI_SQUARED, 0 ) assertion using the standard 'returns expected value' message. The now-unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires are dropped in favor of @stdlib/assert/is-almost-same-value. The two other tests in the file (the typeof check and the exact t.strictEqual( PI_SQUARED, 9.869604401089358 ) check) are untouched.

The ULP bound is the measured minimum:

Comparison Measured ULP diff ULP bound
pow( PI, 2 ) vs. PI_SQUARED 0 0

pow( PI, 2 ) returns 9.869604401089358, which is bit-identical to the exported constant, so the measured ULP difference is 0 and no tighter bound exists. This was measured directly with @stdlib/number/float64/base/ulp-difference. Both operands are compile-time constants and pow is deterministic, so there is no fixture sampling involved and no FMA/arch sensitivity.

As a sanity check that the bound is not vacuous, the next representable float64 above pow( PI, 2 ) (9.86960440108936, 1 ULP away) was confirmed to be rejected at 0: isAlmostSameValue( v, 9.86960440108936, 0 ) returns false.

The bound is strictly tighter than what the test previously accepted. The previous tolerance of EPS * v is 2.1914924100062367e-15, against a ULP of 1.7763568394002505e-15 at that magnitude, i.e. approximately 1.23 ULP — so the old assertion would have passed on a 1 ULP discrepancy, whereas this one requires an exact match.

0 is also the bound used by the already-converted sibling constants constants/float64/ln-two, constants/float64/ln-ten, and constants/float64/half-ln-two, each of which likewise compares against a bit-identical recomputation.

The suite was run twice at the final bound, with identical results both times (4 assertions passing, 0 failing).

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.

  • make test TESTS_FILTER=".*/constants/float64/pi-squared/.*" and make lint-javascript-tests TESTS_FILTER=".*/constants/float64/pi-squared/.*" are both clean.
  • The diff mirrors the already-converted sibling package constants/float32/pi-squared (test: migrate constants/float32/pi-squared to ULP-based assertions #16088) line for line, modulo precision: the same require is added in the same position, the same two requires are dropped, and the test body collapses to the same two-line shape. The float64 variant uses @stdlib/assert/is-almost-same-value, matching the other converted constants/float64 packages, rather than the number/float32/base/assert variant the single-precision package needs.
  • make lint-editorconfig-files could not run in this environment, as the editorconfig-checker binary could not be downloaded. The changed lines were checked by hand for tab indentation, trailing whitespace, LF line endings, and a final newline. For the same reason, the commit was authored with --no-verify.
  • make lint-javascript-benchmarks errors for this package, but it does so identically on unmodified sibling packages: constants/float64/pi-squared has no benchmark/ directory, so the target is invoked with an empty file list. Unrelated to this change.

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 written by Claude Code, which also measured the minimum ULP bound empirically and ran the tests and linter.


@stdlib-js/reviewers


Generated by Claude Code

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Oct 19, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
constants/float64/pi-squared $\\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.

This branch has not been deployed

No deployments
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants