mirror of https://github.com/xzeldon/htop.git
Process: Handle rounding ambiguity between 99.9 and 100.0
Depending upon default behavior of the compiler and floating-point environment, compiler could round down the value between "99.9" and "100.0" to "99.0", instead of rounding it to the nearest value, "100.0". Note: The floating-point environment access and modification is only meaningful when "#pragma STD FENV_ACCESS" is set to "ON"[1]. Otherwise implementation is free to assume that floating-point control modes are always the default. So it would be a good idea to address the rounding ambiguity between "99.9" and "100.0" to become compiler agnostic. [1]: https://en.cppreference.com/w/c/numeric/fenv Credits: @Explorer09, thanks for the suggestion.
This commit is contained in:
parent
da653f8148
commit
6133cac721
|
@ -741,7 +741,9 @@ void Process_printPercentage(float val, char* buffer, int n, int* attr) {
|
||||||
xSnprintf(buffer, n, "%4.1f ", val);
|
xSnprintf(buffer, n, "%4.1f ", val);
|
||||||
} else {
|
} else {
|
||||||
*attr = CRT_colors[PROCESS_MEGABYTES];
|
*attr = CRT_colors[PROCESS_MEGABYTES];
|
||||||
xSnprintf(buffer, n, "%4d ", (int)val);
|
if (val < 100.0F)
|
||||||
|
val = 100.0F; // Don't round down and display "val" as "99".
|
||||||
|
xSnprintf(buffer, n, "%4.0f ", val);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*attr = CRT_colors[PROCESS_SHADOW];
|
*attr = CRT_colors[PROCESS_SHADOW];
|
||||||
|
|
Loading…
Reference in New Issue