28 if(src_type==dest_type)
31 if(src_type.
id() == ID_c_bit_field)
44 if(src_type.
id()==ID_floatbv &&
45 dest_type.
id()==ID_floatbv)
53 else if(src_type.
id()==ID_signedbv &&
54 dest_type.
id()==ID_floatbv)
59 else if(src_type.
id()==ID_unsignedbv &&
60 dest_type.
id()==ID_floatbv)
65 else if(src_type.
id()==ID_floatbv &&
66 dest_type.
id()==ID_signedbv)
72 else if(src_type.
id()==ID_floatbv &&
73 dest_type.
id()==ID_unsignedbv)
95 "both operands of a floating point operator must match the expression type",
102 if(expr.
type().
id() == ID_floatbv)
106 if(expr.
id()==ID_floatbv_plus)
107 return float_utils.
add_sub(lhs_as_bv, rhs_as_bv,
false);
108 else if(expr.
id()==ID_floatbv_minus)
109 return float_utils.
add_sub(lhs_as_bv, rhs_as_bv,
true);
110 else if(expr.
id()==ID_floatbv_mult)
111 return float_utils.
mul(lhs_as_bv, rhs_as_bv);
112 else if(expr.
id()==ID_floatbv_div)
113 return float_utils.
div(lhs_as_bv, rhs_as_bv);
117 else if(expr.
type().
id() == ID_complex)
121 if(subtype.
id()==ID_floatbv)
129 sub_width > 0 && width % sub_width == 0,
130 "width of a complex subtype must be positive and evenly divide the "
131 "width of the complex expression");
133 sub_width * 2 == width,
"a complex type consists of exactly two parts");
135 bvt lhs_real{lhs_as_bv.begin(), lhs_as_bv.begin() + sub_width};
136 bvt rhs_real{rhs_as_bv.begin(), rhs_as_bv.begin() + sub_width};
138 bvt lhs_imag{lhs_as_bv.begin() + sub_width, lhs_as_bv.end()};
139 bvt rhs_imag{rhs_as_bv.begin() + sub_width, rhs_as_bv.end()};
141 bvt result_real, result_imag;
143 if(expr.
id() == ID_floatbv_plus || expr.
id() == ID_floatbv_minus)
145 result_real = float_utils.
add_sub(
146 lhs_real, rhs_real, expr.
id() == ID_floatbv_minus);
147 result_imag = float_utils.
add_sub(
148 lhs_imag, rhs_imag, expr.
id() == ID_floatbv_minus);
150 else if(expr.
id() == ID_floatbv_mult)
155 result_real = float_utils.
add_sub(
156 float_utils.
mul(lhs_real, rhs_real),
157 float_utils.
mul(lhs_imag, rhs_imag),
159 result_imag = float_utils.
add_sub(
160 float_utils.
mul(lhs_real, rhs_imag),
161 float_utils.
mul(lhs_imag, rhs_real),
164 else if(expr.
id() == ID_floatbv_div)
167 float_utils.
mul(lhs_real, rhs_real),
168 float_utils.
mul(lhs_imag, rhs_imag),
171 float_utils.
mul(lhs_imag, rhs_real),
172 float_utils.
mul(lhs_real, rhs_imag),
176 float_utils.
mul(rhs_real, rhs_real),
177 float_utils.
mul(rhs_imag, rhs_imag),
180 result_real = float_utils.
div(numerator_real, denominator);
181 result_imag = float_utils.
div(numerator_imag, denominator);
186 bvt result_bv = std::move(result_real);
187 result_bv.reserve(width);
190 std::make_move_iterator(result_imag.begin()),
191 std::make_move_iterator(result_imag.end()));
Pre-defined bitvector types.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
std::size_t get_width() const
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
virtual bvt convert_floatbv_op(const ieee_float_op_exprt &)
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
virtual std::size_t boolbv_width(const typet &type) const
virtual bvt convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
Base class for all expressions.
typet & type()
Return the type of the expression.
void set_rounding_mode(const bvt &)
bvt from_unsigned_integer(const bvt &)
virtual bvt mul(const bvt &src1, const bvt &src2)
bvt to_unsigned_integer(const bvt &src, std::size_t int_width)
virtual bvt div(const bvt &src1, const bvt &src2)
bvt from_signed_integer(const bvt &)
bvt conversion(const bvt &src, const ieee_float_spect &dest_spec)
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
bvt to_signed_integer(const bvt &src, std::size_t int_width)
Semantic type conversion from/to floating-point formats.
IEEE floating-point operations These have two data operands (op0 and op1) and one rounding mode (op2)...
const irep_idt & id() const
const typet & subtype() const
Semantic type conversion.
The type of an expression, extends irept.
API to expression classes for floating-point arithmetic.
std::vector< literalt > bvt
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
const type_with_subtypet & to_type_with_subtype(const typet &type)