フィルターのクリア

How does 6.022140857*10^23 differ from 6.022140857e+23?

1 回表示 (過去 30 日間)
Antonius Armanious
Antonius Armanious 2017 年 3 月 10 日
編集済み: Stephen23 2017 年 3 月 10 日
In matlab if I write the following script I get a non-zero answer which is awkward, can somebody please explain this?
av = 6.022140857*10^23;
av_1 = 6.022140857e+23;
diff = av - av_1
The answer I get is
diff =
-67108864

採用された回答

Stephen23
Stephen23 2017 年 3 月 10 日
編集済み: Stephen23 2017 年 3 月 10 日
>> fprintf('%.0f\n',av)
602214085699999950000000
>> fprintf('%.0f\n',av_1)
602214085700000020000000
because X*B^P performs two numeric operations on three floating point values and accumulates floating point error with each operation. XeP generates the value directly, without any numeric operations.
Because of this:
Or any of the thousand other threads explaining floating point errors and how they accumulate during numeric operations.
You might also be interested in trying James Tursa's excellent FEX submission:
  1 件のコメント
Antonius Armanious
Antonius Armanious 2017 年 3 月 10 日
Thanks for the clarification.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by