Skip to content

Commit d8dc00f

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 d8dc00f

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

src/util/floatbv_expr.h

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

441+
/// \brief IEEE floating-point mod
442+
class floatbv_mod_exprt : public binary_exprt
443+
{
444+
public:
445+
floatbv_mod_exprt(exprt op, exprt rounding)
446+
: binary_exprt(op, ID_floatbv_mod, std::move(rounding), op.type())
447+
{
448+
}
449+
450+
exprt &op()
451+
{
452+
return op0();
453+
}
454+
455+
const exprt &op() const
456+
{
457+
return op0();
458+
}
459+
460+
exprt &rounding_mode()
461+
{
462+
return op1();
463+
}
464+
465+
const exprt &rounding_mode() const
466+
{
467+
return op1();
468+
}
469+
};
470+
471+
/// \brief Cast an exprt to a \ref floatbv_mod_exprt
472+
///
473+
/// \a expr must be known to be \ref floatbv_mod_exprt.
474+
///
475+
/// \param expr: Source expression
476+
/// \return Object of type \ref floatbv_mod_exprt
477+
inline const floatbv_mod_exprt &to_floatbv_mod_expr(const exprt &expr)
478+
{
479+
PRECONDITION(expr.id() == ID_floatbv_mod);
480+
floatbv_mod_exprt::check(expr);
481+
return static_cast<const floatbv_mod_exprt &>(expr);
482+
}
483+
484+
/// \copydoc to_floatbv_mod_expr(const exprt &)
485+
inline floatbv_mod_exprt &to_floatbv_mod_expr(exprt &expr)
486+
{
487+
PRECONDITION(expr.id() == ID_floatbv_mod);
488+
floatbv_mod_exprt::check(expr);
489+
return static_cast<floatbv_mod_exprt &>(expr);
490+
}
491+
492+
/// \brief IEEE floating-point rem
493+
class floatbv_rem_exprt : public binary_exprt
494+
{
495+
public:
496+
floatbv_rem_exprt(exprt op, exprt rounding)
497+
: binary_exprt(op, ID_floatbv_rem, std::move(rounding), op.type())
498+
{
499+
}
500+
501+
exprt &op()
502+
{
503+
return op0();
504+
}
505+
506+
const exprt &op() const
507+
{
508+
return op0();
509+
}
510+
511+
exprt &rounding_mode()
512+
{
513+
return op1();
514+
}
515+
516+
const exprt &rounding_mode() const
517+
{
518+
return op1();
519+
}
520+
};
521+
522+
/// \brief Cast an exprt to a \ref floatbv_rem_exprt
523+
///
524+
/// \a expr must be known to be \ref floatbv_rem_exprt.
525+
///
526+
/// \param expr: Source expression
527+
/// \return Object of type \ref floatbv_rem_exprt
528+
inline const floatbv_rem_exprt &to_floatbv_rem_expr(const exprt &expr)
529+
{
530+
PRECONDITION(expr.id() == ID_floatbv_rem);
531+
floatbv_rem_exprt::check(expr);
532+
return static_cast<const floatbv_rem_exprt &>(expr);
533+
}
534+
535+
/// \copydoc to_floatbv_rem_expr(const exprt &)
536+
inline floatbv_rem_exprt &to_floatbv_rem_expr(exprt &expr)
537+
{
538+
PRECONDITION(expr.id() == ID_floatbv_rem);
539+
floatbv_rem_exprt::check(expr);
540+
return static_cast<floatbv_rem_exprt &>(expr);
541+
}
542+
441543
/// \brief returns the a rounding mode expression for a given
442544
/// IEEE rounding mode, encoded using the recommendation in
443545
/// 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_prefix_expr;
358+
expr_map[ID_floatbv_rem] = binary_prefix_expr;
358359

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

0 commit comments

Comments
 (0)