next up previous contents index
Next: Real Expressions Up: Command Format Previous: String Attributes   Contents   Index


Logical Expressions

Many commands in MAD require the setting of logical values (flags) to represent the on/off state of an option. A logical value is represented by one of the values TRUE or FALSE, or by a logical expression. A logical expression can occur in logical arrays.

A logical expression has the same format and operator precedence as a logical expression in C. It is built from logical operators and logical operands:


relation      ::= "TRUE" |
                  "FALSE" |
                  real-expr rel-operator real-expr

rel-operator  ::= "==" | "!=" | "<" | ">" | ">=" | "<="

and-expr      ::= relation | and-expr "&&" relation

logical-expr  ::= and-expr | logical-expr "||" and-expr


Table 2.3: Logical Operators in MAD-9
Operator Meaning result type operand type
X $<$ Y true, if X is less than Y logical real,real
X $<=$ Y true, if X is not greater than Y logical real,real
X $>$ Y true, if X is greater than Y logical real,real
X $>=$ Y true, if X is not less than Y logical real,real
X $==$ Y true, if X is equal to Y logical real,real
X $!=$ Y true, if X is not equal to Y logical real,real
X && Y true, if both X and Y are true logical logical,logical
X || Y true, if at least one of X and Y is true logical logical,logical

Example:


OPTION,ECHO=TRUE; // output echo is desired
When a logical attribute is not entered, its default value is always false. When only its name is entered, the value is set to TRUE:

OPTION,ECHO;      // same as above
Example of a logical expression:

X>10 && Y<20 || Z==15


next up previous contents index
Next: Real Expressions Up: Command Format Previous: String Attributes   Contents   Index
MAD User Guide, http://wwwslap.cern.ch/mad/