Thread Subject: Strange double(single(a))-1 output

Subject: Strange double(single(a))-1 output

From: Sebastiaan

Date: 11 Mar, 2009 15:55:02

Message: 1 of 6

Dear list,

I experienced something strange in Matlab R2008a (64 bit Linux) command window, but unfortunately I have not been able to reproduce this in a new Matlab session. I post it here so people can be aware that Matlab can do funny things, and hopefully find a clue.

I tried loosing some non-significant digits of a double which was a single once:
>> a=1.000000005960464
a =
   1.000000005960464
>> class(a)
ans =
double
>> double(single(a))
ans =
     1

So far so good. This is where it goes wrong:
>> double(single(a))-1
ans =
    -1
>> double(single(a))-double(1)
ans =
    -1

This goed well:
>> double(single(a))-single(1)
ans =
     0

Storing it in a variable works ok:
>> b=double(single(a))
b =
     1
>> b-1
ans =
     0
(and a lost its non-significant part as objected).

Other interesting results:
>> double(single(a))-round(a)
ans =
  315.0001
>> double(single(a)) - round(a) % with spaces around the -
ans =
    -1
>> double(single(a))-round(a) % same as before, but with different result
ans =
    -1

Did anyone else experience this? Does anyone have a clue what happens here? Unfortunately (for bug tracking), when starting a new session it works as it should.

Sincerely,

Subject: Strange double(single(a))-1 output

From: Jan Simon

Date: 11 Mar, 2009 17:19:01

Message: 2 of 6

Dear Sebastiaan

> ...
> Unfortunately (for bug tracking), when starting a new session it works as it should.

This sounds fundamental! What must happen in a session, before this error occurs?
Is the problem reproducible?

Jan

Subject: Strange double(single(a))-1 output

From: Jos

Date: 11 Mar, 2009 18:29:01

Message: 3 of 6

"Sebastiaan" <s.breedveld@erasmusmc.REMOVE.BOO.BOO.nl> wrote in message <gp8msm$3f0$1@fred.mathworks.com>...
> Dear list,
>
> I experienced something strange in Matlab R2008a (64 bit Linux) command window, but unfortunately I have not been able to reproduce this in a new Matlab session.

This sounds more like a "workspace" problem than a ML bug ... Come back here when you have reproduced the behavior.

Jos

Subject: Strange double(single(a))-1 output

From: Matt Fig

Date: 11 Mar, 2009 18:40:18

Message: 4 of 6

I tested the below examples on Win 32 xp: 2006a, 2007b
All results are zero.

Also on Win 64 xp: 6.5 2007b
All results are zero.

a=1.000000005960464
double(single(a))-1
double(single(a))-double(1)


What has to happen to make your example reproducible? Since you say a fresh start allows the expected zeros, what happens to change the results? Do these work?

a=1.000000005960464
as = single(a);
double(as) - 1

or

a=1.000000005960464
(double(single(a))) - 1
double(double(single(a))) - 1

Subject: Strange double(single(a))-1 output

From: Sebastiaan

Date: 12 Mar, 2009 09:46:55

Message: 5 of 6

Good news: I can reproduce this bug now easily. I do not understand why it did not work before, but now with every session I start I type:
a=1.000000005960464
double(single(a))-1
and gives -1 as result.

On a different computer with the same version of Matlab, the result is the same.

However, running Matlab with the -nodisplay option, I get different results:
>> a=1.000000005960464;
>> double(single(a))-1
ans =
   2.3656e-07
>> double(single(a))-double(1)
ans =
   2.3656e-07
>> double(single(a))-single(1)
ans =
     0
>> b=double(single(a))
b =
     1
>> b-1
ans =
     0
>> class(b)
ans =
double

So why does double(single(a))-double(1) give a different result than b=double(single(a)); b-1 ?

Still something wrong here.

Output from ver:
MATLAB Version 7.6.0.324 (R2008a)
MATLAB License Number: ***
Operating System: Linux 2.6.25-gentoo-r7 #1 SMP Mon Sep 29 17:50:02 CEST 2008 x86_64
Java VM Version: Java 1.6.0_01 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Version 7.6 (R2008a)

In response:

Jos:
> This sounds more like a "workspace" problem than a ML bug ... Come back here when you have reproduced the behavior.

Why is a workspace problem not a bug?

It seems indeed a workspace problem. Running the commands from an m-file yields the correct results, e.g. these lines:
a=1.000000005960464
class(a)
double(single(a))
double(single(a))-1

Copy/pasting these 4 lines in the workspace also gives the correct results.

BUT

Only copy/pasting the last 3 lines gives the errorneous output.

Mat:
> What has to happen to make your example reproducible? Since you say a fresh start allows the expected zeros, what happens to change the results? Do these work?
>
> a=1.000000005960464
> as = single(a);
> double(as) - 1
gives 0 (works)
 
> a=1.000000005960464
> (double(single(a))) - 1
> double(double(single(a))) - 1
both gave 2.740000605583191e+02 in the first try. A second try gave -1. (bugs)


I will try R2009a soon.

Subject: Strange double(single(a))-1 output

From: Sebastiaan

Date: 12 Mar, 2009 10:35:03

Message: 6 of 6

Ok, 2009a works fine, as do the previous versions. 7.0.4 (32b), R2006b (32b), R2007a (64b), R2007b (64b) and R2009a (64b) work well, only R2008a (64b) fails (don't have 2008b installed).

Also, R2009a with -nodisplay yields the correct results.

I have tried the same installation of R2008a on 3 different machines now (2 Gentoo, 1 RHEL, all 64b with 2.6 kernel), and they all produced the wrong output.

So, the bug seems solved in newer versions.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
single Sebastiaan 11 Mar, 2009 12:00:32
double Sebastiaan 11 Mar, 2009 12:00:32
conversion Sebastiaan 11 Mar, 2009 12:00:32
bug Sebastiaan 11 Mar, 2009 12:00:32
rssFeed for this Thread

Contact us at files@mathworks.com