Re: Bug in operator precedence [message #45167] |
Wed, 17 August 2005 00:05 |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
hi,
RSI does the same, it has constructs like
if (measure eq 3 && ~N_ELEMENTS(powerIn)) then ...
in his library, which rely on ~ having higher precedence than &&.
regards,
lajos
On Wed, 17 Aug 2005, Mark Hadfield wrote:
> * Like many people, I don't bother to read the manual unless I
> really need to, and I have code that relies on what IDL does,
> not what the manual says it should do.
|
|
|
|
Re: Bug in operator precedence [message #45171 is a reply to message #45169] |
Tue, 16 August 2005 15:47  |
Peter Mason
Messages: 145 Registered: June 1996
|
Senior Member |
|
|
Mark Hadfield wrote:
<...>
> * Like many people, I don't bother to read the manual unless I
> really need to, and I have code that relies on what IDL does,
> not what the manual says it should do.
The other day, a colleague pointed out to me that if you read a manual it
means that you have failed :-)
|
|
|
Re: Bug in operator precedence [message #45172 is a reply to message #45171] |
Tue, 16 August 2005 15:20  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
m_schellens@hotmail.com wrote:
> According to the manual, operators
>
> ~ || &&
>
> have lower precedence than
>
> AND OR XOR
>
> Now I get:
> IDL> print, 1 && ~3 and 4
> 0
> IDL> print, 1 && (~3) and 4
> 0
> IDL> print, 1 && ~(3 and 4)
> 1
>
> I would consider this as a bug.
Yes, but I suggest that the best way to fix it is to change the manual.
I think "~" logical negation should have similar priority to "not"
(bitwise negation) and higher than any of the binary logical operators,
ie the "eq"s the "and"s and the "&&"s. Why do I think this? Well...
* Bitwise and logical negation are very similar conceptually
* Unary operators normally outrank binary ones
* Like many people, I don't bother to read the manual unless I
really need to, and I have code that relies on what IDL does,
not what the manual says it should do.
--
Mark Hadfield "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
|
Re: Bug in operator precedence [message #45181 is a reply to message #45180] |
Tue, 16 August 2005 01:43  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
Hi,
print, ~1+1, (~1)+1, ~(1+1) gives 1 1 0, which shows, that ~ has
precedence greater or equal to addition. According to the documentation,
this is clearly wrong (and GDL is right printing 0 1 0).
By the way, in GDL print, NOT 1+1, (NOT 1)+1, NOT (1+1) gives -3 -1 -3,
which should be -1 -1 -3, because the precedence of NOT is equal to
addition (and IDL is right).
Now, we have two similar bugs, and the efforts needed to fix them are
equal. Which bug will be fixed first? (I would bet on GDL's bug fixed
in a few days.)
Ready, Steady, Go! :-))))))))
regards,
lajos
On Tue, 16 Aug 2005, m_schellens@hotmail.com wrote:
> According to the manual, operators
>
> ~ || &&
>
> have lower precedence than
>
> AND OR XOR
>
> Now I get:
> IDL> print, 1 && ~3 and 4
> 0
> IDL> print, 1 && (~3) and 4
> 0
> IDL> print, 1 && ~(3 and 4)
> 1
>
> I would consider this as a bug.
> Anybody agree or am I missing something?
>
> Cheers,
> marc
>
>
|
|
|