[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: assignment inside boolean expression
Craig Markwardt wrote:
> Ben Tupper <firstname.lastname@example.org> writes:
> > "Liam E.Gumley" wrote:
> > >
> > > Recall that in IDL, integers with odd non-zero values are Boolean
> > > 'True'. Beware of floats and doubles though, where any non-zero value is
> > > Boolean 'True'.
> > >
> > Dang!
> > I just spent an hour figuring out an efficient way of determining if an
> > integer is odd!
> > I have an IDL function ISODD() for sale... very cheap. No reasonable
> > offer refused.
> Not to undercut you, but will (X AND 1) do the trick?
Thanks to Ken and Craig. I think for my purposes the following should suffice (I
guess as long as I make sure that I'm working with an integer/long/byte type.)
X = Indgen(6) - 2
For i = 0, N_elements(X)-1 Do $
If X[i] then Print, X[i], ': Odd' Else print, X[i], ': Even'
Bigelow Laboratory for Ocean Science