File tree Expand file tree Collapse file tree 7 files changed +49
-31
lines changed Expand file tree Collapse file tree 7 files changed +49
-31
lines changed Original file line number Diff line number Diff line change @@ -709,9 +709,7 @@ interpretert::mp_vectort interpretert::evaluate(const exprt &expr)
709709 }
710710 else if (expr.type ().id ()==ID_floatbv)
711711 {
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 ();
715713 }
716714 else
717715 result=1 ;
Original file line number Diff line number Diff line change @@ -204,10 +204,8 @@ bool boolbvt::type_conversion(
204204 // bool to float
205205
206206 // 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 ());
211209
212210 INVARIANT (
213211 src_width == 1 , " bitvector of type boolean shall have width one" );
Original file line number Diff line number Diff line change @@ -3064,32 +3064,13 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
30643064
30653065 if (src_type.id ()==ID_bool)
30663066 {
3067- constant_exprt val (irep_idt (), dest_type);
3068-
3069- ieee_floatt a (dest_floatbv_type);
3070-
3071- mp_integer significand;
3072- mp_integer exponent;
3073-
30743067 out << " (ite " ;
30753068 convert_expr (src);
3076- 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);
3084- 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);
3092- out << " )" ;
3069+ out << ' ' ;
3070+ convert_constant (ieee_floatt::one (dest_floatbv_type).to_expr ());
3071+ out << ' ' ;
3072+ convert_constant (ieee_floatt::zero (dest_floatbv_type).to_expr ());
3073+ out << ' )' ;
30933074 }
30943075 else if (src_type.id ()==ID_c_bool)
30953076 {
Original file line number Diff line number Diff line change @@ -470,6 +470,19 @@ void ieee_floatt::extract_base10(
470470 }
471471}
472472
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+
473486void ieee_floatt::build (
474487 const mp_integer &_fraction,
475488 const mp_integer &_exponent)
Original file line number Diff line number Diff line change @@ -220,6 +220,16 @@ class ieee_floatt
220220 return result;
221221 }
222222
223+ static ieee_floatt zero (const ieee_float_spect &spec)
224+ {
225+ ieee_floatt result (spec);
226+ result.make_zero ();
227+ return result;
228+ }
229+
230+ static ieee_floatt one (const floatbv_typet &);
231+ static ieee_floatt one (const ieee_float_spect &);
232+
223233 void make_NaN ();
224234 void make_plus_infinity ();
225235 void make_minus_infinity ();
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ SRC += analyses/ai/ai.cpp \
150150 util/get_base_name.cpp \
151151 util/graph.cpp \
152152 util/help_formatter.cpp \
153+ util/ieee_float.cpp \
153154 util/interval/add.cpp \
154155 util/interval/bitwise.cpp \
155156 util/interval/comparisons.cpp \
Original file line number Diff line number Diff line change 1+ /* ******************************************************************\
2+
3+ Module: Unit tests for ieee_floatt
4+
5+ Author: Daniel Kroening, [email protected] 6+
7+ \*******************************************************************/
8+
9+ #include < util/ieee_float.h>
10+
11+ #include < testing-utils/use_catch.h>
12+
13+ TEST_CASE (" Make an IEEE 754 one" , " [core][util][ieee_float]" )
14+ {
15+ auto spec = ieee_float_spect::single_precision ();
16+ REQUIRE (ieee_floatt::one (spec) == 1 );
17+ }
You can’t perform that action at this time.
0 commit comments