07-24-2012 03:09 AM
In CVI the pow() function does not set the errno variable to indicate that an underflow condition has occurred - is this by design, and is there a workaround? (I would have assumed errno set to ERANGE).
Solved! Go to Solution.
07-26-2012 11:25 AM
thanks a lot for addressing the issue! I have seen this article before when searching for a solution, but I have not studied it further because to me it looked like a MS C specific solution.
In my understanding whether or not errno is set to ERANGE is implementation specific, and it appears to me that in the present implementation of CVI the pow() function does not set this value. Maybe I should try using the clang compiler to see if it behaves differently...
Or did I miss your point?
07-27-2012 02:43 AM
Firstly, I would not think CVI and MS implementations of such a standart function will be different.
Even if they are different, since it looks like they both suffer from the same problem, the workaround can be applicable to both.
When I searched for more info on _matherr. I found this. It says "_UNDERFLOW is not supported" in _matherr.
So the workaround still may not work.
07-31-2012 06:02 AM
the pow() function is a mathematics function. It will only appear a error in the environment. In your application, you have to programm your own error-handling for that function.
You can check the values of the parameter befor the function or check the result at the end (=NAN [not a Number]). I recommend to check the values befor the function.
I hope this helps you further!
07-31-2012 08:47 AM
thanks for your email, it made me smile... Yes, I am aware that pow() is a mathematics function, I even know what it is supposed to do
OK, so now let's be more serious: I have seen that CVI's C99 extensions provide the classification of FP_SUBNORMAL, may be that's something to try...? How would one use it?
08-02-2012 06:30 AM
Thanks for your reply!
errno is not set at all. That's 'o.k.' because that's how it is documented (the case of underflow is not addressed in the docs), but for me it would be better if I could detect underflow events. Say you want to calculate pow ( 8553.0, -165.5 ) the return value is zero because the result is close to zero, i.e. too small to be represented within the 64 bit data range of doubles.
08-02-2012 02:17 PM
Okay, I see. At first, I was considering that the docs did address this: I was interpreting the sentence "If the magnitude of Input Value and Power are such that the computed value cannot be represented as a double..." to be referring to underflows as well, but since the rest of the paragraph says that, in that case, the function returns Infinity, then it's clearly not trying to address underflow.
The value of errno on underflow is not specified by the standard ("If the result underflows, the function returns a value whose magnitude is no greater than the smallest normalized positive number in the specified type and is otherwise implementation- defined; whether errno acquires the value ERANGE is implementation-defined.") but we'll take a look at it for the next version.
08-02-2012 03:21 PM
So many looks for the next version I guess CVI2013 should be released on my birthday
OK, the question is almost solved, may be you could kindly enlighten me about the functionality of FP_SUBNORMAL, what is it supposed to do?