[project @ 2001-02-22 16:10:12 by rrt]
[ghc-hetmet.git] / ghc / lib / std / Numeric.lhs
index fa56105..974c84b 100644 (file)
@@ -1,6 +1,9 @@
+% -----------------------------------------------------------------------------
+% $Id: Numeric.lhs,v 1.11 2001/02/22 13:17:58 simonpj Exp $
 %
-% (c) The AQUA Project, Glasgow University, 1997-99
+% (c) The University of Glasgow, 1997-2000
 %
+
 \section[Numeric]{Numeric interface}
 
 Odds and ends, mostly functions for reading and showing
@@ -8,7 +11,6 @@ Odds and ends, mostly functions for reading and showing
 
 
 \begin{code}
-{-# OPTIONS -fno-implicit-prelude #-}
 module Numeric
 
         ( fromRat          -- :: (RealFloat a) => Rational -> a
@@ -34,19 +36,23 @@ module Numeric
           -- Implementation checked wrt. Haskell 98 lib report, 1/99.
        ) where
 
+import Char
+
 #ifndef __HUGS__
-import PrelBase
-import PrelMaybe
-import PrelShow
-import PrelArr
-import PrelNum
-import PrelNumExtra
-import PrelRead
-import PrelErr ( error )
+       -- GHC imports
+import Prelude         -- For dependencies
+import PrelBase                ( Char(..) )
+import PrelRead                -- Lots of things
+import PrelReal                ( showSigned )
+import PrelFloat       ( fromRat, FFFormat(..), 
+                         formatRealFloat, floatToDigits, showFloat
+                       )
+import PrelNum         ( ord_0 )
 #else
-import Char
+       -- Hugs imports
 import Array
 #endif
+
 \end{code}
 
 #ifndef __HUGS__
@@ -72,6 +78,16 @@ implements the formatting itself is in @PrelNum@ to avoid
 mutual module deps.
 
 \begin{code}
+{-# SPECIALIZE showEFloat ::
+       Maybe Int -> Float  -> ShowS,
+       Maybe Int -> Double -> ShowS #-}
+{-# SPECIALIZE showFFloat ::
+       Maybe Int -> Float  -> ShowS,
+       Maybe Int -> Double -> ShowS #-}
+{-# SPECIALIZE showGFloat ::
+       Maybe Int -> Float  -> ShowS,
+       Maybe Int -> Double -> ShowS #-}
+
 showEFloat    :: (RealFloat a) => Maybe Int -> a -> ShowS
 showFFloat    :: (RealFloat a) => Maybe Int -> a -> ShowS
 showGFloat    :: (RealFloat a) => Maybe Int -> a -> ShowS
@@ -82,7 +98,15 @@ showGFloat d x =  showString (formatRealFloat FFGeneric d x)
 
 \end{code}
 
-#else
+#else  
+
+%*********************************************************
+%*                                                     *
+       All of this code is for Hugs only
+       GHC gets it from PrelFloat!
+%*                                                     *
+%*********************************************************
+
 \begin{code}
 -- This converts a rational to a floating.  This should be used in the
 -- Fractional instances of Float and Double.
@@ -283,7 +307,7 @@ floatToDigits base x =
                         (p - 1 + e0) * 3 `div` 10
                     else
                         ceiling ((log (fromInteger (f+1)) + 
-                                 fromInt e * log (fromInteger b)) / 
+                                 fromIntegral e * log (fromInteger b)) / 
                                   log (fromInteger base))
                 fixup n =
                     if n >= 0 then