Skip to content

Fix ROUND_TO_AWAY rounding decision in float_bvt#8983

Merged
tautschnig merged 1 commit into
diffblue:developfrom
tautschnig:fix-round_to_away
Jun 12, 2026
Merged

Fix ROUND_TO_AWAY rounding decision in float_bvt#8983
tautschnig merged 1 commit into
diffblue:developfrom
tautschnig:fix-round_to_away

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

float_bvt::fraction_rounding_decision used
or_exprt(rounding_bit, sticky_bit)
for ROUND_TO_AWAY, which incorrectly rounds away from zero whenever any extra bits are non-zero. The correct formula is just rounding_bit, matching float_utilst.

ROUND_TO_AWAY means 'round to nearest, ties away from zero':

  • rounding_bit=0: closer to truncated value, don't increment
  • rounding_bit=1, sticky=0: exact tie, round away (increment)
  • rounding_bit=1, sticky=1: closer to incremented value, increment
  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a 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.

@tautschnig tautschnig self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 11:24

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

Fixes the ROUND_TO_AWAY (round-to-nearest, ties away from zero) rounding increment decision in the float_bvt encoding to match IEEE-754 semantics and float_utilst, and adds a regression test for both SAT (--floatbv) and SMT2/Z3 paths.

Changes:

  • Correct float_bvt::fraction_rounding_decision for ROUND_TO_AWAY to use only rounding_bit (not rounding_bit || sticky_bit).
  • Add a new regression test Float-round-to-away covering tie and non-tie cases.
  • Add an SMT2/Z3 regression descriptor to exercise the SMT path.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/solvers/floatbv/float_bv.cpp Fixes the rounding increment condition for ROUND_TO_AWAY in the floatbv encoding.
regression/cbmc/Float-round-to-away/main.c Adds a targeted regression program for ROUND_TO_AWAY tie/non-tie behavior.
regression/cbmc/Float-round-to-away/test.desc Runs the regression with --floatbv (SAT/bit-vector path).
regression/cbmc/Float-round-to-away/test_smt.desc Runs the regression with --smt2 --z3 (SMT path).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread regression/cbmc/Float-round-to-away/main.c Outdated
Comment thread regression/cbmc/Float-round-to-away/test_smt.desc
@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.63%. Comparing base (4ed6b6d) to head (136b9eb).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8983      +/-   ##
===========================================
+ Coverage    80.59%   80.63%   +0.04%     
===========================================
  Files         1713     1713              
  Lines       189403   189403              
  Branches        73       73              
===========================================
+ Hits        152647   152732      +85     
+ Misses       36756    36671      -85     

☔ 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.

float_bvt::fraction_rounding_decision used
  or_exprt(rounding_bit, sticky_bit)
for ROUND_TO_AWAY, which incorrectly rounds away from zero whenever
any extra bits are non-zero. The correct formula is just rounding_bit,
matching float_utilst.

ROUND_TO_AWAY means 'round to nearest, ties away from zero':
- rounding_bit=0: closer to truncated value, don't increment
- rounding_bit=1, sticky=0: exact tie, round away (increment)
- rounding_bit=1, sticky=1: closer to incremented value, increment

The regression test exercises this via the --smt2 path, which lowers
floating-point operations through float_bvt (smt2_convt::convert uses
float_bv()); the --floatbv (SAT) path goes through float_utilst, which
was already correct, and serves as a sanity check. Test 1 (non-tie sum
with rounding_bit=0, sticky=1) fails on the SMT path without this fix.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig merged commit 4033e01 into diffblue:develop Jun 12, 2026
43 checks passed
@tautschnig tautschnig deleted the fix-round_to_away branch June 12, 2026 05:41
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.

4 participants