Bug in rounding functions? Who can explain? :)
1 次查看(过去 30 天)
显示 更早的评论
>> format long
>> 4.1*808e6
ans =
3.312800000000000e+09
>> fix(4.1*808e6)
ans =
3.312799999000000e+09
>> fix(4*808e6 + .1*808e6)
ans =
3.312800000000000e+09
0 个评论
采纳的回答
Walter Roberson
2015-11-11
>> 4.1*808e6 - 3312800000
ans =
-4.76837158203125e-07
That is, due to floating point roundoff, 4.1*808e6 falls just short of an integer. fix() is the same as floor() for positive numbers so fix() removes the fraction after 3312799999 that is not quite 1.0, exactly like how floor(1.99999999) is 1.0 not 2.0
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!