From 076b913c7f876ba0489b9751043eeb61aa34680f Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 17 Aug 2023 04:21:05 +0800 Subject: 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 --- XUtils.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'XUtils.h') diff --git a/XUtils.h b/XUtils.h index 68e370b0..fd1087d5 100644 --- a/XUtils.h +++ b/XUtils.h @@ -82,6 +82,11 @@ ssize_t xReadfileat(openat_arg_t dirfd, const char* pathname, void* buffer, size ATTR_ACCESS3_R(2, 3) ssize_t full_write(int fd, const void* buf, size_t count); +/* 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); + /* 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. */ -- cgit v1.2.3