Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I found strange error in matlab R2013a calculation using0 'floor'

조회 수: 1 (최근 30일)
Eugen
Eugen 2013년 10월 25일
마감: MATLAB Answer Bot 2021년 8월 20일
Use variable c1=0.011. c1 is multiplied by 10 until c1=11. Then use floor(c1) and get value 10
c1=0.011;
c1=c1*10;
c1=c1*10;
c1=c1*10;
floor (c1)
ans =
10
Then use variable c1=0.0011. c1 is multiplied by 10 until c1=11. Then use floor(c1) and get value 11
c1=0.0011;
c1=c1*10;
c1=c1*10;
c1=c1*10;
c1=c1*10;
floor (c1)
ans =
11
Then use variable c1=0.11. c1 is multipled by 10 until c1=11. Then use floor(c1) and get value 11
c1=0.11;
c1=c1*10;
c1=c1*10;
floor (c1)
ans =
11
WHY the first result differ from second and third?

답변 (1개)

A Jenkins
A Jenkins 2013년 10월 25일
Because floating point math is a strange thing.
Try setting
format long
and then rerun your above calculations. (Remove the semicolons so you can the results.)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by