help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Small problem in a if condition


From: THOMAS Paul Richard
Subject: RE: Small problem in a if condition
Date: Mon, 2 Feb 2004 17:35:07 +0100

John,

For what it is worth, I just checked that Matlab 5 and Matlab 6 do an
implicit double() on the the character in the condition (both rhs and lhs).
That is to say, setting x=63 gives a true.

Regards

Paul

-----Message d'origine-----
De : John W. Eaton [mailto:address@hidden
Envoyé : lundi 2 février 2004 16:49
À : Pol
Cc : address@hidden
Objet : Re: Small problem in a if condition


On  2-Feb-2004, Pol <address@hidden> wrote:

| On Sun, 1 Feb 2004 11:12:27 -0600
| 
| "John W. Eaton" <address@hidden> wrote:
| 
| > What version of Octave are you using?  I think the == operator should
| > work for character strings with either 2.0.17 or 2.1.50.
| 
| [~]$ octave --version
| GNU Octave, version 2.1.50 (i686-pc-linux-gnu).

OK, I see now that the problem in your function was that you were
doing something like this:

  x = 1;

  if (x == "?")
    ...
  endif

This doesn't work in 2.1.50, but does in the current sources (and
probably 2.1.53, though I haven't checked).

So the current behavior is that for a mixed-type comparison like
this, the test will return true if the ASCII value of the character is
equal to the integer.  So in the above, if X is 63, then the body of
the IF block will be executed.  I guess we are getting closer to
bug-for-bug compatibility.  Is this really what people want?

I suspect that this behavior leads to subtle bugs as many people
will think that what the == operator is doing is the equivalent of

  isstr (x) && x == "?"         ## this is what strcmp does

instead of

  x == toascii ("?")

Just out of curiosity, how did you expect the == tests in your code to
behave?

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 19/01/04
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 19/01/04
 



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]