comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Bug in operator precedence
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Bug in operator precedence [message #45167] Wed, 17 August 2005 00:05
Foldy Lajos is currently offline  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 #45169 is a reply to message #45167] Tue, 16 August 2005 20:18 Go to previous message
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
Maybe the last statement was ambiguous, should be:
...
also the ~ (logical negation) operator has now the same precedence as
the NOT (bitwise negation) operator, like in IDL
...
Re: Bug in operator precedence [message #45171 is a reply to message #45169] Tue, 16 August 2005 15:47 Go to previous message
Peter Mason is currently offline  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 Go to previous message
Mark Hadfield is currently offline  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 #45180 is a reply to message #45172] Tue, 16 August 2005 01:56 Go to previous message
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
It is already fixed :-)
(in the CVS)
also the ~ operator has now the same precedence as NOT like in IDL

Cheers,
marc
Re: Bug in operator precedence [message #45181 is a reply to message #45180] Tue, 16 August 2005 01:43 Go to previous message
Foldy Lajos is currently offline  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
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Install ENVI/IDL on cygwin
Next Topic: Re: Install ENVI/IDL on cygwin

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:45:35 PDT 2025

Total time taken to generate the page: 0.00480 seconds