
#14425: approxRational is wrong when (rat - eps) overflows in negative direction -------------------------------------+------------------------------------- Reporter: danielk | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by danielk): I suggest the following simple fix. Convert rat and eps to Rational before subtracting and adding epsilon. This eliminates the possibility of overflow (in either direction). {{{ approxRational :: (RealFrac a) => a -> a -> Rational approxRational rat eps = simplest (toRational rat - toRational eps) (toRational rat + toRational eps) ... }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14425#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler