Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 use fuzzy comparison for floating point in const evaluation equality check #809

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

burgholzer
Copy link
Member

Description

This PR fixes another small bug observed as part of #803, which only surfaced under macOS when using GCC as the compiler.
Turns out that GitHub's CodeQL was right after all and exact equality checks on floating point values can come back to bite you.
In this case, two computations of std::tan(1.0) resulted in values that were off by a single ULP.
Although I am not 100% certain how this can even happen, this PR works around any such errors by using a fuzzy floating point comparison with an epsilon on the order of 10-12.

Checklist:

  • The pull request only contains commits that are related to it.
  • I have added appropriate tests and documentation.
  • I have made sure that all CI jobs on GitHub pass.
  • The pull request introduces no new warnings and follows the project's style guidelines.

@burgholzer burgholzer self-assigned this Jan 21, 2025
@burgholzer burgholzer added fix Fix for something that isn't working Core Anything related to the Core library and IR c++ Anything related to C++ code labels Jan 21, 2025
@burgholzer burgholzer enabled auto-merge January 21, 2025 16:23
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.2%. Comparing base (ba3aa86) to head (32f0a47).
Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #809   +/-   ##
=====================================
  Coverage   92.2%   92.2%           
=====================================
  Files        126     126           
  Lines      13827   13827           
  Branches    2153    2153           
=====================================
+ Hits       12756   12758    +2     
+ Misses      1071    1069    -2     
Flag Coverage Δ
cpp 92.0% <100.0%> (+<0.1%) ⬆️
python 99.7% <ø> (ø)
Files with missing lines Coverage Δ
...e/ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp 81.3% <100.0%> (+0.4%) ⬆️

... and 1 file with indirect coverage changes

@burgholzer burgholzer merged commit 9265d78 into main Jan 22, 2025
30 checks passed
@burgholzer burgholzer deleted the fix-const-eval branch January 22, 2025 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Anything related to C++ code Core Anything related to the Core library and IR fix Fix for something that isn't working
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant