summaryrefslogtreecommitdiffstats
path: root/XUtils.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-08-17 04:21:05 +0800
committerBenBE <BenBE@geshi.org>2023-08-18 12:52:28 +0200
commit076b913c7f876ba0489b9751043eeb61aa34680f (patch)
tree35173363985f959a0e77993b07c3b9fe09a2c1c6 /XUtils.c
parent93d76fd37627a3594f52afda32092fa3858f28dc (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 'XUtils.c')
-rw-r--r--XUtils.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/XUtils.c b/XUtils.c
index 9b7735f6..1af0dd4f 100644
--- a/XUtils.c
+++ b/XUtils.c
@@ -12,6 +12,7 @@ in the source distribution for its full text.
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
+#include <math.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
@@ -339,6 +340,16 @@ ssize_t full_write(int fd, const void* buf, size_t count) {
return written;
}
+/* 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. */
+int compareRealNumbers(double a, double b) {
+ int result = isgreater(a, b) - isgreater(b, a);
+ if (result)
+ return result;
+ return !isNaN(a) - !isNaN(b);
+}
+
/* Computes the sum of all positive floating point values in an array.
NaN values in the array are skipped. The returned sum will always be
nonnegative. */

© 2014-2024 Faster IT GmbH | imprint | privacy policy