Skip to content

Commit

Permalink
Don't fold constants if they produce NaNs or infinites
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Dec 15, 2023
1 parent 1d0e800 commit 04e4300
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Language/Fixpoint/Solver/Simplify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ applyConstantFolding bop e1 e2 =
getOp _ = Nothing

cfR :: Bop -> Double -> Double -> Maybe Expr
cfR bop left right = fmap go (getOp' bop)
cfR bop left right = go (getOp' bop)
where
go f = ECon $ R $ f left right
go (Just f) =
let x = f left right
in if isNaN x || isInfinite x then Just $ ECon (R x)
else Nothing
go Nothing = Nothing

getOp' Div = Just (/)
getOp' RDiv = Just (/)
Expand Down

0 comments on commit 04e4300

Please sign in to comment.