Just (-0/1) is now printed as Just (-0.0), not Just -0.0; trac #2036
authorIan Lynagh <igloo@earth.li>
Sun, 27 Apr 2008 13:32:30 +0000 (13:32 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 27 Apr 2008 13:32:30 +0000 (13:32 +0000)
GHC/Float.lhs

index d0b7a33..79683f2 100644 (file)
@@ -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}