9

Expression Te chniques 147
Oper ator s
In the following tables, p and q are any scalar value
or expression, V and W are any vector value or
expression. (The character "x" is used as the vector
cross-product operator.)
Scalar Operators
Thesearethearithmeticoperatorsforscalar
values:
Oper at or
Use
Meaning
+p+q
Addition
-
p-q
Subtraction
-
-p
Additive inverse
*p*q
Multiplication
/ p/q Division
^p^q
power (p to the
power of q)
** p**q
^ and ** are the
same operation
You can also use logical (Boolean) operators w ith
scalar values. These operators all return 1 if true, 0
otherwise:
Oper at or
Use
Meaning
=
p=q
equal to
<p<q
less than
>p>q
Greater than
<= p<=q
less than or equal
to
>= p>=q
Greater than or
equal to
|p|q
Logical OR,
returns 1 if either
p or q is nonzero;
otherwise, returns
0
&p&q
Logical AND,
returns 1 if p and q
are both nonzero;
otherwise, returns
0
Tip: Logicaloperatorsareusefulwiththe"if"
function.
Vector Operators
For vectors that have a variable name, you can use
a special component operator (.) to refer to the
three scalar components of the vector:
Use
Meaning
V.x
first component (X)
V.y
second component (Y)
V.z
third component (Z)
Thesearetheoperatorsforvectorarithmetic:
Opera tor
Use
Meaning
+
V+W
Addition
-
V-W
subtraction
*p*V
scalar multiplication
*V*p
scalar multiplication
*V*W
dot product
XVxW
cross product
/V/p
scalar division
Operator Precedence
Expressions have e ight levels of precedence. The
higher the operator is on the list, the earlier it is
evaluated.
Opera tor
Level o f P recedence
-+
as unary operators, as in -8, +25
.
the component operator, as in V.x
** ^
X
cross pro duct
*/
+-
=<><=>=
|&