5 Operators and Expressions 48
• The arithmetic binary operators add (+), subtract (-), multiply (*), and divide (/) operate on
integer and floating-point typed expressions (including vectors and matrices). The two operands
must be the same type, or one can be a scalar float and the other a float vector or matrix, or one
can be a scalar integer and the other an integer vector. Additionally, for multiply (*), one can be a
vector and the other a matrix with the same dimensional size of the vector. These result in the
same fundamental type (integer or float) as the expressions they operate on. If one operand is
scalar and the other is a vector or matrix, the scalar is applied component-wise to the vector or
matrix, resulting in the same type as the vector or matrix. Dividing by zero does not cause an
exception but does result in an unspecified value. Multiply (*) applied to two vectors yields a
component-wise multiply. Multiply (*) applied to two matrices yields a linear algebraic matrix
multiply, not a component-wise multiply. Multiply of a matrix and a vector yields a linear
algebraic transform. Use the built-in functions dot, cross, and matrixCompMult to get,
respectively, vector dot product, vector cross product, and matrix component-wise multiplication.
• The operator remainder (%) is reserved for future use.
• The arithmetic unary operators negate (-), post- and pre-increment and decrement (-- and ++)
operate on integer or floating-point values (including vectors and matrices). These result with the
same type they operated on. For post- and pre-increment and decrement, the expression must be
one that could be assigned to (an l-value). Pre-increment and pre-decrement add or subtract 1 or
1.0 to the contents of the expression they operate on, and the value of the pre-increment or pre-
decrement expression is the resulting value of that modification. Post-increment and post-
decrement expressions add or subtract 1 or 1.0 to the contents of the expression they operate on,
but the resulting expression has the expression’s value before the post-increment or post-
decrement was executed.
• The relational operators greater than (>), less than (<), greater than or equal (>=), and less than or
equal (<=) operate only on scalar integer and scalar floating-point expressions. The result is
scalar Boolean. The operands’ types must match. To do component-wise comparisons on
vectors, use the built-in functions lessThan, lessThanEqual, greaterThan, and
greaterThanEqual.
• The equality operators equal (==), and not equal (!=) operate on all types except arrays,
structures containing arrays, sampler types and structures containing sampler types They result in
a scalar Boolean. For vectors, matrices, and structures, all components of the operands must be
equal for the operands to be considered equal. To get component-wise equality results for
vectors, use the built-in functions equal and notEqual.
• The logical binary operators and (&&), or ( | | ), and exclusive or (^^) operate only on two
Boolean expressions and result in a Boolean expression. And (&&) will only evaluate the right
hand operand if the left hand operand evaluated to true. Or ( | | ) will only evaluate the right hand
operand if the left hand operand evaluated to false. Exclusive or (^^) will always evaluate both
operands.
• The logical unary operator not (!). It operates only on a Boolean expression and results in a
Boolean expression. To operate on a vector, use the built-in function not.
• The sequence ( , ) operator that operates on expressions by returning the type and value of the
right-most expression in a comma separated list of expressions. All expressions are evaluated, in
order, from left to right.
Version 1.00 Revision 17 (12 May, 2009)