fuzzyCompare

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

Lizenz anzeigen

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

Zitieren als

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

Kompatibilität der MATLAB-Version
Erstellt mit R2012a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0