I would like to test if the value returned in a double is infinity. I tried comparing if the bytes of the double were equal to 0x7F00000000000000 and I tried if(atof(“infinity”) == doubleVal) but the first always returned false and the second always returned true. I see a function infinity( ) in mathALib that looked like it might be helpful but I’m not sure how to include that lib. I can compile using that function but get a link error once on the cRIO. So really two questions here:
How to link with a lib like mathALib?
A nice way to check for infinity (and maybe NaN while your at it)?
I am using a gear tooth sensor and am using the GearTooth class. I call GetPeriod() from the Counter superclass to calculate a rate. At very slow speeds it will sometimes return Inf because no teeth have passed by since I last called GetPeriod I guess. I want to detect Inf and play some games with the rate value I am returning.
In labview, at least, you can configure the timer so you can define what the time period is where if no pulses are seen, it is considered stopped. You can also get a stopped boolean value. I expect there is something similar in C++ if you dig around in the library. You could then use the stopped value instead of testing for infinity.
Ah good point, there are two function in Counter SetMaxPeriod and SetUpdateWhenEmpty which are there to configure this sort of behavior. Those are likely the best solution to my problem. Still if anyone can answer the two original questions I would appreciate it.
I don’t have WindRiver anywhere near me at the moment, but assuming math.h exists, there are functions like isinf(x) and/or the constants FP_INFINITE and FP_NAN in the floating point standards. So you might be able to write
#include <math.h>
if (isinf(1.0/0.0)) {
do something
}
On most development systems, including math.h that means you also need to link against the math library (-lm). I don’t know if WindRiver would do that automatically.
It’s a single mode OS… if you have a header that defines the symbols and you are not trying to statically link the library in, then you just need to load your library. The symbols will be looked up at runtime.