Another modification to constants comparison#67
Merged
Conversation
Yurlungur
approved these changes
May 9, 2025
| bool eps_equal(const Real &a, const Real &b) const { | ||
| const Real diff = std::abs(a - b); | ||
| const Real scale = 0.5 * (std::abs(a) + std::abs(b)); | ||
| return diff / (scale + 1e-100) <= EPS; |
Collaborator
There was a problem hiding this comment.
I'm a little surprised this is more robust.
Collaborator
Author
There was a problem hiding this comment.
Maybe something to do with storing the result of the operations before the comparison to eps?
https://godbolt.org/z/vc848vMds
Collaborator
Author
There was a problem hiding this comment.
Or doing 0 < EPS * 1e-27 is not well defined (in the sense the RHS is set to 0?)
Collaborator
There was a problem hiding this comment.
yeah I think not dividing is maybe technically better. But changing < to <= and storing the pieces could for sure matter.
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.
Debug build of artemis crashed in the constants comparison (of
hspecifically). Seemed like a stupid floating point problem that was solved by making the comparison<=instead of<. I also went ahead and split out the difference and scale into separate variables for possible future debugging.