Bug in single/double operations?

조회 수: 7 (최근 30일)
David Wilson
David Wilson 2011년 6월 27일
Can anybody explain this behaviour?
If you run the following code, it behaves as expected. You finish up with approximately eps('single')=1e-7.
HOWEVER, if you comment out the disp(x) line, then you finish up with eps('double')=1e-16.
Why should a disp(x) change anything? Is it a sneaky invisible casting?
------------------------------------
format long
x = single(1) % single precision
while single(1+x) > 1 % keep going until no difference
x= x/2; % if you can tell any difference, half it.
disp(x) % comment this line out
end % while
---------------------------------------
  댓글 수: 1
Paulo Silva
Paulo Silva 2011년 6월 27일
weird behavior, I have no idea why that happens

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2011년 6월 28일
This exact issue has already been discussed on the newsgroup, with the JIT being the likely cause of the difference:

추가 답변 (1개)

Mike Hosea
Mike Hosea 2011년 6월 27일
It appears to be something to do with the MATLAB JIT-Accelerator. I'm going to say it's probably unintentional. :)
I have to add, however, that while one can usually get away with an algorithm like that in MATLAB (except for code generation), we had to give up on it in numerical software in general after Intel came out with 80-bit extended-precision floating-point registers. Usually you want the eps for the data type, not for the register.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by