Skip to content

Commit

Permalink
Fix simplifying of fp NaN literal (non)equalities
Browse files Browse the repository at this point in the history
NaN floating point values should not be equal to any other value. This
behavior is correctly implemented in the FpLitExpr #eq and #neq methods.
To utilize that, manual comparison in simplification is now swapped to
call these methods, resulting in correct behaviour: (= (NaN) (NaN)) for
example now simplifies to false.
  • Loading branch information
RipplB committed Jul 6, 2024
1 parent 302e861 commit 021194d
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public static ExprSimplifier create(final SimplifierLevel level) {
@SuppressWarnings("unchecked")
public <T extends Type> Expr<T> simplify(final Expr<T> expr, final Valuation valuation) {
return (Expr<T>) TABLE.dispatch(expr, valuation);
} private final DispatchTable2<Valuation, Expr<?>> TABLE = DispatchTable2.<Valuation, Expr<?>>builder()
}

private final DispatchTable2<Valuation, Expr<?>> TABLE = DispatchTable2.<Valuation, Expr<?>>builder()

// Boolean

Expand Down Expand Up @@ -1958,8 +1960,8 @@ private Expr<BoolType> simplifyFpEq(final FpEqExpr expr, final Valuation val) {
final Expr<FpType> leftOp = simplify(expr.getLeftOp(), val);
final Expr<FpType> rightOp = simplify(expr.getRightOp(), val);

if (leftOp instanceof FpLitExpr && rightOp instanceof FpLitExpr) {
return Bool(leftOp.equals(rightOp));
if (leftOp instanceof FpLitExpr lLit && rightOp instanceof FpLitExpr rLit) {
return lLit.eq(rLit);
}

return expr.with(leftOp, rightOp);
Expand Down Expand Up @@ -2024,8 +2026,8 @@ private Expr<BoolType> simplifyFpNeq(final FpNeqExpr expr, final Valuation val)
final Expr<FpType> leftOp = simplify(expr.getLeftOp(), val);
final Expr<FpType> rightOp = simplify(expr.getRightOp(), val);

if (leftOp instanceof FpLitExpr && rightOp instanceof FpLitExpr) {
return Bool(!leftOp.equals(rightOp));
if (leftOp instanceof FpLitExpr lLit && rightOp instanceof FpLitExpr rLit) {
return lLit.neq(rLit);
} else if (leftOp instanceof RefExpr && rightOp instanceof RefExpr) {
if (level != LITERAL_ONLY && leftOp.equals(rightOp)) {
return False();
Expand Down

0 comments on commit 021194d

Please sign in to comment.