From b416433fbe7ccf935ad4e268396aa423143c2318 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 29 Jul 2023 16:24:12 +0800 Subject: 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 --- freebsd/FreeBSDMachine.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'freebsd') diff --git a/freebsd/FreeBSDMachine.c b/freebsd/FreeBSDMachine.c index 26da667a..f5d228c8 100644 --- a/freebsd/FreeBSDMachine.c +++ b/freebsd/FreeBSDMachine.c @@ -281,24 +281,21 @@ static inline void FreeBSDMachine_scanCPU(Machine* super) { // propagate frequency to all cores if only supplied for CPU 0 if (cpus > 1) { if (super->settings->showCPUTemperature) { - double maxTemp = NAN; + double maxTemp = -HUGE_VAL; for (unsigned int i = 1; i < maxcpu; i++) { - const double coreTemp = this->cpus[i].temperature; - if (isnan(coreTemp)) - continue; - - maxTemp = MAXIMUM(maxTemp, coreTemp); + if (isgreater(this->cpus[i].temperature, maxTemp)) { + maxTemp = this->cpus[i].temperature; + this->cpus[0].temperature = maxTemp; + } } - - this->cpus[0].temperature = maxTemp; } if (super->settings->showCPUFrequency) { const double coreZeroFreq = this->cpus[1].frequency; double freqSum = coreZeroFreq; - if (!isnan(coreZeroFreq)) { + if (isNonnegative(coreZeroFreq)) { for (unsigned int i = 2; i < maxcpu; i++) { - if (isnan(this->cpus[i].frequency)) + if (!isNonnegative(this->cpus[i].frequency)) this->cpus[i].frequency = coreZeroFreq; freqSum += this->cpus[i].frequency; -- cgit v1.2.3