[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:11:25 UTC 2010


The following commit has been merged in the master branch:
commit 37e49367bb69f4e1838b6c1db433ec63e9abb6dc
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sat Oct 14 02:50:36 2006 +0100

    Checkpointing

diff --git a/MissingH/Size.hs b/MissingH/Size.hs
index d253cdf..c909c49 100644
--- a/MissingH/Size.hs
+++ b/MissingH/Size.hs
@@ -50,17 +50,18 @@ siOpts = SizeOpts {base = 10,
                    suffixes = "yzafpnum kMGTPEZY",
                    powerIncr = 3}
 
+renderNum opts 0.0 = (0, snd $ renderNum opts 1)
 renderNum opts number =
     (retnum, suffix)
-    where exponent = (logBase (fromIntegral $ base opts) number)::Double
-          lastPower = (firstPower opts) + 
-                      (genericLength(suffixes opts) - 1) * (powerIncr opts)
-          usedexp = 
-              if exponent < fromIntegral (firstPower opts)
-                 then firstPower opts
-                 else if exponent > fromIntegral lastPower
-                      then lastPower
-                      else (truncate exponent `div` (powerIncr opts)) * (powerIncr opts)
-          expidx = (usedexp - (firstPower opts)) `div` (powerIncr opts)
+    where incrList = map idx2pwr [0..genericLength (suffixes opts) - 1]
+          incrIdxList = zip incrList [0..]
+          idx2pwr i = i * powerIncr opts + firstPower opts
+          
+          (usedexp, expidx) =
+              case find 
+                  (\(x, _) -> (fromIntegral $ base opts) ** (fromIntegral x) <= number) 
+                  (reverse incrIdxList) of
+                  Just x -> x
+                  Nothing -> last incrIdxList
           suffix = (suffixes opts !! (fromIntegral expidx))
           retnum = number / ((fromIntegral (base opts) ** (fromIntegral usedexp)))
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list