I see a very strange behavior with the C++ Compiler. Below is my sample code. When I debug this code, I did not get any error whereas when I execute, the "IF" condition fails and the error is thrown. As per the value read from Hardware the value of OV when comparing should be 16.50646050 and temp + OVDIFF should be 11.0. I could not understand why the IF condition fails. A strange thing happens when the comparision is changed the following way. i.e if((temp + OVDIFF) < OV ). In this case the IF condition pass and I am not getting any error.
Can someone explain to me the root cause of this strange behavior? How does C++ compiler handle this comparision?
A few cout statements at the appropriate places should show you what is going on;
1. if 0XFFFF is decimal 65535 then 26.45556/65535 is 0.000403686 which is ten times smaller than the figure you quoted.
2. if Hardware_read() function returns 2554 (two thousand, five hundred and fifty four) - then
OV = OV * LSB; = 2554 * 0.000403686 = something like 1.03101 (to five decimal places)
3. OV = OV + LSB = 1.03101 + 0.000403686 = 1.03142 (to 5 decimal places)
4. (temp + OVDIFF) = 10.0 + 1.0 = 11.0
so your if test is if ( 1.03142 >= 11) which is obviously not true.