@@ -25,8 +25,21 @@ exprt float_bvt::convert(const exprt &expr) const
25
25
return not_exprt (is_equal (expr.op0 (), expr.op1 (), get_spec (expr.op0 ())));
26
26
else if (expr.id ()==ID_floatbv_typecast)
27
27
{
28
- const typet &src_type=expr.op0 ().type ();
29
- const typet &dest_type=expr.type ();
28
+ const auto &floatbv_typecast_expr = to_floatbv_typecast_expr (expr);
29
+
30
+ const exprt &src = floatbv_typecast_expr.op ();
31
+ const exprt &rm = floatbv_typecast_expr.rounding_mode ();
32
+ const typet &src_type = src.type ();
33
+ const typet &dest_type = floatbv_typecast_expr.type ();
34
+
35
+ if (src_type.id () == ID_c_bit_field)
36
+ {
37
+ // go through underlying type
38
+ return convert (floatbv_typecast_exprt (
39
+ typecast_exprt (src, to_c_bit_field_type (src_type).subtype ()),
40
+ rm,
41
+ dest_type));
42
+ }
30
43
31
44
if (dest_type.id ()==ID_signedbv &&
32
45
src_type.id ()==ID_floatbv) // float -> signed
@@ -60,10 +73,30 @@ exprt float_bvt::convert(const exprt &expr) const
60
73
else
61
74
return nil_exprt ();
62
75
}
63
- else if (expr.id ()==ID_typecast &&
64
- expr.type ().id ()==ID_bool &&
65
- expr.op0 ().type ().id ()==ID_floatbv) // float -> bool
66
- return not_exprt (is_zero (expr.op0 ()));
76
+ else if (expr.id () == ID_typecast)
77
+ {
78
+ const typet &src_type = expr.op0 ().type ();
79
+ const typet &dest_type = expr.type ();
80
+
81
+ if (
82
+ dest_type.id () == ID_bool && src_type.id () == ID_floatbv) // float -> bool
83
+ {
84
+ return not_exprt (is_zero (expr.op0 ()));
85
+ }
86
+ else if (
87
+ src_type.id () == ID_c_bool &&
88
+ dest_type.id () == ID_floatbv) // c_bool -> float
89
+ {
90
+ return from_c_bool (expr.op0 (), get_spec (expr));
91
+ }
92
+ else if (
93
+ src_type.id () == ID_bool && dest_type.id () == ID_floatbv) // bool -> float
94
+ {
95
+ return from_bool (expr.op0 (), get_spec (expr));
96
+ }
97
+ else
98
+ return nil_exprt ();
99
+ }
67
100
else if (expr.id ()==ID_floatbv_plus)
68
101
return add_sub (false , expr.op0 (), expr.op1 (), expr.op2 (), get_spec (expr));
69
102
else if (expr.id ()==ID_floatbv_minus)
@@ -254,6 +287,24 @@ exprt float_bvt::from_unsigned_integer(
254
287
return rounder (result, rm, spec);
255
288
}
256
289
290
+ exprt float_bvt::from_bool (const exprt &src, const ieee_float_spect &spec) const
291
+ {
292
+ ieee_floatt zero (spec);
293
+ zero.make_zero ();
294
+ const auto zero_expr = zero.to_expr ();
295
+ ieee_floatt one (spec);
296
+ one.build (1 , 0 );
297
+ const auto one_expr = one.to_expr ();
298
+ return if_exprt (src, one_expr, zero_expr);
299
+ }
300
+
301
+ exprt float_bvt::from_c_bool (const exprt &src, const ieee_float_spect &spec)
302
+ const
303
+ {
304
+ // we go via bool
305
+ return from_bool (typecast_exprt (src, bool_typet ()), spec);
306
+ }
307
+
257
308
exprt float_bvt::to_signed_integer (
258
309
const exprt &src,
259
310
std::size_t dest_width,
0 commit comments