Date: Feb 7, 2013 9:39 AM
Author: Bruno Luong
Subject: Re: Computation precision on command line and in scripts

"Pierre" wrote in message <kf05u8$9n3$1@newscl01ah.mathworks.com>...

>
> The underlying question was: Are computations with singles performed in double or in single precision??


This question is interesting but actually is not a right question to ask.

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

That explains the result like:

>> uint8(1)+(0.4+0.1+0.1+0.1)

ans =

2

>> 0.4+0.1+0.1+0.1+uint8(1)

ans =

2

>>

IMO the observation in your example is not due to casting, but due to JIT accelerator might detect (single(1) - 1) is 0. The JIT is activated or not in different mode (command line, function, or debug mode). It also depends on which MATLAB version you are running.

Bruno