% goodFloat.m % Illustrate bad floating point compare in MATLAB % P. Conrad for CISC106 section 99 11/06/2006 length = 10; width = 30; price = 100; pricePerSquareInch = price / (length * width); expectedAnswer = 0.333333 tolerance = 0.0001; if ( abs(pricePerSquareInch - expectedAnswer) < tolerance) fprintf('It worked\n'); else fprintf('It didn''t work\n'); end