Skip to content

Fix ROUND_TO_AWAY rounding decision in float_bvt#8983

Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-round_to_away
Open

Fix ROUND_TO_AWAY rounding decision in float_bvt#8983
tautschnig wants to merge 1 commit intodiffblue: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.

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

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 11:24
Copy link
Copy Markdown

Copilot AI left a comment

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 on lines +47 to +48
// 1.5 * 1.1 = 1.65 exactly. In float: 0x1.a66666p+0 (1.6499999...).
// Same as ROUND_TO_EVEN since it's not a tie.
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The comment says 1.5 * 1.1 = 1.65 exactly, but 1.1f is not exactly representable as a float, so the floating-point multiplication operands are already rounded. Consider rewording to clarify this is exact in real arithmetic, but not in IEEE-754 float (or use hex-float literals throughout if you want exact operand values).

Suggested change
// 1.5 * 1.1 = 1.65 exactly. In float: 0x1.a66666p+0 (1.6499999...).
// Same as ROUND_TO_EVEN since it's not a tie.
// In real arithmetic, 1.5 * 1.1 = 1.65 exactly, but 1.1f is not exactly
// representable in binary32, so the float operands are already rounded.
// This multiplication is still a non-tie case, so ROUND_TO_AWAY should
// match ROUND_TO_EVEN.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,10 @@
CORE no-new-smt
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

This test invokes the SMT solver (--smt2 --z3) but the label line doesn’t include smt-backend. In this repo, the default cbmc regression run excludes tests tagged smt-backend (see regression/cbmc/CMakeLists.txt), so SMT-only tests are typically labeled accordingly. Consider adding the smt-backend tag to avoid running this in SAT-only profiles / environments without Z3.

Suggested change
CORE no-new-smt
CORE no-new-smt smt-backend

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.55%. Comparing base (a6531d4) to head (3e0b040).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8983      +/-   ##
===========================================
+ Coverage    80.50%   80.55%   +0.05%     
===========================================
  Files         1704     1704              
  Lines       188796   188796              
  Branches        73       73              
===========================================
+ Hits        151993   152092      +99     
+ Misses       36803    36704      -99     

☔ View full report in Codecov by Sentry.
📢 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