0.9-0.89 is 0.010000000000000000208166817117217
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, why
0.9-0.89 is 0.010000000000000000208166817117217?
I want to use it in:
if a-b<c sprintf('error') end......
when I use vpa, than I get error in if..
thank you
댓글 수: 0
채택된 답변
Image Analyst
2013년 8월 15일
One of the most frequently asked questions, so see the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
댓글 수: 2
James Tursa
2013년 8월 15일
@John, For your particular example:
>> num2strexact(0.9)
ans =
0.90000000000000002220446049250313080847263336181640625
>> num2strexact(0.89)
ans =
0.89000000000000001332267629550187848508358001708984375
>> num2strexact(0.9-0.89)
ans =
1.00000000000000088817841970012523233890533447265625e-2
As you can see above, none of the numbers involved can be represented exactly in IEEE double precision floating point. You can find NUM2STREXACT here:
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!