fuzzyCompare

Compares two floating point values and returns true if they are considered equal, false otherwise
301.0 次下载
更新时间 2012/6/14

查看许可证

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

引用格式

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

MATLAB 版本兼容性
创建方式 R2012a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0