Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions singularity-opac/constants/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,12 @@ struct RuntimePhysicalConstants {
return is_same;
}

private:
bool eps_equal(const Real &a, const Real &b) const {
return 2.0 * std::abs(a - b) < EPS * (std::abs(a) + std::abs(b) + 1e-100);
}
private:
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little surprised this is more robust.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something to do with storing the result of the operations before the comparison to eps?
https://godbolt.org/z/vc848vMds

Copy link
Contributor Author

@adamdempsey90 adamdempsey90 May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or doing 0 < EPS * 1e-27 is not well defined (in the sense the RHS is set to 0?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think not dividing is maybe technically better. But changing < to <= and storing the pieces could for sure matter.

}
};

using PhysicalConstantsUnity =
Expand Down