From: Ian Lynagh Date: Sun, 27 Apr 2008 13:32:30 +0000 (+0000) Subject: Just (-0/1) is now printed as Just (-0.0), not Just -0.0; trac #2036 X-Git-Tag: 2008-05-28~11 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=a5e4b9f4fbd1a148c80294a02e345e84d8945526;p=ghc-base.git Just (-0/1) is now printed as Just (-0.0), not Just -0.0; trac #2036 --- diff --git a/GHC/Float.lhs b/GHC/Float.lhs index d0b7a33..79683f2 100644 --- a/GHC/Float.lhs +++ b/GHC/Float.lhs @@ -292,7 +292,7 @@ instance RealFloat Float where isIEEE _ = True instance Show Float where - showsPrec x = showSigned showFloat x + showsPrec x = showSignedFloat showFloat x showList = showList__ (showsPrec 0) \end{code} @@ -433,7 +433,7 @@ instance RealFloat Double where isIEEE _ = True instance Show Double where - showsPrec x = showSigned showFloat x + showsPrec x = showSignedFloat showFloat x showList = showList__ (showsPrec 0) \end{code} @@ -948,3 +948,21 @@ foreign import ccall unsafe "isDoubleNegativeZero" isDoubleNegativeZero :: Doubl "realToFrac/Double->Double" realToFrac = id :: Double -> Double #-} \end{code} + +%********************************************************* +%* * +\subsection{Utils} +%* * +%********************************************************* + +\begin{code} +showSignedFloat :: (RealFloat a) + => (a -> ShowS) -- ^ a function that can show unsigned values + -> Int -- ^ the precedence of the enclosing context + -> a -- ^ the value to show + -> ShowS +showSignedFloat showPos p x + | x < 0 || isNegativeZero x + = showParen (p > 6) (showChar '-' . showPos (-x)) + | otherwise = showPos x +\end{code}