summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-03-29 00:37:26 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-03-29 00:37:26 +0200
commit3c16b5343e4d4b5b6f4008603a1c4a9bfff1ec92 (patch)
treeac7bf769bfecc3bf7faddd5e04bf1d84d510091e
parent81a231f9fc126edb1cf3f0e030b6846321431a82 (diff)
downloadxmobar-3c16b5343e4d4b5b6f4008603a1c4a9bfff1ec92.tar.gz
xmobar-3c16b5343e4d4b5b6f4008603a1c4a9bfff1ec92.tar.bz2
Battery: some divisions by zero eliminated
-rw-r--r--src/Plugins/Monitors/Batt.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index 7d4242a..a472045 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -123,7 +123,7 @@ readBattery files =
return $ Battery (3600 * a / 1000000) -- wattseconds
(3600 * b / 1000000) -- wattseconds
(c / 1000000) -- volts
- (d / c) -- amperes
+ (if c > 0 then (d / c) else -1) -- amperes
where grab = fmap (read . B.unpack) . B.readFile
readBatteries :: BattOpts -> [Files] -> IO Result
@@ -131,10 +131,12 @@ readBatteries opts bfs =
do bats <- mapM readBattery (take 3 bfs)
ac <- haveAc (onlineFile opts)
let sign = if ac then 1 else -1
- left = sum (map now bats) / sum (map full bats)
+ ft = sum (map full bats)
+ left = if ft > 0 then sum (map now bats) / ft else 0
watts = sign * sum (map voltage bats) * sum (map current bats)
time = if watts == 0 then 0 else sum $ map time' bats
- time' b = (if ac then full b - now b else now b) / (sign * watts)
+ mwatts = if watts == 0 then 1 else sign * watts
+ time' b = (if ac then full b - now b else now b) / mwatts
acstr = if ac then onString opts else offString opts
return $ if isNaN left then NA else Result left watts time acstr