1. Comparison between bool variables and zero values
The IF Statements for comparing bool values with zero values are as follows:
Bool btestflag = false;
A). If (btestflag = 0); If (btestflag = 1 );
B). If (btestflag = true); If (btestflag = false );
C). If (btestflag); If (! Btestflag );
Writing Method A: btestflag is easy to misunderstand as an integer variable. It does not mean that some compilers define false and the true values are all the same 0, 1. Therefore, this writing method is not good;
B's Writing Method: I think this method is feasible, but the bool type value should be assigned to btestflag value instead of integer value conversion, this may cause errors due to different compilers;
C: simple and clear, and achieve the desired effect. If btestflag is trueCode, Jump to the following when false.
2. Compare float variables with zero values
The IF statement for comparing float values with zero values is as follows:
Float ftestval = 0.0;
A). If (ftestval = 0.0); If (ftestval! = 0.0 );
B). If (ftestval >=- epsinon) & (ftestval <= epsinon); // epsinon is the defined precision.