BUG: Define vnl_math::sqrteps as exactly-representable 0x1p-26#1051
Closed
hjmjohnson wants to merge 1 commit into
Closed
BUG: Define vnl_math::sqrteps as exactly-representable 0x1p-26#1051hjmjohnson wants to merge 1 commit into
hjmjohnson wants to merge 1 commit into
Conversation
sqrteps is meant to be sqrt(eps) where eps is std::numeric_limits< double>::epsilon() = 2^-52. The exact value sqrt(2^-52) = 2^-26 is a power of two and therefore exactly representable as a double; in decimal it is 1.490116119384765625e-8. The previous literal 1.490116119384766e-08 is 3.75e-24 above that exact value, exceeding the half-ULP threshold (~1.65e-24), so it rounds to 2^-26 + 2^-78 -- one ULP high. The hex float 0x1p-26 is the simplest unambiguous spelling of the intended value and matches what IEEE-754 correctly-rounded sqrt(eps) returns at runtime (and what C++26 constexpr std::sqrt(eps) will yield). vgl already relies on the exact value: core/vgl/vgl_triangle_3d.cxx computes sqrteps = std::sqrt(numeric_limits<double>::epsilon()) at runtime, which is exactly 0x1p-26. Reported via greptile review on InsightSoftwareConsortium/ITK PR #6427.
There was a problem hiding this comment.
Pull request overview
This PR corrects vnl_math::sqrteps to be the exactly representable value of sqrt(std::numeric_limits<double>::epsilon()) by replacing a slightly-too-large decimal literal with the precise hexadecimal floating-point literal 0x1p-26.
Changes:
- Replace
vnl_math::sqrteps’s decimal literal with0x1p-26to represent2^-26exactly. - Add an explanatory comment documenting why
0x1p-26is the correct value forsqrt(eps).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Moving ITK efforts for VXL to https://github.com/InsightSoftwareConsortium/vxl/tree/for/itk-vxl-master. This is primarily so that the ITK development team can focus on the ITK-needed features of vxl and remove the rest. |
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.
Define
vnl_math::sqrtepsas the exactly-representable0x1p-26instead of the 1-ULP-high decimal literal1.490116119384766e-08.Why 0x1p-26 is the correct value
sqrtepsissqrt(eps)whereeps = std::numeric_limits<double>::epsilon() = 2^-52. Thereforesqrteps = sqrt(2^-52) = 2^-26, a power of two and exactly representable as adouble(decimal1.490116119384765625e-8).The previous literal
1.490116119384766e-08is3.75e-24above that exact value, exceeding the half-ULP threshold (~1.65e-24), so it rounds to2^-26 + 2^-78— one ULP high.0x1p-26is the simplest unambiguous spelling and equals what IEEE-754 correctly-roundedsqrt(eps)returns at runtime (and what C++26constexpr std::sqrt(eps)will yield).vglalready relies on the exact value:core/vgl/vgl_triangle_3d.cxxcomputessqrteps = std::sqrt(std::numeric_limits<double>::epsilon())at runtime, which is exactly0x1p-26.Impact / testing
core/vnl/tests/test_math.cxxonly takes&vnl_math::sqrteps(symbol-existence check).pdf1d,clsfy) usesqrtepsas a convergence/comparison tolerance, where a 1-ULP change is negligible.0x1p-26 == std::sqrt(std::numeric_limits<double>::epsilon()).