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

Introduce floatbv_round_to_integral_exprt #8538

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

kroening
Copy link
Member

@kroening kroening commented Dec 21, 2024

This adds a new expression, floatbv_round_to_integral, which rounds an IEEE 754 floating-point number given as bit-vector to the nearest integer, considering the explicitly given rounding mode.

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

@kroening kroening force-pushed the round_to_integral branch 2 times, most recently from 84b83ec to b52d32e Compare December 21, 2024 14:45
@kroening kroening changed the title Introduce round_to_integral_exprt Introduce floatbv_round_to_integral_exprt Dec 21, 2024
@kroening kroening force-pushed the round_to_integral branch 9 times, most recently from 9c6589a to e189f1c Compare December 21, 2024 21:49
@kroening kroening marked this pull request as ready for review December 21, 2024 22:07
Copy link

codecov bot commented Dec 21, 2024

Codecov Report

Attention: Patch coverage is 78.89088% with 118 lines in your changes missing coverage. Please review.

Project coverage is 78.19%. Comparing base (36b2335) to head (ddeedbc).

Files with missing lines Patch % Lines
src/util/ieee_float.cpp 77.64% 38 Missing ⚠️
src/solvers/smt2/smt2_conv.cpp 33.33% 14 Missing ⚠️
unit/solvers/floatbv/float_utils.cpp 84.78% 14 Missing ⚠️
src/solvers/floatbv/float_utils.cpp 72.22% 10 Missing ⚠️
unit/util/ieee_float.cpp 88.00% 9 Missing ⚠️
src/solvers/smt2/smt2_parser.cpp 12.50% 7 Missing ⚠️
src/ansi-c/goto-conversion/goto_check_c.cpp 40.00% 6 Missing ⚠️
src/util/ieee_float.h 86.95% 6 Missing ⚠️
src/goto-programs/interpreter_evaluate.cpp 0.00% 4 Missing ⚠️
src/ansi-c/c_typecheck_expr.cpp 75.00% 3 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8538      +/-   ##
===========================================
- Coverage    78.79%   78.19%   -0.61%     
===========================================
  Files         1730     1730              
  Lines       199160   201007    +1847     
  Branches     18320    18331      +11     
===========================================
+ Hits        156938   157179     +241     
- Misses       42222    43828    +1606     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kroening kroening force-pushed the round_to_integral branch 4 times, most recently from f59ad70 to 151d627 Compare January 2, 2025 13:28
double ceil(double x)
{
return __sort_of_CPROVER_round_to_integral(FE_UPWARD, x);
return __CPROVER_round_to_integrald(x, 2); // FE_UPWARD
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you choose not to use the named constant FE_UPWARD?

Copy link
Member Author

Choose a reason for hiding this comment

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

__CPROVER_round_to_integrald uses our own numbering, which may or may not match FE_UPWARD on the target platform.

@@ -136,6 +136,32 @@ bvt float_utilst::to_integer(
return result;
}

bvt float_utilst::round_to_integral(const bvt &src)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where does this actually consider the rounding mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

It calls add_sub.

Comment on lines +154 to +174

auto tmp1 = add_sub(src, magic_number_bv, false);

auto tmp2 = add_sub(tmp1, magic_number_bv, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If ieee_floatt::round_to_integral is to be trusted, shouldn't the sign bit be used instead of hard-coding false and true?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note line 153 -- this variant tweaks the sign bit of the magic constant instead.

@kroening kroening force-pushed the round_to_integral branch 2 times, most recently from ec1cfc6 to 643372e Compare January 9, 2025 23:10
This splits ieee_floatt into two parts:

1) ieee_float_valuet stores an IEEE 754 floating-point value.  It offers no
operations that require rounding, and hence, does not require a rounding
mode.

2) ieee_floatt extends ieee_float_valuet with a rounding mode, and hence,
offers operators that require rounding.
@kroening kroening force-pushed the round_to_integral branch 2 times, most recently from dcf0732 to b6b25aa Compare January 10, 2025 14:45
This adds a new expression, floatbv_round_to_integral, which rounds an IEEE
754 floating-point number given as bit-vector to the nearest integer,
considering the explicitly given rounding mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants