@@ -800,6 +800,42 @@ exprt smt2_parsert::function_application()
800800 else
801801 throw error () << " unexpected sort given as operand to to_fp" ;
802802 }
803+ else if (id == " to_fp_unsigned" )
804+ {
805+ if (next_token () != smt2_tokenizert::NUMERAL)
806+ throw error (" expected number after to_fp_unsigned" );
807+
808+ auto width_e = std::stoll (smt2_tokenizer.get_buffer ());
809+
810+ if (next_token () != smt2_tokenizert::NUMERAL)
811+ throw error (" expected second number after to_fp_unsigned" );
812+
813+ auto width_f = std::stoll (smt2_tokenizer.get_buffer ());
814+
815+ if (next_token () != smt2_tokenizert::CLOSE)
816+ throw error (" expected ')' after to_fp_unsigned" );
817+
818+ // width_f *includes* the hidden bit
819+ const ieee_float_spect spec (width_f - 1 , width_e);
820+
821+ auto rounding_mode = expression ();
822+
823+ auto source_op = expression ();
824+
825+ if (next_token () != smt2_tokenizert::CLOSE)
826+ throw error (" expected ')' at the end of to_fp_unsigned" );
827+
828+ if (source_op.type ().id () == ID_unsignedbv)
829+ {
830+ // The operand is hard-wired to be interpreted
831+ // as an unsigned number.
832+ return floatbv_typecast_exprt (
833+ source_op, rounding_mode, spec.to_type ());
834+ }
835+ else
836+ throw error ()
837+ << " unexpected sort given as operand to to_fp_unsigned" ;
838+ }
803839 else
804840 {
805841 throw error () << " unknown indexed identifier '"
0 commit comments