Why does 7*(0.1) - 0.7 = 1.1102e-16 whereas 9*(0.1)-0.9 =0 in MATLAB?
11 ビュー (過去 30 日間)
古いコメントを表示
Why does
7*(0.1)-0.7 = 1.1102e-16,
3*(0.1)-0.3 = 5.55112e-17,
6*(0.1)-0.6 = 1.1102e-16
whereas
9*(0.1)-0.9 = 0,
2*(0.1)-0.2 = 0,
4*(0.1)-0.4 = 0 in MATLAB?
0 件のコメント
回答 (3 件)
Stephen23
2018 年 12 月 5 日
編集済み: Stephen23
2018 年 12 月 5 日
Those values that you are computing with cannot be exactly represented using binary floating point numbers. What you see printed in the command window is the closest representation to 5 or 16 significant digits, depending on your current format setting. To see the "real" value download James Tursa's FEX submission:
Use James Tursa's num2strexact and you will see that none of those values really have the exact value 0.1, or whatever value you use. All you are looking at is a representation of those floating point numbers displayed in the command window, to the precision defined by your format setting. Just because you see 0.1 displayed tells you nothing about the "real" floating point number's value.
You need to learn about the limits of floating point numbers. Start by reading these:
This is worth reading as well:
0 件のコメント
the cyclist
2018 年 12 月 5 日
Some of those combinations are represented by the same floating point value, and some are not.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!