Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Add Ian Remmler to LICENSE
[slstatus.git]
/
components
/
battery.c
diff --git
a/components/battery.c
b/components/battery.c
index
6105a37
..
99e09d5
100644
(file)
--- a/
components/battery.c
+++ b/
components/battery.c
@@
-1,5
+1,4
@@
/* See LICENSE file for copyright and license details. */
/* See LICENSE file for copyright and license details. */
-#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
@@
-83,7
+82,7
@@
battery_remaining(const char *bat)
{
int charge_now, current_now, m, h;
battery_remaining(const char *bat)
{
int charge_now, current_now, m, h;
-
float
timeleft;
+
double
timeleft;
char path[PATH_MAX], state[12];
if (esnprintf(path, sizeof(path),
char path[PATH_MAX], state[12];
if (esnprintf(path, sizeof(path),
@@
-107,9
+106,13
@@
return NULL;
}
return NULL;
}
- timeleft = (float)charge_now / (float)current_now;
+ if (current_now == 0) {
+ return NULL;
+ }
+
+ timeleft = (double)charge_now / (double)current_now;
h = timeleft;
h = timeleft;
- m = (timeleft - (
float
)h) * 60;
+ m = (timeleft - (
double
)h) * 60;
return bprintf("%dh %dm", h, m);
}
return bprintf("%dh %dm", h, m);
}