1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 12:10:03 +00:00

Patch to fix rounding error with CPU values.

This commit is contained in:
Filipe Ferreira 2009-05-17 23:30:10 -06:00 committed by Brenden Matthews
parent 6477962dc9
commit 5552f4135e
5 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,7 @@
2009-05-17
* Added support for the Lua programming language
* Added support for rending images by way of IMLIB2
* Patch to fix rounding error with CPU values (thanks Filipe)
2009-05-11
* Added arguments to hwmon for value precalculation

View File

@ -463,7 +463,8 @@ void update_stuff(void)
#endif
}
int round_to_int(float f)
/* Ohkie to return negative values for temperatures */
int round_to_int_temp(float f)
{
if (f >= 0.0) {
return (int) (f + 0.5);
@ -471,3 +472,13 @@ int round_to_int(float f)
return (int) (f - 0.5);
}
}
/* Don't return negative values for cpugraph, bar, gauge, percentage.
* Causes unreasonable numbers to show */
unsigned int round_to_int(float f)
{
if (f >= 0.0) {
return (int) (f + 0.5);
} else {
return 0;
}
}

View File

@ -37,7 +37,9 @@ void format_seconds_short(char *buf, unsigned int n, long t);
void update_x11info(void);
#endif
int round_to_int(float);
int round_to_int_temp(float);
unsigned int round_to_int(float);
extern unsigned long long need_mask;
extern int no_buffers;

View File

@ -3534,7 +3534,7 @@ static void generate_text_internal(char *p, int p_max_size,
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
}
OBJ(cpugraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
new_graph(p, obj->a, obj->b, obj->c, obj->d,
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
100, 1, obj->showaslog);
}

View File

@ -87,7 +87,7 @@ int temp_print(char *p, size_t p_max_size, double n, enum TEMP_UNIT input_unit)
int out;
size_t plen;
out = round_to_int(convert_temp_output(n, input_unit));
out = round_to_int_temp(convert_temp_output(n, input_unit));
plen = spaced_print(p, p_max_size, "%d", 3, out);
return !(plen >= p_max_size);