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!