Re: Division in a conditional statement [message #36287 is a reply to message #36282] |
Sat, 30 August 2003 08:46  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Hassan Iqbal writes:
> Can anybody tell me what does this mean:
>
> x= a LT total(abs(b))/1e7/NFREE
>
> where:
> b= an array of floating point numbers
> a= a floating point number
> NFREE= an integer
>
> I will be very much thankful. I really need to understand this.
This means that the person who wrote this code
was overly concerned with job security and was
trying to write code only he could decipher.
Either that or he had a sadistic personality, but
I prefer the kinder interpretation. :-)
To interpret this code, you have to have an
understanding of "operator precedence" (you
could look this up on IDL's on-line help).
Parentheses have the highest or first order of precedence
(and your code writer should have used them to
give meaning to this expression). Followed by
multiplication and division operators (fourth
highest order), and followed up by the LT operator,
which has the sixth highest order of pprecedence.
So, everything to the right of the "LT" operator
happens first and a result is stored in a temporary
variable. Then this result is compared to A with the
LT operator. A couple of parentheses would have made
this plain:
x= a LT (total(abs(b))/1e7/NFREE)
Operators of the same order of precedence, by the way,
are handled left to right.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|