From help-octave-request at bevo dot che dot wisc dot edu Mon Feb 2 09:49:40 2004 Subject: Re: Small problem in a if condition From: "John W. Eaton" To: Pol Cc: help-octave at bevo dot che dot wisc dot edu Date: Mon, 2 Feb 2004 09:48:31 -0600 On 2-Feb-2004, Pol wrote: | On Sun, 1 Feb 2004 11:12:27 -0600 | | "John W. Eaton" 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 -------------------------------------------------------------