diff options
author | Explorer09 <explorer09@gmail.com> | 2023-08-17 04:21:05 +0800 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-08-18 12:52:28 +0200 |
commit | 076b913c7f876ba0489b9751043eeb61aa34680f (patch) | |
tree | 35173363985f959a0e77993b07c3b9fe09a2c1c6 /linux/LinuxProcess.c | |
parent | 93d76fd37627a3594f52afda32092fa3858f28dc (diff) |
Compare all percentage fields with compareRealNumbers()
The SPACESHIP_NUMBER() macro does not work well with floating point
values that are possible to be NaNs. Change the compare logic of all
percentage fields of Process entries to use compareRealNumbers().
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'linux/LinuxProcess.c')
-rw-r--r-- | linux/LinuxProcess.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 0a88644c..87561818 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -310,16 +310,6 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces RichString_appendAscii(str, attr, buffer); } -/* Compares floating point values for ordering data entries. In this function, - NaN is considered "less than" any other floating point value (regardless of - sign), and two NaNs are considered "equal" regardless of payload. */ -static int compareRealNumbers(double a, double b) { - int result = isgreater(a, b) - isgreater(b, a); - if (result) - return result; - return !isNaN(a) - !isNaN(b); -} - static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { const LinuxProcess* p1 = (const LinuxProcess*)v1; const LinuxProcess* p2 = (const LinuxProcess*)v2; @@ -385,11 +375,11 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce return SPACESHIP_NUMBER(p1->oom, p2->oom); #ifdef HAVE_DELAYACCT case PERCENT_CPU_DELAY: - return SPACESHIP_NUMBER(p1->cpu_delay_percent, p2->cpu_delay_percent); + return compareRealNumbers(p1->cpu_delay_percent, p2->cpu_delay_percent); case PERCENT_IO_DELAY: - return SPACESHIP_NUMBER(p1->blkio_delay_percent, p2->blkio_delay_percent); + return compareRealNumbers(p1->blkio_delay_percent, p2->blkio_delay_percent); case PERCENT_SWAP_DELAY: - return SPACESHIP_NUMBER(p1->swapin_delay_percent, p2->swapin_delay_percent); + return compareRealNumbers(p1->swapin_delay_percent, p2->swapin_delay_percent); #endif case IO_PRIORITY: return SPACESHIP_NUMBER(LinuxProcess_effectiveIOPriority(p1), LinuxProcess_effectiveIOPriority(p2)); |