Repository navigation
test: migrate math/iter/utils/continued-fraction to ULP-based assertions - #15621
Merged
Merged
Conversation
…tions Replace the relative-tolerance (`delta`/`tol`) floating-point assertions in `test/test.js` with ULP-based assertions using `@stdlib/assert/is-almost-same-value`, per the tracking issue. Each converted site uses the minimum required ULP value, as measured against `@stdlib/number/float64/base/ulp-difference`: 2 for the two `[3,4,12,4]` fixtures, 1 for the two `0.3` continued-fraction sequences, and 0 for the remaining sites, which return exactly representable results. The now-unused `abs` and `EPS` requires are dropped. Only test files are changed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0165ZHkBWycywuobReCi8YRh
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.
Resolves a part of #11352.
Description
This pull request:
math/iter/utils/continued-fraction'stest/test.jsfrom relative-tolerance (EPS-based) floating-point assertions to ULP-based assertions using@stdlib/assert/is-almost-same-value.if ( v === expected ) { ... } else { delta = abs( v - expected ); tol = K * EPS * abs( expected ); ... }blocks with a singlet.strictEqual( isAlmostSameValue( v, expected, N ), true, 'returns expected value' );. Theif/elseguard is redundant here (unlike the siblingmath/iter/sequences/continued-fraction, whose guard carries an extrai === terms.length-1clause), becauseisAlmostSameValuealready returnstruefor exactly equal values.absandEPSrequires and adds the@stdlib/assert/is-almost-same-valuerequire directly aftertape, matching the position used in already-converted packages (e.g.,math/iter/sequences/continued-fraction,stats/incr/mape).test/test.js. No other files are touched.Measured minimum
The bounds were not guessed. Each site was instrumented to record the actual
@stdlib/number/float64/base/ulp-differencebetween the returned and the expected value:[ 3, 4, 12, 4 ]3.2453.244999999999999[ -3, -4, -12, -4 ]-3.245-3.244999999999999seq( PI )PIPIseq( -PI )-PI-PI[ 0, 2 ]0.50.5[ 0, 10 ]0.10.1seq( 0.3 )0.30.29999999999999993seq( -0.5 )-0.5-0.5seq( -0.3 )-0.3-0.29999999999999993seq( -0.1 )-0.1-0.1seq( PI ),tol: 1e-73.14159265301190253.1415926530119025seq( -PI ),tol: 1e-7-3.1415926530119025-3.1415926530119025Tightness was then confirmed empirically: decrementing every non-zero bound by one (
2 -> 1,1 -> 0) turns exactly those four assertions red and nothing else:So each bound is the smallest integer that passes, and the sites left at
0assert exact equality, which is strictly tighter than the tolerance they replace.Eight of the twelve sites reduce to
0because the underlying implementation uses only+,-,*,/,abs, andfloor— all exactly specified by IEEE 754 — so those results are bit-reproducible rather than platform-dependent. There are no transcendental calls anywhere inmath/iter/utils/continued-fractionormath/iter/sequences/continued-fraction, hence no FMA/arch-dependent variation. The suite was run twice at the final bounds with identical, fully passing results.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 two
3.245sites need 2 ULPs where the siblingmath/iter/sequences/continued-fractionsettled on 2 uniformly; here the remaining sites genuinely measure tighter, so they are pinned at1and0rather than being rounded up to a single file-wide constant. If reviewers would prefer one uniform bound of2across the file for readability, that is a one-line change per site.Other
Verification caveat — please read.
make install-node-modulescould not complete in the environment used to author this change: the npm registry reachable from that environment resolveses-object-atomsonly up to1.1.1, while a transitive dependency requires^1.1.2, so the install aborts withETARGET. As a consequencemake testandmake lintcould not be run, and thepre-commitandpre-pushhooks (which neednode_modules) were bypassed. CI on this PR is therefore the first authoritative run, which is why it is opened as a draft.What was verified, with
tapeandeslintinstalled standalone:test/test.js— 79/79 assertions pass, run twice, identical results.test/test.validate.js— 38/38 pass, unchanged and untouched by this PR.if/elsecontributed exactly one assertion, as does each new single-line assertion.eslint8.57.1 was run against the changed file with the repository's ownstdlib/require-order,stdlib/require-spaces,stdlib/vars-order, andstdlib/no-empty-lines-between-requiresrules, plus coreno-unused-vars: 0 problems. (The fulletc/eslint/.eslintrc.tests.jsconfig could not be loaded, as thestdlibplugin pulls inremarkand other uninstalled dependencies.) A negative control confirmed those rules do fire, so the clean result is meaningful rather than a silently inert run.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written by Claude Code running as an unattended scheduled task. The agent searched the repository for a package still using relative-tolerance assertions, studied the already-merged sibling
math/iter/sequences/continued-fractionand other converted packages to mirror the established idiom, applied the migration, and determined each minimum ULP bound empirically by measuring actual ULP differences and confirming tightness and determinism through repeated runs.@stdlib-js/reviewers
🤖 Generated with Claude Code
https://claude.ai/code/session_0165ZHkBWycywuobReCi8YRh
Generated by Claude Code