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

Home » Public Forums » archive » Re: Yet another bug??
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Yet another bug?? [message #4282 is a reply to message #4253] Wed, 17 May 1995 00:00 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
phil@peace.med.ohio-state.edu (Phil) writes:

> Sorry to keep posting but I've just started developing some useful
> tools in IDL and it seems I run across a new 'bug' every day. Could
> someone tell me the sense behind the following:

> IDL> print, not 0
> -1
> IDL> print, not 1
> -2

> Shouldn't (not 0) = 1 and (not 1) = 0 or am i just missing something?
> Is there somehting in the manuals that describes this logic?

> Just wondering.


What the NOT function really does is to reverse all the bits in a number. Thus
the bit pattern representing 0, which not surprising is all 0s, turns into all
1s which is the bit pattern for the integer -1. Such behavior is really useful
when one wants to get down to the bit level of a number, and I think that other
languages behave this way as well. Apparently, any even integer is treated as
false and any odd integer is treated as true. For example,

IDL> for i = -5,5 do if i then print,i
-5
-3
-1
1
3
5

But the function KEYWORD_SET, which is also associated with boolean values,
seems to behave differently. It only treats the value 0 as false, and anything
else as true.

IDL> for i = -5,5 do if keyword_set(i) then print,i
-5
-4
-3
-2
-1
1
2
3
4
5
IDL> print, keyword_set(not 1)
1

I consider that a bug.

Also, floating point numbers work differently then integer numbers, and match
the behavior of KEYWORD_SET.

IDL> print, not 0.
1.00000
IDL> print, not 1.
0.00000

and

IDL> for i = -5,5 do if float(i) then print,i
-5
-4
-3
-2
-1
1
2
3
4
5

Basically, it's a mess. I'm not too upset about the difference between
floating point and integer behavior, but KEYWORD_SET really worries me now. If
I use a statement like

MYPROG, TEST_KEY=(NOT A)

and I'm using KEYWORD_SET inside the routine to test whether or TEST_KEY was
set, I'll get the wrong answer.

Bill Thompson
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Delay in printing to screen
Next Topic: Delay in printing to screen

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

Current Time: Thu Mar 26 03:00:43 PDT 2026

Total time taken to generate the page: 2.48284 seconds