Skip to content

util: IEEE-754 sign-aware expression builders (signbit/fabs/copysign)#9131

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:python-upstream-02-ieee-sign-builders
Open

util: IEEE-754 sign-aware expression builders (signbit/fabs/copysign)#9131
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:python-upstream-02-ieee-sign-builders

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

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.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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>
@tautschnig tautschnig self-assigned this Jul 23, 2026
Copilot AI review requested due to automatic review settings July 23, 2026 11:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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, and ieee_copysign expression builders implemented using sign_exprt to 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 thread unit/util/ieee_float.cpp
Comment on lines +158 to +159
auto eval_bool = [&](const exprt &e) -> bool
{ return simplify_expr(e, ns).is_true(); };
Comment thread src/util/ieee_float.cpp
Comment on lines +1425 to +1426
PRECONDITION(magnitude.type().id() == ID_floatbv);
PRECONDITION(sign_source.type().id() == ID_floatbv);
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.83%. Comparing base (f71fdad) to head (0fad631).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants