@@ -10,6 +10,7 @@ Author: Daniel Kroening, kroening@kroening.com
1010
1111#include < util/arith_tools.h>
1212#include < util/bitvector_types.h>
13+ #include < util/ieee_float.h>
1314
1415std::ostream &smt2_format_rec (std::ostream &out, const typet &type)
1516{
@@ -92,7 +93,33 @@ std::ostream &smt2_format_rec(std::ostream &out, const exprt &expr)
9293 }
9394 else if (expr_type.id () == ID_floatbv)
9495 {
95- out << value;
96+ const ieee_floatt v = ieee_floatt (constant_expr);
97+ const size_t e = v.spec .e ;
98+ const size_t f = v.spec .f + 1 ; // SMT-LIB counts the hidden bit
99+
100+ if (v.is_NaN ())
101+ {
102+ out << " (_ NaN " << e << " " << f << " )" ;
103+ }
104+ else if (v.is_infinity ())
105+ {
106+ if (v.get_sign ())
107+ out << " (_ -oo " << e << " " << f << " )" ;
108+ else
109+ out << " (_ +oo " << e << " " << f << " )" ;
110+ }
111+ else
112+ {
113+ // Zero, normal or subnormal
114+
115+ mp_integer binary = v.pack ();
116+ std::string binaryString (integer2binary (v.pack (), v.spec .width ()));
117+
118+ out << " (fp "
119+ << " #b" << binaryString.substr (0 , 1 ) << " "
120+ << " #b" << binaryString.substr (1 , e) << " "
121+ << " #b" << binaryString.substr (1 + e, f - 1 ) << " )" ;
122+ }
96123 }
97124 else
98125 DATA_INVARIANT (false , " unhandled constant: " + expr_type.id_string ());
0 commit comments