Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,813
Registered: 7/26/08
Re: Computation precision on command line and in scripts
Posted: Feb 7, 2013 9:39 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.