From 606ec04189d5038f6b5a6cc09cfe2e1ee10f8dad Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Fri, 29 May 2009 08:35:49 +0000 Subject: [PATCH] Make two type defaults explicit Now that -Werror rejects programs that use silent type-class defaulting, we must commit in the source code. I've used Double in CPUTime, which is the same as was picked automatically before, but I expect Float would be ok. realToInteger :: Real a => a -> Integer realToInteger ct = round (realToFrac ct :: Double) In GHC.Float I used Float (rather that than the auto-picked Double) because I'm pretty certain it has enough precision. -- f :: Integer, log :: Float -> Float, -- ceiling :: Float -> Int ceiling ((log (fromInteger (f+1) :: Float) + --- GHC/Float.lhs | 4 +++- System/CPUTime.hsc | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/GHC/Float.lhs b/GHC/Float.lhs index d68119c..3059db9 100644 --- a/GHC/Float.lhs +++ b/GHC/Float.lhs @@ -625,7 +625,9 @@ floatToDigits base x = -- Haskell promises that p-1 <= logBase b f < p. (p - 1 + e0) * 3 `div` 10 else - ceiling ((log (fromInteger (f+1)) + + -- f :: Integer, log :: Float -> Float, + -- ceiling :: Float -> Int + ceiling ((log (fromInteger (f+1) :: Float) + fromIntegral e * log (fromInteger b)) / log (fromInteger base)) --WAS: fromInt e * log (fromInteger b)) diff --git a/System/CPUTime.hsc b/System/CPUTime.hsc index b5d86d8..307b2a2 100644 --- a/System/CPUTime.hsc +++ b/System/CPUTime.hsc @@ -37,6 +37,11 @@ import Foreign.C #include "HsBase.h" #endif +realToInteger :: Real a => a -> Integer +realToInteger ct = round (realToFrac ct :: Double) + -- CTime, CClock, CUShort etc are in Real but not Fractional, + -- so we must convert to Double before we can round it + #ifdef __GLASGOW_HASKELL__ -- ----------------------------------------------------------------------------- -- |Computation 'getCPUTime' returns the number of picoseconds CPU time @@ -64,7 +69,6 @@ getCPUTime = do u_usec <- (#peek struct timeval,tv_usec) ru_utime :: IO CTime s_sec <- (#peek struct timeval,tv_sec) ru_stime :: IO CTime s_usec <- (#peek struct timeval,tv_usec) ru_stime :: IO CTime - let realToInteger = round . realToFrac :: Real a => a -> Integer return ((realToInteger u_sec * 1000000 + realToInteger u_usec + realToInteger s_sec * 1000000 + realToInteger s_usec) * 1000000) @@ -77,7 +81,6 @@ foreign import ccall unsafe getrusage :: CInt -> Ptr CRUsage -> IO CInt times p_tms u_ticks <- (#peek struct tms,tms_utime) p_tms :: IO CClock s_ticks <- (#peek struct tms,tms_stime) p_tms :: IO CClock - let realToInteger = round . realToFrac :: Real a => a -> Integer return (( (realToInteger u_ticks + realToInteger s_ticks) * 1000000000000) `div` fromIntegral clockTicks) -- 1.7.10.4