Floating-point comparisons

IDCC-14
TitleDo not compare floating-point values using == or ~=.
PriorityStrongly recommended
Severity level3
DescriptionDo not compare floating-point values using == or ~=. Rounding errors due to algorithm design or machine precision can cause unexpected results. Use a tolerance instead. Generated code can produce floating-point results different from the MATLAB results.
RationaleRobustness

Avoid:

out = myFcn(in) == sqrt(3);

Instead use:

out = abs(myFcn(in) - sqrt(3)) < 1e-12;