From ce2ff6ef6dced7abbe127ff0c5b0bfd74900621d Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 23 Feb 2010 18:34:02 -0500 Subject: [PATCH] fenv: Add support for suppressing exceptions across a computation. --- Data/Floating/Environment.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Data/Floating/Environment.hs b/Data/Floating/Environment.hs index 7aea8e6..74b2015 100644 --- a/Data/Floating/Environment.hs +++ b/Data/Floating/Environment.hs @@ -45,7 +45,8 @@ module Data.Floating.Environment ( -- during the execution of 'fenvEval'. The easiest way to ensure that this -- does not happen is to only use such expressions as the argument to -- 'pure'; never as the argument to 'fmap'. - fenvEval, withRoundingMode, raiseExceptions, fenvTrace, + fenvEval, withRoundingMode, raiseExceptions, holdExceptions, + holdExceptions_, fenvTrace, -- * Direct access to the floating point environment -- | Special care must be taken when using these functions. Modifying the @@ -245,6 +246,16 @@ raiseExceptions :: [FloatException] -> FEnv a -> FEnv a raiseExceptions ex = liftA2 seq $ FEnv unsafePerformIO (unsafeRaiseExceptions ex) +-- | Save and restore the floating point state across an FEnv computation. +-- The result includes the exceptions returned during this computation. +holdExceptions :: FEnv a -> FEnv (a, [FloatException]) +holdExceptions = FEnv unsafePerformIO . fenvEval + +-- | Same as 'holdExceptions', except that any exceptions raised during the +-- computation are discarded. +holdExceptions_ :: FEnv a -> FEnv a +holdExceptions_ = fmap fst . holdExceptions + -- | This function is to help with debugging the floating point environment -- handling. @fenvTrace msg x@ constructs an FEnv value containing @x@ that -- prints @msg@ (using 'Debug.Trace.trace') whenever the value is extracted. -- 2.11.4.GIT