X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FPrelude.lhs;h=0f9aa1a8fd72d986d958b8106e1cbc8c92523ceb;hb=a76db2a07f99716c40e05d73210f80b4e4794b9a;hp=58de2745efe00cd2904c7fca17abefc908f4c447;hpb=cdc022f6f568886cee383427969d06451dd400c6;p=ghc-hetmet.git diff --git a/ghc/lib/std/Prelude.lhs b/ghc/lib/std/Prelude.lhs index 58de274..0f9aa1a 100644 --- a/ghc/lib/std/Prelude.lhs +++ b/ghc/lib/std/Prelude.lhs @@ -1,3 +1,11 @@ +% ------------------------------------------------------------------------------ +% $Id: Prelude.lhs,v 1.22 2000/06/30 13:39:36 simonmar Exp $ +% +% (c) The University of Glasgow, 1992-2000 +% + +\section[Prelude]{Module @Prelude@} + We add the option -fno-implicit-prelude here to tell the reader that special names such as () and -> shouldn't be resolved to Prelude.() and Prelude.-> (as they are normally). -- SDM 8/10/97 @@ -182,36 +190,34 @@ mapM_ f as = sequence_ (map f as) %********************************************************* \begin{code} -{-# SPECIALIZE fromIntegral :: - Int -> Rational, - Integer -> Rational, - Int -> Int, - Int -> Integer, - Int -> Float, - Int -> Double, - Integer -> Int, - Integer -> Integer, - Integer -> Float, - Integer -> Double #-} +{-# RULES +"fromIntegral/Int->Int" fromIntegral = id :: Int -> Int +"fromIntegral/Integer->Integer" fromIntegral = id :: Integer -> Integer +"fromIntegral/Int->Integer" fromIntegral = int2Integer +"fromIntegral/Integer->Int" fromIntegral = integer2Int +"fromIntegral/Int->Rational" forall n . fromIntegral n = int2Integer n :% 1 +"fromIntegral/Integer->Rational" forall n . fromIntegral n = n :% (1 :: Integer) +"fromIntegral/Int->Float" fromIntegral = int2Float +"fromIntegral/Int->Double" fromIntegral = int2Double +"fromIntegral/Integer->Float" forall n . fromIntegral n = encodeFloat n 0 :: Float +"fromIntegral/Integer->Double" forall n . fromIntegral n = encodeFloat n 0 :: Double + #-} fromIntegral :: (Integral a, Num b) => a -> b fromIntegral = fromInteger . toInteger -{-# SPECIALIZE realToFrac :: - Double -> Rational, - Rational -> Double, - Float -> Rational, - Rational -> Float - #-} -realToFrac :: (Real a, Fractional b) => a -> b -realToFrac = fromRational . toRational - {-# RULES -"realToFrac/Double->Float" realToFrac = doubleToFloat "realToFrac/Float->Double" realToFrac = floatToDouble -"realToFrac/Double->Double" realToFrac = id :: Double -> Double -"realToFrac/Float->Float" realToFrac = id :: Float -> Float -"realToFrac/Rational->Rational" realToFrac = id :: Rational -> Rational +"realToFrac/Double->Float" realToFrac = doubleToFloat +"realToFrac/Float->Float" realToFrac = id :: Float -> Float +"realToFrac/Double->Double" realToFrac = id :: Double -> Double +"realToFrac/Rational->Rational" realToFrac = id :: Rational -> Rational +"realToFrac/Float->Rational" realToFrac = rf2rat :: Float -> Rational +"realToFrac/Double->Rational" realToFrac = rf2rat :: Double -> Rational +"realToFrac/Rational->Float" realToFrac = fromRat :: Rational -> Float +"realToFrac/Rational->Double" realToFrac = fromRat :: Rational -> Double #-} +realToFrac :: (Real a, Fractional b) => a -> b +realToFrac = fromRational . toRational doubleToFloat :: Double -> Float doubleToFloat (D# d) = F# (double2Float# d) @@ -219,5 +225,12 @@ doubleToFloat (D# d) = F# (double2Float# d) floatToDouble :: Float -> Double floatToDouble (F# f) = D# (float2Double# f) +{-# SPECIALIZE rf2rat :: + Float -> Rational, + Double -> Rational + #-} +rf2rat :: RealFloat a => a -> Rational +rf2rat x = if n >= 0 then (m * (b ^ n)) :% 1 else m :% (b ^ (-n)) + where (m,n) = decodeFloat x + b = floatRadix x \end{code} -