It's a bug?

4 ビュー (過去 30 日間)
Emiliano Rosso
Emiliano Rosso 2018 年 11 月 29 日
編集済み: madhan ravi 2018 年 11 月 29 日
I discovered a potential bug and I want to report it:
Matlab R2018a windows 10
alfa=-0.0052+(61-1)*0.0001;
reasoning this is 0.0060-0.0052=0.0008=8e-04
so:
alfa2=8e-04;
isequal(alfa,alfa2)
ans
0
if you open alfa variable you can see:
8.000000000000004e-04
in fact if you round alfa:
alfa3=round(alfa,10);
isequal(alfa2,alfa3)
ans
1
That's all Thanks
  1 件のコメント
Bruno Luong
Bruno Luong 2018 年 11 月 29 日
Welcome to the club, you are one more person who confuses about finite precision floating point calculation.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 29 日
編集済み: madhan ravi 2018 年 11 月 29 日
It‘s called floating point comparison just search with the tag floating-point in this forum you will find lot of reasons
abs(alfa-alfa2)<1e-04

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by