Skip to content

Commit c10e5ca

Browse files
committed
Introduce round_to_integral_exprt
This adds a new expression, 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.
1 parent d5cf498 commit c10e5ca

File tree

11 files changed

+202
-264
lines changed

11 files changed

+202
-264
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,21 @@ exprt c_typecheck_baset::do_special_functions(
32373237

32383238
return std::move(infl_expr);
32393239
}
3240+
else if(identifier == CPROVER_PREFIX "round_to_integral")
3241+
{
3242+
if(expr.arguments().size() != 2)
3243+
{
3244+
error().source_location = f_op.source_location();
3245+
error() << identifier << " expects two arguments" << eom;
3246+
throw 0;
3247+
}
3248+
3249+
auto round_to_integral_expr =
3250+
floatbv_round_to_integral_exprt{expr.arguments()[0], expr.arguments()[1]};
3251+
round_to_integral_expr.add_source_location() = source_location;
3252+
3253+
return std::move(round_to_integral_expr);
3254+
}
32403255
else if(
32413256
identifier == CPROVER_PREFIX "abs" || identifier == CPROVER_PREFIX "labs" ||
32423257
identifier == CPROVER_PREFIX "llabs" ||

0 commit comments

Comments
 (0)