summaryrefslogtreecommitdiff
path: root/libraries/base/System/CPUTime.hsc
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2009-05-29 08:35:49 +0000
committersimonpj@microsoft.com <unknown>2009-05-29 08:35:49 +0000
commitac45944d7319c86fbddd6949284917ef0ed6c741 (patch)
treec3d5ed9fea73a39f64f6d4e4d310b9b641bcfac7 /libraries/base/System/CPUTime.hsc
parentc40a70c34e3f730234cc3406876cdfbdd6c64b43 (diff)
downloadhaskell-ac45944d7319c86fbddd6949284917ef0ed6c741.tar.gz
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) +
Diffstat (limited to 'libraries/base/System/CPUTime.hsc')
-rw-r--r--libraries/base/System/CPUTime.hsc7
1 files changed, 5 insertions, 2 deletions
diff --git a/libraries/base/System/CPUTime.hsc b/libraries/base/System/CPUTime.hsc
index b5d86d873e..307b2a2ddb 100644
--- a/libraries/base/System/CPUTime.hsc
+++ b/libraries/base/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)