mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
Explicitly convert type to double to avoid losing precision
Division between integers will also be integer.
Thus, to preserve fractional part explicitly
convert first operand to double.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 28d54aab05
("examples: Introduce domtop")
Signed-off-by: Egor Makrushin <emakrushin@astralinux.ru>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
ab9da5c4ab
commit
f70b7c9772
@ -224,7 +224,7 @@ print_cpu_usage(size_t cpu,
|
||||
* performed has a bad effect on the precision, so instead of dividing
|
||||
* @now_params and @then_params by 1000 and then multiplying again by
|
||||
* 100, we divide only once by 10 and get the same result. */
|
||||
usage = (now_params[pos].value.ul - then_params[pos].value.ul) /
|
||||
usage = (double)(now_params[pos].value.ul - then_params[pos].value.ul) /
|
||||
(now - then) / 10;
|
||||
|
||||
if (delim)
|
||||
|
Loading…
Reference in New Issue
Block a user