From a5e4b9f4fbd1a148c80294a02e345e84d8945526 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sun, 27 Apr 2008 13:32:30 +0000 Subject: [PATCH] Just (-0/1) is now printed as Just (-0.0), not Just -0.0; trac #2036 --- GHC/Float.lhs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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} -- 1.7.10.4