next up previous contents index
Next: Operands in Expressions Up: Command Format Previous: Real Expressions   Contents   Index


Operators

An expression can be formed using operators and functions acting on operands.


Table 2.4: Real Operators in MAD-9
Operator Meaning result type operand type(s)
Real operators with one operand
+ X unary plus, returns X real real
- X unary minus, returns the negative of X real real
Real operators with two operands
X + Y add X to Y real real,real
X - Y subtract Y from X real real,real
X * Y multiply X by Y real real,real
X / Y divide X by Y real real,real
X ^ Y power, return X raised to the power Y ( $\mathtt{Y} > 0$) real real,real


Table 2.5: Real Functions in MAD-9
Function Meaning result type argument type(s)
Real functions with no arguments
RANF() random number, uniform distribution in [0,1) real -
GAUSS() random number, Gaussian distribution with $\sigma=1$ real -
USER0() random number, user-defined distribution real -
SI() arc length from start of ring to the entry of the current element. This function is only available in the EALIGN command real -
SC() arc length from start of ring to the centre of the current element. This function is only available in the EALIGN command real -
SO() arc length from start of ring to the exit of current the element. This function is only available in the EALIGN command real -
Real functions with one argument
TRUNC(X) truncate X towards zero (discard fractional part) real real
ROUND(X) round X to nearest integer real real
FLOOR(X) return largest integer not greater than X real real
CEIL(X) return smallest integer not less than X real real
SIGN(X) return sign of X (+1 for X positive, -1 for X negative, 0 for X zero) real real
SQRT(X) return square root of X real real
LOG(X) return natural logarithm of X real real
EXP(X) return exponential to the base $e$ of X real real
SIN(X) return trigonometric sine of X real real
COS(X) return trigonometric cosine of X real real
ABS(X) return absolute value of X real real
TAN(X) return trigonometric tangent of X real real
ASIN(X) return inverse trigonometric sine of X real real
ACOS(X) return inverse trigonometric cosine of X real real
ATAN(X) return inverse trigonometric tangent of X real real
TGAUSS(X) random number, Gaussian distribution with $\sigma$=1, truncated at X real real
USER1(X) random number, user-defined distribution with one parameter real real
EVAL(X) evaluate the argument immediately and transmit it as a constant real real
Real functions with two arguments
ATAN2(X,Y) return inverse trigonometric tangent of Y/X real real,real
MAX(X,Y) return the larger of X, Y real real,real
MIN(X,Y) return the smaller of X, Y real real,real
MOD(X,Y) return the largest value less than Y which differs from X by a multiple of Y real real,real
USER2(X,Y) random number, user-defined distribution with two parameters real real,real


Table 2.6: Real Functions of Arrays in MAD-9
Function Meaning result type operand type
VMAX(X,Y) return largest array component real real array
VMIN(X,Y) return smallest array component real real array
VRMS(X,Y) return rms value of an array real real array
VABSMAX(X,Y) return absolute largest array component real real array

Care must be used when an ordinary expression contains a random generator. It may be re-evaluated at unpredictable times, generating a new value. However, the use of a random generator in an assignment expression is safe. Examples:


D:DRIFT,L=0.01*RANF();    // a drift space with random length,
                          // may change during execution.
P=EVAL(0.001*TGAUSS(X));  // Evaluated once and stored as a constant.


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