|
|
Re: Computation precision on command line and in scripts
Posted:
Feb 9, 2013 5:10 AM
|
|
Update. I'm now pretty sure the JIT accelerator does something when the lhs is a scalar (:).
What I did is force calling the built-in function by a wrap functions, so JIT is not kicked in, and the result is different only when the scalar LHS is indexed by (:).
Here is the code that shows what is going on:
function [a rd_colon rd] = foo(b, c, d, bsxflag)
if nargin >= 4 && bsxflag % http://www.mathworks.com/matlabcentral/fileexchange/23821-bsxops bsxops(1); end
a = zeros(1,2,'double'); bar = b + c - d; a(1) = b + c - d; % always 0 a(2) = bar; % always 0
rd_colon = double(0); % <= zeros(1,1,'double'); rd_colon(:) = b + c - d; % 1.0000e-09 when bsxflag is FALSE
rd = b + c - d; % always 0
bsxops(0);
end % foo
% Test on command line (2012B, WIN7-64):
>> [a rd_colon rd] = foo(single(1),double(1e-9),double(1), 0)
a =
0 0
rd_colon =
1.0000e-09
rd =
0
>> [a rd_colon rd] = foo(single(1),double(1e-9),double(1), 1)
a =
0 0
rd_colon =
0
rd =
0
% Bruno
|
|