Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Computation precision on command line and in scripts
Replies: 8   Last Post: Feb 11, 2013 6:59 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 9,696 Registered: 7/26/08
Re: Computation precision on command line and in scripts
Posted: Feb 9, 2013 5:10 AM
 Plain Text Reply

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

Date Subject Author
2/7/13 Bruno Luong
2/7/13 Bruno Luong
2/7/13 Bruno Luong
2/7/13 Bruno Luong
2/9/13 Bruno Luong
2/11/13 Bruno Luong

© The Math Forum at NCTM 1994-2017. All Rights Reserved.