Repository navigation
test: migrate math/base/special/rempio2 to ULP-based assertions - #14410
Merged
Merged
Conversation
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
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
math/base/special/rempio2from EPS-scaled relative tolerance comparisons to ULP-based assertions using@stdlib/assert/is-almost-same-value, per [RFC]: Migratemath/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352.@stdlib/math/base/special/absand@stdlib/constants/float64/epsrequires fromtest/test.jsandtest/test.native.js.Details:
Package converted:
math/base/special/rempio2(test/test.jsandtest/test.native.js; these are the only test files in the package).Final ULP bounds, identical across both test files:
randu()*100)EPS * abs( x )1ULPrandu()*1.0e-100)EPS * abs( x )-100 * randu())EPS * abs( x )1ULP-1.0e-100 * randu())EPS * abs( x )π/4EPS * abs( x )1ULPMeasured minimum:
1ULP is the smallest integer bound under which the positive and negative reconstruction loops pass. Instrumentingulpdiff( ( PIO2*n ) + ( y[0]+y[1] ), x )directly over 1.2M random samples per range gives a maximum observed difference of exactly1ULP for the±[0,100)ranges and0for both tiny ranges and for all 20 multiples ofπ/4. Lowering the bound to0produces 88–97 failing assertions per run.For the two tiny ranges,
|x| < 2^-27, so the function returnsn = 0withy[0] = xandy[1] = 0and reconstruction is bit-for-bit exact; those assertions therefore use exact equality, matching the float32 counterpartmath/base/special/rempio2f. Exact equality (rather than a0ULP bound) is used deliberately, becauserandu()is documented as returning on the interval[0,1)and soxmay be-0, whichisAlmostSameValue( z, x, 0 )would reject.The multiples-of-
π/4loop measures0ULP here, but is kept at1ULP to match the other reconstruction loops andrempio2f, 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.jsactually executed rather than being skipped, and the suite was then run four times at the final bounds. Every run: 83291 assertions intest/test.jsand 83291 intest/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
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Questions
The assertion messages in
test/test.native.jswere'can recover input value'rather than'returns expected value'; they have been normalized to'returns expected value'to match the idiom in #11352 and inrempio2f. Happy to restore the original wording if reviewers would prefer to keep it.Other
The conversion mirrors the float32 counterpart in the same family,
math/base/special/rempio2f, which has the same test structure and already usest.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 valuestests contain no tolerance math and are unchanged.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
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