Skip to content

Commit 6c2e056

Browse files
committed
Add floatbv_mod_exprt and floatbv_rem_exprt classes
This documents the existing use of the floatbv_mod and floatbv_rem expressions.
1 parent fd13d3a commit 6c2e056

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/util/floatbv_expr.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,72 @@ inline ieee_float_op_exprt &to_ieee_float_op_expr(exprt &expr)
438438
return ret;
439439
}
440440

441+
/// \brief IEEE floating-point mod
442+
///
443+
/// Note that this expression does not have a rounding mode.
444+
class floatbv_mod_exprt : public binary_exprt
445+
{
446+
public:
447+
floatbv_mod_exprt(exprt _lhs, exprt _rhs)
448+
: binary_exprt(_lhs, ID_floatbv_mod, _rhs, _lhs.type())
449+
{
450+
}
451+
};
452+
453+
/// \brief Cast an exprt to a \ref floatbv_mod_exprt
454+
///
455+
/// \a expr must be known to be \ref floatbv_mod_exprt.
456+
///
457+
/// \param expr: Source expression
458+
/// \return Object of type \ref floatbv_mod_exprt
459+
inline const floatbv_mod_exprt &to_floatbv_mod_expr(const exprt &expr)
460+
{
461+
PRECONDITION(expr.id() == ID_floatbv_mod);
462+
floatbv_mod_exprt::check(expr);
463+
return static_cast<const floatbv_mod_exprt &>(expr);
464+
}
465+
466+
/// \copydoc to_floatbv_mod_expr(const exprt &)
467+
inline floatbv_mod_exprt &to_floatbv_mod_expr(exprt &expr)
468+
{
469+
PRECONDITION(expr.id() == ID_floatbv_mod);
470+
floatbv_mod_exprt::check(expr);
471+
return static_cast<floatbv_mod_exprt &>(expr);
472+
}
473+
474+
/// \brief IEEE floating-point rem
475+
///
476+
/// Note that this expression does not have a rounding mode.
477+
class floatbv_rem_exprt : public binary_exprt
478+
{
479+
public:
480+
floatbv_rem_exprt(exprt _lhs, exprt _rhs)
481+
: binary_exprt(_lhs, ID_floatbv_rem, _rhs, _lhs.type())
482+
{
483+
}
484+
};
485+
486+
/// \brief Cast an exprt to a \ref floatbv_rem_exprt
487+
///
488+
/// \a expr must be known to be \ref floatbv_rem_exprt.
489+
///
490+
/// \param expr: Source expression
491+
/// \return Object of type \ref floatbv_rem_exprt
492+
inline const floatbv_rem_exprt &to_floatbv_rem_expr(const exprt &expr)
493+
{
494+
PRECONDITION(expr.id() == ID_floatbv_rem);
495+
floatbv_rem_exprt::check(expr);
496+
return static_cast<const floatbv_rem_exprt &>(expr);
497+
}
498+
499+
/// \copydoc to_floatbv_rem_expr(const exprt &)
500+
inline floatbv_rem_exprt &to_floatbv_rem_expr(exprt &expr)
501+
{
502+
PRECONDITION(expr.id() == ID_floatbv_rem);
503+
floatbv_rem_exprt::check(expr);
504+
return static_cast<floatbv_rem_exprt &>(expr);
505+
}
506+
441507
/// \brief returns the a rounding mode expression for a given
442508
/// IEEE rounding mode, encoded using the recommendation in
443509
/// C11 5.2.4.2.2

src/util/format_expr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ void format_expr_configt::setup()
354354
expr_map[ID_floatbv_minus] = ternary_expr;
355355
expr_map[ID_floatbv_mult] = ternary_expr;
356356
expr_map[ID_floatbv_div] = ternary_expr;
357-
expr_map[ID_floatbv_mod] = ternary_expr;
357+
expr_map[ID_floatbv_mod] = binary_infix_expr;
358+
expr_map[ID_floatbv_rem] = binary_infix_expr;
358359

359360
expr_map[ID_constant] =
360361
[](std::ostream &os, const exprt &expr) -> std::ostream & {

0 commit comments

Comments
 (0)