About floor function problem.
7 次查看(过去 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.
更多回答(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!