File tree 6 files changed +29
-26
lines changed 6 files changed +29
-26
lines changed Original file line number Diff line number Diff line change @@ -709,9 +709,7 @@ interpretert::mp_vectort interpretert::evaluate(const exprt &expr)
709
709
}
710
710
else if (expr.type ().id ()==ID_floatbv)
711
711
{
712
- ieee_floatt f (to_floatbv_type (expr.type ()));
713
- f.from_integer (1 );
714
- result=f.pack ();
712
+ result = ieee_floatt::one (to_floatbv_type (expr.type ())).pack ();
715
713
}
716
714
else
717
715
result=1 ;
Original file line number Diff line number Diff line change @@ -204,10 +204,8 @@ bool boolbvt::type_conversion(
204
204
// bool to float
205
205
206
206
// build a one
207
- ieee_floatt f (to_floatbv_type (dest_type));
208
- f.from_integer (1 );
209
-
210
- dest = convert_bv (f.to_expr ());
207
+ auto one = ieee_floatt::one (to_floatbv_type (dest_type));
208
+ dest = convert_bv (one.to_expr ());
211
209
212
210
INVARIANT (
213
211
src_width == 1 , " bitvector of type boolean shall have width one" );
Original file line number Diff line number Diff line change @@ -3066,29 +3066,12 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
3066
3066
{
3067
3067
constant_exprt val (irep_idt (), dest_type);
3068
3068
3069
- ieee_floatt a (dest_floatbv_type);
3070
-
3071
- mp_integer significand ;
3072
- mp_integer exponent;
3073
-
3074
3069
out << " (ite " ;
3075
3070
convert_expr (src);
3076
3071
out << " " ;
3077
-
3078
- significand = 1 ;
3079
- exponent = 0 ;
3080
- a.build (significand , exponent);
3081
- val.set_value (integer2bvrep (a.pack (), a.spec .width ()));
3082
-
3083
- convert_constant (val);
3072
+ convert_constant (ieee_floatt::one (dest_floatbv_type).to_expr ());
3084
3073
out << " " ;
3085
-
3086
- significand = 0 ;
3087
- exponent = 0 ;
3088
- a.build (significand , exponent);
3089
- val.set_value (integer2bvrep (a.pack (), a.spec .width ()));
3090
-
3091
- convert_constant (val);
3074
+ convert_constant (ieee_floatt::zero (dest_floatbv_type).to_expr ());
3092
3075
out << " )" ;
3093
3076
}
3094
3077
else if (src_type.id ()==ID_c_bool)
Original file line number Diff line number Diff line change @@ -470,6 +470,19 @@ void ieee_floatt::extract_base10(
470
470
}
471
471
}
472
472
473
+ ieee_floatt ieee_floatt::one (const ieee_float_spect &spec)
474
+ {
475
+ ieee_floatt result{spec};
476
+ result.exponent = 0 ;
477
+ result.fraction = power (2 , result.spec .f );
478
+ return result;
479
+ }
480
+
481
+ ieee_floatt ieee_floatt::one (const floatbv_typet &type)
482
+ {
483
+ return one (ieee_float_spect{type});
484
+ }
485
+
473
486
void ieee_floatt::build (
474
487
const mp_integer &_fraction,
475
488
const mp_integer &_exponent)
Original file line number Diff line number Diff line change @@ -199,6 +199,16 @@ class ieee_floatt
199
199
return result;
200
200
}
201
201
202
+ static ieee_floatt zero (const ieee_float_spect &spec)
203
+ {
204
+ ieee_floatt result (spec);
205
+ result.make_zero ();
206
+ return result;
207
+ }
208
+
209
+ static ieee_floatt one (const floatbv_typet &);
210
+ static ieee_floatt one (const ieee_float_spect &);
211
+
202
212
void make_NaN ();
203
213
void make_plus_infinity ();
204
214
void make_minus_infinity ();
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ SRC += analyses/ai/ai.cpp \
150
150
util/get_base_name.cpp \
151
151
util/graph.cpp \
152
152
util/help_formatter.cpp \
153
+ util/ieee_float.cpp \
153
154
util/interval/add.cpp \
154
155
util/interval/bitwise.cpp \
155
156
util/interval/comparisons.cpp \
You can’t perform that action at this time.
0 commit comments