GH-40: Centralize and document epsilon/tolerance constants#145
Merged
Conversation
Introduce a central header for the previously scattered near-zero / division-guard tolerances, grouped by meaning with a rationale comment block explaining the absolute-vs-relative choice (domains are unit-disk normalized, so O(1) operands make absolute machine-epsilon-scaled tolerances appropriate). SPLINE_CLOSURE_EPS is kept relative because it compares un-normalized user input. No call sites changed yet; behavior unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the duplicated/scattered near-zero and division-guard literals across FornbergMC, PMatrixBuilder, Domain, SplineBoundaryComponent, RootFinder, and Grid with the named constants from Tolerances.h. Each substitution preserves the exact value, so behavior is unchanged (full suite incl. thesis examples stays green). The PMatrixBuilder coincident-center error message no longer hardcodes the literal '1e-14' (which would drift from the constant); it now reports the actual distance and references the coincidence tolerance. The corresponding test assertion is updated to match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Blind-review follow-ups: - Convert the second central-difference step (DiscreteBoundaryComponent:: evaluateDerivative, BoundaryComponent.cpp) to FINITE_DIFFERENCE_STEP; it was missed in the initial sweep while its Domain.cpp sibling was converted. Value identical, behavior unchanged. - Reword the NEWTON_UPDATE_SCALE_EPS comment: it guards a tangent-magnitude divisor, so the honest distinction from GEOMETRIC_COINCIDENCE_EPS is that it guards a different quantity (tune independently), not that it 'does not test coincidence'. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
Blind review (4 specialized agents)Fanned out four reviewers against the diff: code-reviewer, comment-analyzer, silent-failure-hunter, pr-test-analyzer. No blocking findings — the value-preservation claim was verified site-by-site from every angle. Verified
Acted on
Noted, not acted on (out of scope / pre-existing)
|
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.
Closes #40 (centralization scope; hazard guards split to #144).
Context
Issue #40 asked for a codebase-wide review of epsilon selection and scaling. An audit found its original trigger — a
rho_val / (z_0 - c_val)division — was already guarded, and that the real problem was consistency: the codebase had exactly one centralized tolerance (BOUNDARY_TOLERANCEinTypes.h) and 15+ scattered, undocumented magic numbers (1e-14,1e-15,1e-10,1e-6,100·ε).Per discussion, the work was split along its risk boundary into two issues. This PR is the value-preserving half; the genuine behavior-changing hazard guards are tracked in #144.
What this PR does
src/core/Tolerances.h— namedconstexprconstants grouped by meaning (not value), with a rationale comment block: domains are unit-disk-normalized, so O(1) operands make absolute machine-epsilon-scaled tolerances appropriate;SPLINE_CLOSURE_EPSis intentionally relative because it compares un-normalized user input. Includes a 'do not retune without re-running thesis regression tests' warning.GEOMETRIC_COINCIDENCE_EPS(1e-14),NEWTON_UPDATE_SCALE_EPS(1e-14),PIVOT_EPS(1e-15),SPLINE_CLOSURE_EPS(100·ε, relative),GRID_GEOMETRY_EPS(1e-10),FINITE_DIFFERENCE_STEP(1e-6).1e-14(which would drift from the constant); it reports the actual distance and references the coincidence tolerance. Its test assertion is updated to match.BOUNDARY_TOLERANCEstays inTypes.h(domain-level), cross-referenced from the new header.FornbergMCConfigurationtolerances are left as-is (already named and configurable).Verification
ctest: 306/306 pass, including the thesis examples (thesis2/thesis4/thesis5) — the regression guardrail for the value-preserving claim.Out of scope (tracked elsewhere)
🤖 Generated with Claude Code