floating point precision
显示 更早的评论
I am getting three kind of values for a variable (say vmax) after running my code. First value is 1. Second value is 1.0000 Third value is <1 I applied if else statements here as follows :
if vmax>=1
figure(1);
z=imread('C:\Program Files (x86)\MATLAB71\work\success.jpg');
imshow(z);
else
figure(2);
z=imread('C:\Program Files (x86)\MATLAB71\work\fail.jpg');
imshow(z);
end
As 1.0000 is slightly greater than 1 and I need same output for vmax=1 and vmax = 1.0000
But for few inputs which are giving vmax = 1.0000 , the if else works properly while for the other inputs which are giving vmax = 1.0000 , the if else executes "else" part. I am not getting why is this happening? For the same value of vmax, sometimes if else works the way it should while other times it works maliciously. Please help me.
采纳的回答
更多回答(2 个)
Sean de Wolski
2012-4-9
I'm not toally clear on your question. If you're looking to see if something is close to 1,
isclose21 = abs(x-1)<1^-10; %is absolute difference between x and 1 less than 1e-10?
类别
在 帮助中心 和 File Exchange 中查找有关 Data Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!