About floor function problem.
조회 수: 5 (최근 30일)
이전 댓글 표시
floor(1.999999999999)=1 floor(1.99999999999999999999999999)=2, why is that?
Floor should return the lower integer right? Thanks.
댓글 수: 0
채택된 답변
Matt J
2012년 10월 23일
편집: Matt J
2012년 10월 23일
If that confuses you, this probably will too:
>> isequal(1.99999999999999999999999999, 2)
ans =
1
Anyway, it has nothing to do with the FLOOR command. It's because your big long decimal can't be distinguished from 2 in floating point.
댓글 수: 6
Matt J
2012년 10월 23일
This one contains an overloaded floor function, if that's what you mean
추가 답변 (1개)
Azzi Abdelmalek
2012년 10월 23일
Just try without floor
a=1.99999999999999999999999999
댓글 수: 8
Walter Roberson
2012년 10월 23일
If you are starting with an integer, then dividing by a power of 2 can never result in this kind of round-off. Powers of 2 are represented exactly in binary floating point numbers, and dividing by a power of two effectively only changes the internal binary exponent without changing the mantissa. If you are running into this kind of round-off then either you are not starting with an integer or you are not dividing by a power of 2.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!