Data arithmatic addition with single precision
2 ビュー (過去 30 日間)
古いコメントを表示
Hello
I am adding 21 elements of an array by two different methods. The two methods should show same value. But while printing the results the are different. Please suggest.
clc
clear all
close all
x=rand(1,100)*10^16;
x = single(x)
method1 = sum(x(1:21))+x(22)-x(1);
method2 = sum(x(2:22));
sprintf('%f',method1)
sprintf('%f',method2)
Regards,
Gagarin
0 件のコメント
回答 (1 件)
James Tursa
2019 年 9 月 27 日
編集済み: James Tursa
2019 年 9 月 27 日
Floating point operations will often yield slightly different results if you change the order of operations. This is to be expected.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!