Skip to content

Add floatbv_mod_exprt and floatbv_rem_exprt classes #8532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/util/floatbv_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,72 @@ inline ieee_float_op_exprt &to_ieee_float_op_expr(exprt &expr)
return ret;
}

/// \brief IEEE floating-point mod
///
/// Note that this expression does not have a rounding mode.
class floatbv_mod_exprt : public binary_exprt
{
public:
floatbv_mod_exprt(exprt _lhs, exprt _rhs)
: binary_exprt(_lhs, ID_floatbv_mod, _rhs, _lhs.type())
{
}
};

/// \brief Cast an exprt to a \ref floatbv_mod_exprt
///
/// \a expr must be known to be \ref floatbv_mod_exprt.
///
/// \param expr: Source expression
/// \return Object of type \ref floatbv_mod_exprt
inline const floatbv_mod_exprt &to_floatbv_mod_expr(const exprt &expr)
{
PRECONDITION(expr.id() == ID_floatbv_mod);
floatbv_mod_exprt::check(expr);
return static_cast<const floatbv_mod_exprt &>(expr);
}

/// \copydoc to_floatbv_mod_expr(const exprt &)
inline floatbv_mod_exprt &to_floatbv_mod_expr(exprt &expr)
{
PRECONDITION(expr.id() == ID_floatbv_mod);
floatbv_mod_exprt::check(expr);
return static_cast<floatbv_mod_exprt &>(expr);
}

/// \brief IEEE floating-point rem
///
/// Note that this expression does not have a rounding mode.
class floatbv_rem_exprt : public binary_exprt
{
public:
floatbv_rem_exprt(exprt _lhs, exprt _rhs)
: binary_exprt(_lhs, ID_floatbv_rem, _rhs, _lhs.type())
{
}
};

/// \brief Cast an exprt to a \ref floatbv_rem_exprt
///
/// \a expr must be known to be \ref floatbv_rem_exprt.
///
/// \param expr: Source expression
/// \return Object of type \ref floatbv_rem_exprt
inline const floatbv_rem_exprt &to_floatbv_rem_expr(const exprt &expr)
{
PRECONDITION(expr.id() == ID_floatbv_rem);
floatbv_rem_exprt::check(expr);
return static_cast<const floatbv_rem_exprt &>(expr);
}

/// \copydoc to_floatbv_rem_expr(const exprt &)
inline floatbv_rem_exprt &to_floatbv_rem_expr(exprt &expr)
{
PRECONDITION(expr.id() == ID_floatbv_rem);
floatbv_rem_exprt::check(expr);
return static_cast<floatbv_rem_exprt &>(expr);
}

/// \brief returns the a rounding mode expression for a given
/// IEEE rounding mode, encoded using the recommendation in
/// C11 5.2.4.2.2
Expand Down
3 changes: 2 additions & 1 deletion src/util/format_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ void format_expr_configt::setup()
expr_map[ID_floatbv_minus] = ternary_expr;
expr_map[ID_floatbv_mult] = ternary_expr;
expr_map[ID_floatbv_div] = ternary_expr;
expr_map[ID_floatbv_mod] = ternary_expr;
expr_map[ID_floatbv_mod] = binary_infix_expr;
expr_map[ID_floatbv_rem] = binary_infix_expr;
Comment on lines +357 to +358
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes resolve #8276.


expr_map[ID_constant] =
[](std::ostream &os, const exprt &expr) -> std::ostream & {
Expand Down
Loading