util: IEEE-754 sign-aware expression builders (signbit/fabs/copysign)#9131
Open
tautschnig wants to merge 1 commit into
Open
util: IEEE-754 sign-aware expression builders (signbit/fabs/copysign)#9131tautschnig wants to merge 1 commit into
tautschnig wants to merge 1 commit into
Conversation
Centralise IEEE sign-bit semantics in ieee_signbit/ieee_fabs/ieee_copysign, built on sign_exprt so negative zero is handled correctly (copysign(1,-0.0) == -1.0, fabs(-0.0) == +0.0) -- unlike an 'x < 0' formulation. With a unit test covering signbit/fabs/copysign incl. the negative-zero cases. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds IEEE-754 sign-bit–aware expression builders to util/ieee_float (signbit/fabs/copysign) to correctly handle negative zero and avoid incorrect x < 0-based encodings, with a unit test validating the intended semantics.
Changes:
- Add
ieee_signbit,ieee_fabs, andieee_copysignexpression builders implemented usingsign_exprtto reflect IEEE sign-bit semantics (incl.-0.0). - Document the IEEE-754 rationale and negative-zero pitfalls in the public header.
- Add unit tests covering signbit/fabs/copysign, including negative-zero cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/util/ieee_float.h |
Declares and documents new IEEE sign-aware expression builders. |
src/util/ieee_float.cpp |
Implements ieee_signbit/ieee_fabs/ieee_copysign using sign_exprt and if_exprt. |
unit/util/ieee_float.cpp |
Adds a unit test to validate semantics (incl. negative zero). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+158
to
+159
| auto eval_bool = [&](const exprt &e) -> bool | ||
| { return simplify_expr(e, ns).is_true(); }; |
Comment on lines
+1425
to
+1426
| PRECONDITION(magnitude.type().id() == ID_floatbv); | ||
| PRECONDITION(sign_source.type().id() == ID_floatbv); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9131 +/- ##
========================================
Coverage 80.83% 80.83%
========================================
Files 1715 1715
Lines 189948 189995 +47
Branches 73 73
========================================
+ Hits 153540 153586 +46
- Misses 36408 36409 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Centralise IEEE sign-bit semantics in ieee_signbit/ieee_fabs/ieee_copysign, built on sign_exprt so negative zero is handled correctly (copysign(1,-0.0) == -1.0, fabs(-0.0) == +0.0) -- unlike an 'x < 0' formulation. With a unit test covering signbit/fabs/copysign incl. the negative-zero cases.