Skip to content

test: migrate math/base/special/rempio2 to ULP-based assertions - #14410

Merged
kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-e0cl1b
Aug 19, 2026
Merged

kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-e0cl1b

Conversation

@kgryte

@kgryte kgryte commented Aug 19, 2026

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

Details:

  • Package converted: math/base/special/rempio2 (test/test.js and test/test.native.js; these are the only test files in the package).

  • Final ULP bounds, identical across both test files:

    test previous tolerance final bound
    reconstruction, positive (randu()*100) EPS * abs( x ) 1 ULP
    reconstruction, tiny positive (randu()*1.0e-100) EPS * abs( x ) exact
    reconstruction, negative (-100 * randu()) EPS * abs( x ) 1 ULP
    reconstruction, tiny negative (-1.0e-100 * randu()) EPS * abs( x ) exact
    reconstruction, multiples of π/4 EPS * abs( x ) 1 ULP
  • Measured minimum: 1 ULP is the smallest integer bound under which the positive and negative reconstruction loops pass. Instrumenting ulpdiff( ( PIO2*n ) + ( y[0]+y[1] ), x ) directly over 1.2M random samples per range gives a maximum observed difference of exactly 1 ULP for the ±[0,100) ranges and 0 for both tiny ranges and for all 20 multiples of π/4. Lowering the bound to 0 produces 88–97 failing assertions per run.

  • For the two tiny ranges, |x| < 2^-27, so the function returns n = 0 with y[0] = x and y[1] = 0 and reconstruction is bit-for-bit exact; those assertions therefore use exact equality, matching the float32 counterpart math/base/special/rempio2f. Exact equality (rather than a 0 ULP bound) is used deliberately, because randu() is documented as returning on the interval [0,1) and so x may be -0, which isAlmostSameValue( z, x, 0 ) would reject.

  • The multiples-of-π/4 loop measures 0 ULP here, but is kept at 1 ULP to match the other reconstruction loops and rempio2f, and to leave headroom for compiler-dependent contraction in the C implementation on platforms other than the one measured.

  • Determinism: the native add-on was compiled locally so that test/test.native.js actually executed rather than being skipped, and the suite was then run four times at the final bounds. Every run: 83291 assertions in test/test.js and 83291 in test/test.native.js, all passing.

  • Linting is clean for both files under etc/eslint/.eslintrc.tests.js, and the only changed files are the two test files.

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?

The assertion messages in test/test.native.js were 'can recover input value' rather than 'returns expected value'; they have been normalized to 'returns expected value' to match the idiom in #11352 and in rempio2f. Happy to restore the original wording if reviewers would prefer to keep it.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

The conversion mirrors the float32 counterpart in the same family, math/base/special/rempio2f, which has the same test structure and already uses t.strictEqual( isAlmostSameValue( z, x, 1 ), true, 'returns expected value' ); for the reconstruction loops and exact equality for the tiny ranges.

The for large/huge positive/negative input values tests contain no tolerance math and are unchanged.

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, running unattended as a scheduled task, which selected the package, mirrored the conversion idiom from previously merged conversions, and empirically determined and verified the minimum ULP bounds.


@stdlib-js/reviewers


Generated by Claude Code

Replaces the computed relative tolerance checks (`delta <= EPS*abs(x)`)
in `test/test.js` and `test/test.native.js` with ULP-based assertions
using `@stdlib/assert/is-almost-same-value`, mirroring the idiom already
used by the float32 counterpart `math/base/special/rempio2f`.

The reconstruction checks over the positive, negative, and multiples of
pi/4 input ranges assert equality to within 1 ULP. For the tiny positive
and tiny negative ranges, reconstruction is exact, and so the assertions
use exact equality.

Ref: #11352

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0126JBJYGMzjhQq8VHZUyEaa
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Good First PR A pull request resolving a Good First Issue. labels Aug 19, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
math/base/special/rempio2 $\\color{red}893/907$
$\\color{green}+98.46\\%$
$\\color{red}82/87$
$\\color{green}+94.25\\%$
$\\color{green}5/5$
$\\color{green}+100.00\\%$
$\\color{red}893/907$
$\\color{green}+98.46\\%$

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

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Aug 19, 2026
@kgryte
kgryte marked this pull request as ready for review August 19, 2026 11:41
@kgryte
kgryte requested a review from a team August 19, 2026 11:41
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 19, 2026
@kgryte
kgryte merged commit 3541bb7 into develop Aug 19, 2026
82 checks passed
@kgryte
kgryte deleted the claude/great-brahmagupta-e0cl1b branch August 19, 2026 11:43
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 19, 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. Math Issue or pull request specific to math functionality. Tests Pull requests specifically adding tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants