|
|
Re: Computation precision on command line and in scripts
Posted:
Feb 7, 2013 4:12 PM
|
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message > > The documentation states that > > 1) an arithmetic expression is mixed with two numerical type, the result is cast in lower type, then the operation is carried out. > > 2) The expression is evaluated from left to right >
It seems that this rule does not applied for scalar expression affected with colon operator on the lhs. To avoid JIT, I put the argument as parameters of foo function.
function [a rd rs] = foo(b, c, d)
a = zeros(1,2,'double'); bar = b + c -d; a(1) = b + c -d; a(2) = bar;
rd = 0; rd(:) = b + c -d;
rs = single(0); rs(:) = b + c -d;
end % foo
% and here is the result
>> [a rd rs] = foo(single(1),1e-9,1)
a =
0 0
rd =
1.0000e-09
rs =
1.0000e-09
>>
|
|