Strange behavior when passing single precision numbers into atan2
이전 댓글 표시
When I pass two single-precision arguments into the atan2 function, the result is different if I assign the output to a variable compared with just allowing it to be assigned to ans. If I run the following code:
a = single(1.2345678);
b = single(1.3456789);
atan2(a,b)
c = atan2(a,b)
This is displayed to the workspace:
ans =
7.4236256e-01
c =
7.4236250e-01
Why is there a discrepancy between these two numbers?
댓글 수: 4
Walter Roberson
2016년 8월 4일
Which MATLAB version are you using, on which operating system?
Also, what is your "format" set to? I do not get that format of output for any of the "format" options I try.
per isakson
2016년 8월 5일
format hex
a = single(1.2345678);
b = single(1.3456789);
atan2(a,b)
c = atan2(a,b)
version
outputs
ans =
3f3e0b79
c =
3f3e0b79
ans =
9.0.0.341360 (R2016a)
i.e. identical values (on Win7)
Colby Smith
2016년 8월 5일
dpb
2016년 8월 5일
Wonder how much if not all may not be related to the underlying compiler libraries...so versions used by TMW matter?
답변 (1개)
dpb
2016년 8월 5일
single doesn't have anything to do with it (albeit the precision of the input values is about that of single precision in decimal digits)...
>> sprintf('%.7e\n',atan2(a,b))
ans =
7.4236256e-01
>> sprintf('%.7e\n',c)
ans =
7.4236250e-01
I'm guessing OP had to have used something like the above to see the result as shown, Walter.
The answer likely has to do with Matlab displaying a result directly to the workspace from the FPP vis a vis a variable store as the difference is on order of double resolution...
>> eps(c)
ans =
5.9605e-08
>>
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!