Weird-Confusing mistake in subtraction result!!!!

6 ビュー (過去 30 日間)
shirin mhd
shirin mhd 2022 年 8 月 25 日
移動済み: Matt J 2022 年 8 月 25 日
Hi everyone
I have a weird problem with a simple subtraction.
Here is my code. I define 'R' and 'a1 to a8':
R=194067676.886295
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a1=19044444.410581;
a2=15000000.000000;
a3=1500000.000000;
a4=4000000;
a5=500000;
a6=32323232.475714;
a7=120000000;
a8=1700000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sum=a1+a2+a3+a4+a5+a6+a7+a8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d=sum-R
As you can see from the result below, the value of 'R' and 'sum' is the same.
I expect the subtraction of 'R' and 'sum' which is 'd', becomes zero.
But as you can see, it isn't zero and I don't understand why is this happening.
result:
R =
1.940676768862950e+08
sum =
1.940676768862950e+08
d =
2.980232238769531e-08
please help me with this problem.
I'm really confused.

採用された回答

Stephen23
Stephen23 2022 年 8 月 25 日
移動済み: Matt J 2022 年 8 月 25 日
  1 件のコメント
shirin mhd
shirin mhd 2022 年 8 月 25 日
移動済み: Matt J 2022 年 8 月 25 日
I really appreciate your taking the time to explain the concept and share links. Im a novice coder and I'm learning a lot from here. Thank you for your help.

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

その他の回答 (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