Data arithmatic addition with single precision
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
James Tursa
am 27 Sep. 2019
Bearbeitet: James Tursa
am 27 Sep. 2019
Floating point operations will often yield slightly different results if you change the order of operations. This is to be expected.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!