Data arithmatic addition with single precision
조회 수: 1 (최근 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!