diff options
author | Explorer09 <explorer09@gmail.com> | 2023-07-29 16:24:12 +0800 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-08-18 12:52:28 +0200 |
commit | b416433fbe7ccf935ad4e268396aa423143c2318 (patch) | |
tree | 55a38c76f4f0091ed6b06d7369706bd2f1f6f61e /XUtils.h | |
parent | c6fd64fce8502a4e557711abe9fee394763ac52c (diff) |
Replace isnan() with better comparisons (isgreater(), etc.)
The standard isnan() function is defined to never throw FP exceptions
even when the argument is a "signaling" NaN. This makes isnan() more
expensive than (x != x) expression unless the compiler flag
'-fno-signaling-nans' is given.
Introduce functions isNaN(), isNonnegative(), isPositive(),
sumPositiveValues() and compareRealNumbers(), and replace isnan() in
htop's codebase with the new functions. These functions utilize
isgreater() and isgreaterequal() comparisons, which do not throw FP
exceptions on "quiet" NaNs, which htop uses extensively.
With isnan() removed, there is no need to suppress the warning
'-Wno-c11-extensions' in FreeBSD. Remove the code from 'configure.ac'.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'XUtils.h')
-rw-r--r-- | XUtils.h | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -82,4 +82,9 @@ 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); +/* 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. */ +double sumPositiveValues(const double* array, size_t count); + #endif |