-
-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace isnan() with better comparisons (isgreater(), etc.) #1271
Conversation
Maybe introduce a Furthermore you may update |
Any chance to avoid the |
// Checks if a floating point value is positive. Returns false on a NaN.
static inline bool isPositive(double x) {
return isgreater(x, 0.0);
}
// Checks if a floating point value is nonnegative. Returns false on a NaN.
static inline bool isNonNegative(double x) {
return isgreaterequal(x, 0.0);
}
// Cheaper version of C99 isnan(). Unlike isnan(), this may throw FP exception on a "signaling" NaN.
static inline bool isNan(double x) {
return !isgreaterequal(x, x);
}
That
|
|
LGTM. What's the behaviour for
Fine by me, too.
I think we better avoid the
That's an implementation detail you see when looking at the
I think the sanity check for absolute zero is not strictly needed, as negative temperature exists. Apart from that, using NB, it actually should be |
Infinity is technically not NaN. It would return false even on the C99 standard The difference between standard
Okay. So the inline function
I didn't get it. When using the My question was, when could the summing operation result in a NaN? With the code like the following: percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ] + v[CPU_METER_SOFTIRQ] all the values are supposed to be defined and non-NaN, aren't they? |
Okay, just wanted to make sure, those edge cases are covered.
ACK.
There are some platforms that do not provide all of those values. Thus some of those values can be |
And it looks like a bug when I read it. NaNs propagate during addition, and if any value of the I was considering a function to be added in XUtils.c, but I'm not sure which is the best name for it: double sumPositiveValues(const double* array, size_t count) {
double sum = 0.0;
for (size_t i = 0; i < count; i++) {
if (!isPositive(array[i]))
continue; // Skip negative and NaN values
sum += array[i];
if (!(sum < HUGE_VAL))
break;
}
return sum;
} |
Though |
This |
98182cb
to
88b106c
Compare
7418ce3
to
3e0cb1c
Compare
5eaaaef
to
7661df8
Compare
@Explorer09 Anything left you want to change before we can go ahead with this one? |
|
How much code does this affect? And is this sufficiently distinct from the existing change to go in a different PR? I mean, if this is basically a code change mostly similar to the other changes we've seen so far, i'm quite inclined to say to keep it in this PR. Though if the changes do end up causing a noticeable difference in behaviour, like they probably will, there's good reason to split them just in case we need to partially undo those changes. And although I'd prefer to go ahead with this PR soonish™ there's actually no preasure to have it been done by yesterday. ;-) Call is yours, just don't drag it on for too long. :)
This should be best directed at @natoscott and @smalinux, who mostly worked on that part. |
It should just take a `PCPProcess*` argument rather than a `Process*`. Signed-off-by: Kang-Che Sung <[email protected]>
In PCPProcess_writeField(), the "n" variable should be size_t type. The "n" parameters of Process_printPercentage() and PCPProcess_printDelay() should be size_t type as well. Signed-off-by: Kang-Che Sung <[email protected]>
* Shorter result message for "assume yes (cross compiling)" * Replace grave accent + apostrophe quoting with just apostrophes. It is expected that Autoconf 2.72 updates the quoting as well and the old style has confused a syntax highlighter (Vim). Signed-off-by: Kang-Che Sung <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable.
* Use saturatingSub() when subtracting CPU time and I/O read/write bytes of processes so that the values would never go negative (causing unsigned integer wraparound). * The CPU percentages of processes are now NaN if the time interval between measures (the "delta time") is zero. Make the conditional explicit and avoid division by zero. Previously the percentage values would be 0.0. Note: The saturatingSub() function is not used in cpu_delay_percent, blkio_delay_percent and swapin_delay_percent with a comment added that explains the reason. Signed-off-by: Kang-Che Sung <[email protected]>
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 <[email protected]>
Add a check of the '__SUPPORT_SNAN__' predefined macro and print a warning message if the compiler defines it. The warning is not printed with '--enable-debug' specified as we assume users know what they are doing. :) Signed-off-by: Kang-Che Sung <[email protected]>
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 <[email protected]>
@Explorer09 @BenBE yep, thanks - these are leftovers from using Linux headers/code at one point in the PCP platform. We'd need some PCP metrics to provide those netlink stats, but that doesn't exist currently so I'll open a separate PR to drop these fields for now. |
Just to give a note: This PR is ready for review and merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing, rest LGTM.
Leave this with me, these can use compareRealNumbers but I need to look more closely at the ordering aspect (any change here can be done subsequently). Thanks! |
The standard
isnan()
function is defined to never throw FP exceptions even when the argument is a "signaling" NaN. This makesisnan()
more expensive than(x != x)
expression unless the compiler flag-fno-signaling-nans
is given.Introduce functions
isNaN()
,isNonnegative()
,isPositive()
,sumPositiveValues()
andcompareRealNumbers()
, and replaceisnan()
in htop's codebase with the new functions. These functions utilizeisgreater()
andisgreaterequal()
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 fromconfigure.ac
.