Skip to content

Commit 9c6589a

Browse files
committed
Introduce floatbv_round_to_integral_exprt
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.
1 parent d5cf498 commit 9c6589a

File tree

24 files changed

+514
-328
lines changed

24 files changed

+514
-328
lines changed

regression/cbmc-library/__sort_of_CPROVER_round_to_integral-01/main.c

-9
This file was deleted.

regression/cbmc-library/__sort_of_CPROVER_round_to_integral-01/test.desc

-8
This file was deleted.

regression/cbmc-library/__sort_of_CPROVER_round_to_integralf-01/main.c

-9
This file was deleted.

regression/cbmc-library/__sort_of_CPROVER_round_to_integralf-01/test.desc

-8
This file was deleted.

regression/cbmc-library/__sort_of_CPROVER_round_to_integrall-01/main.c

-9
This file was deleted.

regression/cbmc-library/__sort_of_CPROVER_round_to_integrall-01/test.desc

-8
This file was deleted.

src/ansi-c/c_typecheck_expr.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,24 @@ exprt c_typecheck_baset::do_special_functions(
32373237

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

src/ansi-c/cprover_builtin_headers.h

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ int __CPROVER_islessgreaterf(float f, float g);
9393
int __CPROVER_islessgreaterd(double f, double g);
9494
int __CPROVER_isunorderedf(float f, float g);
9595
int __CPROVER_isunorderedd(double f, double g);
96+
float __CPROVER_round_to_integralf(float, int);
97+
double __CPROVER_round_to_integrald(double, int);
98+
long double __CPROVER_round_to_integralld(long double, int);
9699

97100
// absolute value
98101
int __CPROVER_abs(int x);

0 commit comments

Comments
 (0)