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!