fuzzyCompare

Compares two floating point values and returns true if they are considered equal, false otherwise
301 Downloads
Updated 14 Jun 2012

View License

Compares two floating point values and returns true if they are considered equal, false otherwise. Inspired by Qt's qFuzzyCompare function. Two floating point variables that should in theory be equal, might not always be equal, due to mthe finite number of bits that a computational device uses to store and operate on values.

Ex:
num = 7;
sqrtd = sqrt(num);
sqrtd(2) = sqrt(sqrtd(1));
sqrtd(3) = sqrt(sqrtd(2))
prods(1) = sqrtd(end);
prods(2) = prods(1)^2;
prods(3) = prods(2)^2
finalNum = prods(3)^2
num==finalNum %This is false, though they should be the same
fuzzyCompare( num, finalNum ) %this is true

Cite As

Ivar Eskerud Smith (2024). fuzzyCompare (https://www.mathworks.com/matlabcentral/fileexchange/37160-fuzzycompare), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0